raspberry.patch 2.9 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980
  1. diff -Nur linux-3.11.10.orig/arch/arm/configs/bcmrpi_cutdown_defconfig linux-3.11.10/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.11.10.orig/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-3.11.10/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-02-07 19:57:28.000000000 +0100
  4. @@ -0,0 +1,503 @@
  5. +CONFIG_EXPERIMENTAL=y
  6. +# CONFIG_LOCALVERSION_AUTO is not set
  7. +CONFIG_SYSVIPC=y
  8. +CONFIG_POSIX_MQUEUE=y
  9. +CONFIG_IKCONFIG=y
  10. +CONFIG_IKCONFIG_PROC=y
  11. +# CONFIG_UID16 is not set
  12. +# CONFIG_KALLSYMS is not set
  13. +CONFIG_EMBEDDED=y
  14. +# CONFIG_VM_EVENT_COUNTERS is not set
  15. +# CONFIG_COMPAT_BRK is not set
  16. +CONFIG_SLAB=y
  17. +CONFIG_MODULES=y
  18. +CONFIG_MODULE_UNLOAD=y
  19. +CONFIG_MODVERSIONS=y
  20. +CONFIG_MODULE_SRCVERSION_ALL=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_ARCH_BCM2708=y
  23. +CONFIG_NO_HZ=y
  24. +CONFIG_HIGH_RES_TIMERS=y
  25. +CONFIG_AEABI=y
  26. +CONFIG_ZBOOT_ROM_TEXT=0x0
  27. +CONFIG_ZBOOT_ROM_BSS=0x0
  28. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  29. +CONFIG_CPU_IDLE=y
  30. +CONFIG_VFP=y
  31. +CONFIG_BINFMT_MISC=m
  32. +CONFIG_NET=y
  33. +CONFIG_PACKET=y
  34. +CONFIG_UNIX=y
  35. +CONFIG_XFRM_USER=y
  36. +CONFIG_NET_KEY=m
  37. +CONFIG_INET=y
  38. +CONFIG_IP_MULTICAST=y
  39. +CONFIG_IP_PNP=y
  40. +CONFIG_IP_PNP_DHCP=y
  41. +CONFIG_IP_PNP_RARP=y
  42. +CONFIG_SYN_COOKIES=y
  43. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  44. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  45. +# CONFIG_INET_XFRM_MODE_BEET is not set
  46. +# CONFIG_INET_LRO is not set
  47. +# CONFIG_INET_DIAG is not set
  48. +# CONFIG_IPV6 is not set
  49. +CONFIG_NET_PKTGEN=m
  50. +CONFIG_IRDA=m
  51. +CONFIG_IRLAN=m
  52. +CONFIG_IRCOMM=m
  53. +CONFIG_IRDA_ULTRA=y
  54. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  55. +CONFIG_IRDA_FAST_RR=y
  56. +CONFIG_IRTTY_SIR=m
  57. +CONFIG_KINGSUN_DONGLE=m
  58. +CONFIG_KSDAZZLE_DONGLE=m
  59. +CONFIG_KS959_DONGLE=m
  60. +CONFIG_USB_IRDA=m
  61. +CONFIG_SIGMATEL_FIR=m
  62. +CONFIG_MCS_FIR=m
  63. +CONFIG_BT=m
  64. +CONFIG_BT_L2CAP=y
  65. +CONFIG_BT_SCO=y
  66. +CONFIG_BT_RFCOMM=m
  67. +CONFIG_BT_RFCOMM_TTY=y
  68. +CONFIG_BT_BNEP=m
  69. +CONFIG_BT_BNEP_MC_FILTER=y
  70. +CONFIG_BT_BNEP_PROTO_FILTER=y
  71. +CONFIG_BT_HIDP=m
  72. +CONFIG_BT_HCIBTUSB=m
  73. +CONFIG_BT_HCIBCM203X=m
  74. +CONFIG_BT_HCIBPA10X=m
  75. +CONFIG_BT_HCIBFUSB=m
  76. +CONFIG_BT_HCIVHCI=m
  77. +CONFIG_BT_MRVL=m
  78. +CONFIG_BT_MRVL_SDIO=m
  79. +CONFIG_BT_ATH3K=m
  80. +CONFIG_CFG80211=m
  81. +CONFIG_MAC80211=m
  82. +CONFIG_MAC80211_RC_PID=y
  83. +CONFIG_MAC80211_MESH=y
  84. +CONFIG_WIMAX=m
  85. +CONFIG_NET_9P=m
  86. +CONFIG_NFC=m
  87. +CONFIG_NFC_PN533=m
  88. +CONFIG_DEVTMPFS=y
  89. +CONFIG_BLK_DEV_LOOP=y
  90. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  91. +CONFIG_BLK_DEV_NBD=m
  92. +CONFIG_BLK_DEV_RAM=y
  93. +CONFIG_CDROM_PKTCDVD=m
  94. +CONFIG_MISC_DEVICES=y
  95. +CONFIG_SCSI=y
  96. +# CONFIG_SCSI_PROC_FS is not set
  97. +CONFIG_BLK_DEV_SD=m
  98. +CONFIG_BLK_DEV_SR=m
  99. +CONFIG_SCSI_MULTI_LUN=y
  100. +# CONFIG_SCSI_LOWLEVEL is not set
  101. +CONFIG_NETDEVICES=y
  102. +CONFIG_TUN=m
  103. +CONFIG_PHYLIB=m
  104. +CONFIG_MDIO_BITBANG=m
  105. +CONFIG_NET_ETHERNET=y
  106. +# CONFIG_NETDEV_1000 is not set
  107. +# CONFIG_NETDEV_10000 is not set
  108. +CONFIG_LIBERTAS_THINFIRM=m
  109. +CONFIG_LIBERTAS_THINFIRM_USB=m
  110. +CONFIG_AT76C50X_USB=m
  111. +CONFIG_USB_ZD1201=m
  112. +CONFIG_USB_NET_RNDIS_WLAN=m
  113. +CONFIG_RTL8187=m
  114. +CONFIG_MAC80211_HWSIM=m
  115. +CONFIG_ATH_COMMON=m
  116. +CONFIG_ATH9K=m
  117. +CONFIG_ATH9K_HTC=m
  118. +CONFIG_CARL9170=m
  119. +CONFIG_B43=m
  120. +CONFIG_B43LEGACY=m
  121. +CONFIG_HOSTAP=m
  122. +CONFIG_IWM=m
  123. +CONFIG_LIBERTAS=m
  124. +CONFIG_LIBERTAS_USB=m
  125. +CONFIG_LIBERTAS_SDIO=m
  126. +CONFIG_P54_COMMON=m
  127. +CONFIG_P54_USB=m
  128. +CONFIG_RT2X00=m
  129. +CONFIG_RT2500USB=m
  130. +CONFIG_RT73USB=m
  131. +CONFIG_RT2800USB=m
  132. +CONFIG_RT2800USB_RT53XX=y
  133. +CONFIG_RTL8192CU=m
  134. +CONFIG_WL1251=m
  135. +CONFIG_WL12XX_MENU=m
  136. +CONFIG_ZD1211RW=m
  137. +CONFIG_MWIFIEX=m
  138. +CONFIG_MWIFIEX_SDIO=m
  139. +CONFIG_WIMAX_I2400M_USB=m
  140. +CONFIG_USB_CATC=m
  141. +CONFIG_USB_KAWETH=m
  142. +CONFIG_USB_PEGASUS=m
  143. +CONFIG_USB_RTL8150=m
  144. +CONFIG_USB_USBNET=y
  145. +CONFIG_USB_NET_AX8817X=m
  146. +CONFIG_USB_NET_CDCETHER=m
  147. +CONFIG_USB_NET_CDC_EEM=m
  148. +CONFIG_USB_NET_DM9601=m
  149. +CONFIG_USB_NET_SMSC75XX=m
  150. +CONFIG_USB_NET_SMSC95XX=y
  151. +CONFIG_USB_NET_GL620A=m
  152. +CONFIG_USB_NET_NET1080=m
  153. +CONFIG_USB_NET_PLUSB=m
  154. +CONFIG_USB_NET_MCS7830=m
  155. +CONFIG_USB_NET_CDC_SUBSET=m
  156. +CONFIG_USB_ALI_M5632=y
  157. +CONFIG_USB_AN2720=y
  158. +CONFIG_USB_KC2190=y
  159. +# CONFIG_USB_NET_ZAURUS is not set
  160. +CONFIG_USB_NET_CX82310_ETH=m
  161. +CONFIG_USB_NET_KALMIA=m
  162. +CONFIG_USB_NET_INT51X1=m
  163. +CONFIG_USB_IPHETH=m
  164. +CONFIG_USB_SIERRA_NET=m
  165. +CONFIG_USB_VL600=m
  166. +CONFIG_PPP=m
  167. +CONFIG_PPP_ASYNC=m
  168. +CONFIG_PPP_SYNC_TTY=m
  169. +CONFIG_PPP_DEFLATE=m
  170. +CONFIG_PPP_BSDCOMP=m
  171. +CONFIG_SLIP=m
  172. +CONFIG_SLIP_COMPRESSED=y
  173. +CONFIG_NETCONSOLE=m
  174. +CONFIG_INPUT_POLLDEV=m
  175. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  176. +CONFIG_INPUT_JOYDEV=m
  177. +CONFIG_INPUT_EVDEV=m
  178. +# CONFIG_INPUT_KEYBOARD is not set
  179. +# CONFIG_INPUT_MOUSE is not set
  180. +CONFIG_INPUT_MISC=y
  181. +CONFIG_INPUT_AD714X=m
  182. +CONFIG_INPUT_ATI_REMOTE=m
  183. +CONFIG_INPUT_ATI_REMOTE2=m
  184. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  185. +CONFIG_INPUT_POWERMATE=m
  186. +CONFIG_INPUT_YEALINK=m
  187. +CONFIG_INPUT_CM109=m
  188. +CONFIG_INPUT_UINPUT=m
  189. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  190. +CONFIG_INPUT_ADXL34X=m
  191. +CONFIG_INPUT_CMA3000=m
  192. +CONFIG_SERIO=m
  193. +CONFIG_SERIO_RAW=m
  194. +CONFIG_GAMEPORT=m
  195. +CONFIG_GAMEPORT_NS558=m
  196. +CONFIG_GAMEPORT_L4=m
  197. +CONFIG_VT_HW_CONSOLE_BINDING=y
  198. +# CONFIG_LEGACY_PTYS is not set
  199. +# CONFIG_DEVKMEM is not set
  200. +CONFIG_SERIAL_AMBA_PL011=y
  201. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  202. +# CONFIG_HW_RANDOM is not set
  203. +CONFIG_RAW_DRIVER=y
  204. +CONFIG_GPIO_SYSFS=y
  205. +# CONFIG_HWMON is not set
  206. +CONFIG_WATCHDOG=y
  207. +CONFIG_BCM2708_WDT=m
  208. +# CONFIG_MFD_SUPPORT is not set
  209. +CONFIG_FB=y
  210. +CONFIG_FB_BCM2708=y
  211. +CONFIG_FRAMEBUFFER_CONSOLE=y
  212. +CONFIG_LOGO=y
  213. +# CONFIG_LOGO_LINUX_MONO is not set
  214. +# CONFIG_LOGO_LINUX_VGA16 is not set
  215. +CONFIG_SOUND=y
  216. +CONFIG_SND=m
  217. +CONFIG_SND_SEQUENCER=m
  218. +CONFIG_SND_SEQ_DUMMY=m
  219. +CONFIG_SND_MIXER_OSS=m
  220. +CONFIG_SND_PCM_OSS=m
  221. +CONFIG_SND_SEQUENCER_OSS=y
  222. +CONFIG_SND_HRTIMER=m
  223. +CONFIG_SND_DUMMY=m
  224. +CONFIG_SND_ALOOP=m
  225. +CONFIG_SND_VIRMIDI=m
  226. +CONFIG_SND_MTPAV=m
  227. +CONFIG_SND_SERIAL_U16550=m
  228. +CONFIG_SND_MPU401=m
  229. +CONFIG_SND_BCM2835=m
  230. +CONFIG_SND_USB_AUDIO=m
  231. +CONFIG_SND_USB_UA101=m
  232. +CONFIG_SND_USB_CAIAQ=m
  233. +CONFIG_SND_USB_6FIRE=m
  234. +CONFIG_SOUND_PRIME=m
  235. +CONFIG_HID_PID=y
  236. +CONFIG_USB_HIDDEV=y
  237. +CONFIG_HID_A4TECH=m
  238. +CONFIG_HID_ACRUX=m
  239. +CONFIG_HID_APPLE=m
  240. +CONFIG_HID_BELKIN=m
  241. +CONFIG_HID_CHERRY=m
  242. +CONFIG_HID_CHICONY=m
  243. +CONFIG_HID_CYPRESS=m
  244. +CONFIG_HID_DRAGONRISE=m
  245. +CONFIG_HID_EMS_FF=m
  246. +CONFIG_HID_ELECOM=m
  247. +CONFIG_HID_EZKEY=m
  248. +CONFIG_HID_HOLTEK=m
  249. +CONFIG_HID_KEYTOUCH=m
  250. +CONFIG_HID_KYE=m
  251. +CONFIG_HID_UCLOGIC=m
  252. +CONFIG_HID_WALTOP=m
  253. +CONFIG_HID_GYRATION=m
  254. +CONFIG_HID_TWINHAN=m
  255. +CONFIG_HID_KENSINGTON=m
  256. +CONFIG_HID_LCPOWER=m
  257. +CONFIG_HID_LOGITECH=m
  258. +CONFIG_HID_MAGICMOUSE=m
  259. +CONFIG_HID_MICROSOFT=m
  260. +CONFIG_HID_MONTEREY=m
  261. +CONFIG_HID_MULTITOUCH=m
  262. +CONFIG_HID_NTRIG=m
  263. +CONFIG_HID_ORTEK=m
  264. +CONFIG_HID_PANTHERLORD=m
  265. +CONFIG_HID_PETALYNX=m
  266. +CONFIG_HID_PICOLCD=m
  267. +CONFIG_HID_QUANTA=m
  268. +CONFIG_HID_ROCCAT=m
  269. +CONFIG_HID_SAMSUNG=m
  270. +CONFIG_HID_SONY=m
  271. +CONFIG_HID_SPEEDLINK=m
  272. +CONFIG_HID_SUNPLUS=m
  273. +CONFIG_HID_GREENASIA=m
  274. +CONFIG_HID_SMARTJOYPLUS=m
  275. +CONFIG_HID_TOPSEED=m
  276. +CONFIG_HID_THRUSTMASTER=m
  277. +CONFIG_HID_WACOM=m
  278. +CONFIG_HID_WIIMOTE=m
  279. +CONFIG_HID_ZEROPLUS=m
  280. +CONFIG_HID_ZYDACRON=m
  281. +CONFIG_USB=y
  282. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  283. +CONFIG_USB_MON=m
  284. +CONFIG_USB_DWCOTG=y
  285. +CONFIG_USB_STORAGE=y
  286. +CONFIG_USB_STORAGE_REALTEK=m
  287. +CONFIG_USB_STORAGE_DATAFAB=m
  288. +CONFIG_USB_STORAGE_FREECOM=m
  289. +CONFIG_USB_STORAGE_ISD200=m
  290. +CONFIG_USB_STORAGE_USBAT=m
  291. +CONFIG_USB_STORAGE_SDDR09=m
  292. +CONFIG_USB_STORAGE_SDDR55=m
  293. +CONFIG_USB_STORAGE_JUMPSHOT=m
  294. +CONFIG_USB_STORAGE_ALAUDA=m
  295. +CONFIG_USB_STORAGE_ONETOUCH=m
  296. +CONFIG_USB_STORAGE_KARMA=m
  297. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  298. +CONFIG_USB_STORAGE_ENE_UB6250=m
  299. +CONFIG_USB_UAS=m
  300. +CONFIG_USB_LIBUSUAL=y
  301. +CONFIG_USB_MDC800=m
  302. +CONFIG_USB_MICROTEK=m
  303. +CONFIG_USB_SERIAL=m
  304. +CONFIG_USB_SERIAL_GENERIC=y
  305. +CONFIG_USB_SERIAL_AIRCABLE=m
  306. +CONFIG_USB_SERIAL_ARK3116=m
  307. +CONFIG_USB_SERIAL_BELKIN=m
  308. +CONFIG_USB_SERIAL_CH341=m
  309. +CONFIG_USB_SERIAL_WHITEHEAT=m
  310. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  311. +CONFIG_USB_SERIAL_CP210X=m
  312. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  313. +CONFIG_USB_SERIAL_EMPEG=m
  314. +CONFIG_USB_SERIAL_FTDI_SIO=m
  315. +CONFIG_USB_SERIAL_FUNSOFT=m
  316. +CONFIG_USB_SERIAL_VISOR=m
  317. +CONFIG_USB_SERIAL_IPAQ=m
  318. +CONFIG_USB_SERIAL_IR=m
  319. +CONFIG_USB_SERIAL_EDGEPORT=m
  320. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  321. +CONFIG_USB_SERIAL_GARMIN=m
  322. +CONFIG_USB_SERIAL_IPW=m
  323. +CONFIG_USB_SERIAL_IUU=m
  324. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  325. +CONFIG_USB_SERIAL_KEYSPAN=m
  326. +CONFIG_USB_SERIAL_KLSI=m
  327. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  328. +CONFIG_USB_SERIAL_MCT_U232=m
  329. +CONFIG_USB_SERIAL_MOS7720=m
  330. +CONFIG_USB_SERIAL_MOS7840=m
  331. +CONFIG_USB_SERIAL_MOTOROLA=m
  332. +CONFIG_USB_SERIAL_NAVMAN=m
  333. +CONFIG_USB_SERIAL_PL2303=m
  334. +CONFIG_USB_SERIAL_OTI6858=m
  335. +CONFIG_USB_SERIAL_QCAUX=m
  336. +CONFIG_USB_SERIAL_QUALCOMM=m
  337. +CONFIG_USB_SERIAL_SPCP8X5=m
  338. +CONFIG_USB_SERIAL_HP4X=m
  339. +CONFIG_USB_SERIAL_SAFE=m
  340. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  341. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  342. +CONFIG_USB_SERIAL_SYMBOL=m
  343. +CONFIG_USB_SERIAL_TI=m
  344. +CONFIG_USB_SERIAL_CYBERJACK=m
  345. +CONFIG_USB_SERIAL_XIRCOM=m
  346. +CONFIG_USB_SERIAL_OPTION=m
  347. +CONFIG_USB_SERIAL_OMNINET=m
  348. +CONFIG_USB_SERIAL_OPTICON=m
  349. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  350. +CONFIG_USB_SERIAL_ZIO=m
  351. +CONFIG_USB_SERIAL_SSU100=m
  352. +CONFIG_USB_SERIAL_DEBUG=m
  353. +CONFIG_USB_EMI62=m
  354. +CONFIG_USB_EMI26=m
  355. +CONFIG_USB_ADUTUX=m
  356. +CONFIG_USB_SEVSEG=m
  357. +CONFIG_USB_RIO500=m
  358. +CONFIG_USB_LEGOTOWER=m
  359. +CONFIG_USB_LCD=m
  360. +CONFIG_USB_LED=m
  361. +CONFIG_USB_CYPRESS_CY7C63=m
  362. +CONFIG_USB_CYTHERM=m
  363. +CONFIG_USB_IDMOUSE=m
  364. +CONFIG_USB_FTDI_ELAN=m
  365. +CONFIG_USB_APPLEDISPLAY=m
  366. +CONFIG_USB_LD=m
  367. +CONFIG_USB_TRANCEVIBRATOR=m
  368. +CONFIG_USB_IOWARRIOR=m
  369. +CONFIG_USB_TEST=m
  370. +CONFIG_USB_ISIGHTFW=m
  371. +CONFIG_USB_YUREX=m
  372. +CONFIG_MMC=y
  373. +CONFIG_MMC_SDHCI=y
  374. +CONFIG_MMC_SDHCI_PLTFM=y
  375. +CONFIG_MMC_SDHCI_BCM2708=y
  376. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  377. +CONFIG_LEDS_GPIO=y
  378. +CONFIG_LEDS_TRIGGER_TIMER=m
  379. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  380. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  381. +CONFIG_UIO=m
  382. +CONFIG_UIO_PDRV=m
  383. +CONFIG_UIO_PDRV_GENIRQ=m
  384. +# CONFIG_IOMMU_SUPPORT is not set
  385. +CONFIG_EXT4_FS=y
  386. +CONFIG_EXT4_FS_POSIX_ACL=y
  387. +CONFIG_EXT4_FS_SECURITY=y
  388. +CONFIG_REISERFS_FS=m
  389. +CONFIG_REISERFS_FS_XATTR=y
  390. +CONFIG_REISERFS_FS_POSIX_ACL=y
  391. +CONFIG_REISERFS_FS_SECURITY=y
  392. +CONFIG_JFS_FS=m
  393. +CONFIG_JFS_POSIX_ACL=y
  394. +CONFIG_JFS_SECURITY=y
  395. +CONFIG_XFS_FS=m
  396. +CONFIG_XFS_QUOTA=y
  397. +CONFIG_XFS_POSIX_ACL=y
  398. +CONFIG_XFS_RT=y
  399. +CONFIG_GFS2_FS=m
  400. +CONFIG_OCFS2_FS=m
  401. +CONFIG_BTRFS_FS=m
  402. +CONFIG_BTRFS_FS_POSIX_ACL=y
  403. +CONFIG_NILFS2_FS=m
  404. +CONFIG_AUTOFS4_FS=y
  405. +CONFIG_FUSE_FS=m
  406. +CONFIG_CUSE=m
  407. +CONFIG_FSCACHE=y
  408. +CONFIG_CACHEFILES=y
  409. +CONFIG_ISO9660_FS=m
  410. +CONFIG_JOLIET=y
  411. +CONFIG_ZISOFS=y
  412. +CONFIG_UDF_FS=m
  413. +CONFIG_MSDOS_FS=y
  414. +CONFIG_VFAT_FS=y
  415. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  416. +CONFIG_NTFS_FS=m
  417. +CONFIG_TMPFS=y
  418. +CONFIG_TMPFS_POSIX_ACL=y
  419. +CONFIG_CONFIGFS_FS=y
  420. +CONFIG_SQUASHFS=m
  421. +CONFIG_SQUASHFS_XATTR=y
  422. +CONFIG_SQUASHFS_LZO=y
  423. +CONFIG_SQUASHFS_XZ=y
  424. +CONFIG_NFS_FS=y
  425. +CONFIG_NFS_V3=y
  426. +CONFIG_NFS_V3_ACL=y
  427. +CONFIG_NFS_V4=y
  428. +CONFIG_ROOT_NFS=y
  429. +CONFIG_NFS_FSCACHE=y
  430. +CONFIG_CIFS=m
  431. +CONFIG_CIFS_WEAK_PW_HASH=y
  432. +CONFIG_CIFS_XATTR=y
  433. +CONFIG_CIFS_POSIX=y
  434. +CONFIG_9P_FS=m
  435. +CONFIG_PARTITION_ADVANCED=y
  436. +CONFIG_MAC_PARTITION=y
  437. +CONFIG_EFI_PARTITION=y
  438. +CONFIG_NLS_DEFAULT="utf8"
  439. +CONFIG_NLS_CODEPAGE_437=y
  440. +CONFIG_NLS_CODEPAGE_737=m
  441. +CONFIG_NLS_CODEPAGE_775=m
  442. +CONFIG_NLS_CODEPAGE_850=m
  443. +CONFIG_NLS_CODEPAGE_852=m
  444. +CONFIG_NLS_CODEPAGE_855=m
  445. +CONFIG_NLS_CODEPAGE_857=m
  446. +CONFIG_NLS_CODEPAGE_860=m
  447. +CONFIG_NLS_CODEPAGE_861=m
  448. +CONFIG_NLS_CODEPAGE_862=m
  449. +CONFIG_NLS_CODEPAGE_863=m
  450. +CONFIG_NLS_CODEPAGE_864=m
  451. +CONFIG_NLS_CODEPAGE_865=m
  452. +CONFIG_NLS_CODEPAGE_866=m
  453. +CONFIG_NLS_CODEPAGE_869=m
  454. +CONFIG_NLS_CODEPAGE_936=m
  455. +CONFIG_NLS_CODEPAGE_950=m
  456. +CONFIG_NLS_CODEPAGE_932=m
  457. +CONFIG_NLS_CODEPAGE_949=m
  458. +CONFIG_NLS_CODEPAGE_874=m
  459. +CONFIG_NLS_ISO8859_8=m
  460. +CONFIG_NLS_CODEPAGE_1250=m
  461. +CONFIG_NLS_CODEPAGE_1251=m
  462. +CONFIG_NLS_ASCII=y
  463. +CONFIG_NLS_ISO8859_1=m
  464. +CONFIG_NLS_ISO8859_2=m
  465. +CONFIG_NLS_ISO8859_3=m
  466. +CONFIG_NLS_ISO8859_4=m
  467. +CONFIG_NLS_ISO8859_5=m
  468. +CONFIG_NLS_ISO8859_6=m
  469. +CONFIG_NLS_ISO8859_7=m
  470. +CONFIG_NLS_ISO8859_9=m
  471. +CONFIG_NLS_ISO8859_13=m
  472. +CONFIG_NLS_ISO8859_14=m
  473. +CONFIG_NLS_ISO8859_15=m
  474. +CONFIG_NLS_KOI8_R=m
  475. +CONFIG_NLS_KOI8_U=m
  476. +CONFIG_NLS_UTF8=m
  477. +# CONFIG_SCHED_DEBUG is not set
  478. +# CONFIG_DEBUG_BUGVERBOSE is not set
  479. +# CONFIG_FTRACE is not set
  480. +# CONFIG_ARM_UNWIND is not set
  481. +CONFIG_CRYPTO_AUTHENC=m
  482. +CONFIG_CRYPTO_SEQIV=m
  483. +CONFIG_CRYPTO_CBC=y
  484. +CONFIG_CRYPTO_HMAC=y
  485. +CONFIG_CRYPTO_XCBC=m
  486. +CONFIG_CRYPTO_MD5=y
  487. +CONFIG_CRYPTO_SHA1=y
  488. +CONFIG_CRYPTO_SHA256=m
  489. +CONFIG_CRYPTO_SHA512=m
  490. +CONFIG_CRYPTO_TGR192=m
  491. +CONFIG_CRYPTO_WP512=m
  492. +CONFIG_CRYPTO_CAST5=m
  493. +CONFIG_CRYPTO_DES=y
  494. +CONFIG_CRYPTO_DEFLATE=m
  495. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  496. +# CONFIG_CRYPTO_HW is not set
  497. +CONFIG_CRC_ITU_T=y
  498. +CONFIG_LIBCRC32C=y
  499. +CONFIG_I2C=y
  500. +CONFIG_I2C_BOARDINFO=y
  501. +CONFIG_I2C_COMPAT=y
  502. +CONFIG_I2C_CHARDEV=m
  503. +CONFIG_I2C_HELPER_AUTO=y
  504. +CONFIG_I2C_BCM2708=m
  505. +CONFIG_SPI=y
  506. +CONFIG_SPI_MASTER=y
  507. +CONFIG_SPI_BCM2708=m
  508. diff -Nur linux-3.11.10.orig/arch/arm/configs/bcmrpi_defconfig linux-3.11.10/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.11.10.orig/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-3.11.10/arch/arm/configs/bcmrpi_defconfig 2014-02-07 19:57:28.000000000 +0100
  511. @@ -0,0 +1,991 @@
  512. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  513. +# CONFIG_LOCALVERSION_AUTO is not set
  514. +CONFIG_SYSVIPC=y
  515. +CONFIG_POSIX_MQUEUE=y
  516. +CONFIG_FHANDLE=y
  517. +CONFIG_AUDIT=y
  518. +CONFIG_NO_HZ=y
  519. +CONFIG_HIGH_RES_TIMERS=y
  520. +CONFIG_BSD_PROCESS_ACCT=y
  521. +CONFIG_BSD_PROCESS_ACCT_V3=y
  522. +CONFIG_TASKSTATS=y
  523. +CONFIG_TASK_DELAY_ACCT=y
  524. +CONFIG_TASK_XACCT=y
  525. +CONFIG_TASK_IO_ACCOUNTING=y
  526. +CONFIG_IKCONFIG=y
  527. +CONFIG_IKCONFIG_PROC=y
  528. +CONFIG_CGROUP_FREEZER=y
  529. +CONFIG_CGROUP_DEVICE=y
  530. +CONFIG_CGROUP_CPUACCT=y
  531. +CONFIG_RESOURCE_COUNTERS=y
  532. +CONFIG_BLK_CGROUP=y
  533. +CONFIG_NAMESPACES=y
  534. +CONFIG_SCHED_AUTOGROUP=y
  535. +CONFIG_EMBEDDED=y
  536. +# CONFIG_COMPAT_BRK is not set
  537. +CONFIG_PROFILING=y
  538. +CONFIG_OPROFILE=m
  539. +CONFIG_KPROBES=y
  540. +CONFIG_JUMP_LABEL=y
  541. +CONFIG_MODULES=y
  542. +CONFIG_MODULE_UNLOAD=y
  543. +CONFIG_MODVERSIONS=y
  544. +CONFIG_MODULE_SRCVERSION_ALL=y
  545. +# CONFIG_BLK_DEV_BSG is not set
  546. +CONFIG_BLK_DEV_THROTTLING=y
  547. +CONFIG_PARTITION_ADVANCED=y
  548. +CONFIG_MAC_PARTITION=y
  549. +CONFIG_CFQ_GROUP_IOSCHED=y
  550. +CONFIG_ARCH_BCM2708=y
  551. +CONFIG_AEABI=y
  552. +CONFIG_SECCOMP=y
  553. +CONFIG_CC_STACKPROTECTOR=y
  554. +CONFIG_ZBOOT_ROM_TEXT=0x0
  555. +CONFIG_ZBOOT_ROM_BSS=0x0
  556. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  557. +CONFIG_KEXEC=y
  558. +CONFIG_CPU_FREQ=y
  559. +CONFIG_CPU_FREQ_STAT=m
  560. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  561. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  562. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  563. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  564. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  565. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  566. +CONFIG_CPU_IDLE=y
  567. +CONFIG_VFP=y
  568. +CONFIG_BINFMT_MISC=m
  569. +CONFIG_NET=y
  570. +CONFIG_PACKET=y
  571. +CONFIG_UNIX=y
  572. +CONFIG_XFRM_USER=y
  573. +CONFIG_NET_KEY=m
  574. +CONFIG_INET=y
  575. +CONFIG_IP_MULTICAST=y
  576. +CONFIG_IP_PNP=y
  577. +CONFIG_IP_PNP_DHCP=y
  578. +CONFIG_IP_PNP_RARP=y
  579. +CONFIG_SYN_COOKIES=y
  580. +CONFIG_INET_AH=m
  581. +CONFIG_INET_ESP=m
  582. +CONFIG_INET_IPCOMP=m
  583. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  584. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  585. +CONFIG_INET_XFRM_MODE_BEET=m
  586. +CONFIG_INET_LRO=m
  587. +CONFIG_INET_DIAG=m
  588. +CONFIG_IPV6_PRIVACY=y
  589. +CONFIG_INET6_AH=m
  590. +CONFIG_INET6_ESP=m
  591. +CONFIG_INET6_IPCOMP=m
  592. +CONFIG_IPV6_MULTIPLE_TABLES=y
  593. +CONFIG_NETFILTER=y
  594. +CONFIG_NF_CONNTRACK=m
  595. +CONFIG_NF_CONNTRACK_ZONES=y
  596. +CONFIG_NF_CONNTRACK_EVENTS=y
  597. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  598. +CONFIG_NF_CT_PROTO_DCCP=m
  599. +CONFIG_NF_CT_PROTO_UDPLITE=m
  600. +CONFIG_NF_CONNTRACK_AMANDA=m
  601. +CONFIG_NF_CONNTRACK_FTP=m
  602. +CONFIG_NF_CONNTRACK_H323=m
  603. +CONFIG_NF_CONNTRACK_IRC=m
  604. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  605. +CONFIG_NF_CONNTRACK_SNMP=m
  606. +CONFIG_NF_CONNTRACK_PPTP=m
  607. +CONFIG_NF_CONNTRACK_SANE=m
  608. +CONFIG_NF_CONNTRACK_SIP=m
  609. +CONFIG_NF_CONNTRACK_TFTP=m
  610. +CONFIG_NF_CT_NETLINK=m
  611. +CONFIG_NETFILTER_TPROXY=m
  612. +CONFIG_NETFILTER_XT_SET=m
  613. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  614. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  615. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  616. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  617. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  618. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  619. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  620. +CONFIG_NETFILTER_XT_TARGET_LED=m
  621. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  622. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  623. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  624. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  625. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  626. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  627. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  628. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  629. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  630. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  631. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  632. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  633. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  634. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  635. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  636. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  637. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  638. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  639. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  640. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  641. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  642. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  643. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  644. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  645. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  646. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  647. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  648. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  649. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  650. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  651. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  652. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  653. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  654. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  655. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  656. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  657. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  658. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  659. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  660. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  661. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  662. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  663. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  664. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  665. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  666. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  667. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  668. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  669. +CONFIG_NETFILTER_XT_MATCH_U32=m
  670. +CONFIG_IP_SET=m
  671. +CONFIG_IP_SET_BITMAP_IP=m
  672. +CONFIG_IP_SET_BITMAP_IPMAC=m
  673. +CONFIG_IP_SET_BITMAP_PORT=m
  674. +CONFIG_IP_SET_HASH_IP=m
  675. +CONFIG_IP_SET_HASH_IPPORT=m
  676. +CONFIG_IP_SET_HASH_IPPORTIP=m
  677. +CONFIG_IP_SET_HASH_IPPORTNET=m
  678. +CONFIG_IP_SET_HASH_NET=m
  679. +CONFIG_IP_SET_HASH_NETPORT=m
  680. +CONFIG_IP_SET_HASH_NETIFACE=m
  681. +CONFIG_IP_SET_LIST_SET=m
  682. +CONFIG_IP_VS=m
  683. +CONFIG_IP_VS_PROTO_TCP=y
  684. +CONFIG_IP_VS_PROTO_UDP=y
  685. +CONFIG_IP_VS_PROTO_ESP=y
  686. +CONFIG_IP_VS_PROTO_AH=y
  687. +CONFIG_IP_VS_PROTO_SCTP=y
  688. +CONFIG_IP_VS_RR=m
  689. +CONFIG_IP_VS_WRR=m
  690. +CONFIG_IP_VS_LC=m
  691. +CONFIG_IP_VS_WLC=m
  692. +CONFIG_IP_VS_LBLC=m
  693. +CONFIG_IP_VS_LBLCR=m
  694. +CONFIG_IP_VS_DH=m
  695. +CONFIG_IP_VS_SH=m
  696. +CONFIG_IP_VS_SED=m
  697. +CONFIG_IP_VS_NQ=m
  698. +CONFIG_IP_VS_FTP=m
  699. +CONFIG_IP_VS_PE_SIP=m
  700. +CONFIG_NF_CONNTRACK_IPV4=m
  701. +CONFIG_IP_NF_IPTABLES=m
  702. +CONFIG_IP_NF_MATCH_AH=m
  703. +CONFIG_IP_NF_MATCH_ECN=m
  704. +CONFIG_IP_NF_MATCH_TTL=m
  705. +CONFIG_IP_NF_FILTER=m
  706. +CONFIG_IP_NF_TARGET_REJECT=m
  707. +CONFIG_IP_NF_TARGET_ULOG=m
  708. +CONFIG_NF_NAT_IPV4=m
  709. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  710. +CONFIG_IP_NF_TARGET_NETMAP=m
  711. +CONFIG_IP_NF_TARGET_REDIRECT=m
  712. +CONFIG_IP_NF_MANGLE=m
  713. +CONFIG_IP_NF_TARGET_ECN=m
  714. +CONFIG_IP_NF_TARGET_TTL=m
  715. +CONFIG_IP_NF_RAW=m
  716. +CONFIG_IP_NF_ARPTABLES=m
  717. +CONFIG_IP_NF_ARPFILTER=m
  718. +CONFIG_IP_NF_ARP_MANGLE=m
  719. +CONFIG_NF_CONNTRACK_IPV6=m
  720. +CONFIG_IP6_NF_IPTABLES=m
  721. +CONFIG_IP6_NF_MATCH_AH=m
  722. +CONFIG_IP6_NF_MATCH_EUI64=m
  723. +CONFIG_IP6_NF_MATCH_FRAG=m
  724. +CONFIG_IP6_NF_MATCH_OPTS=m
  725. +CONFIG_IP6_NF_MATCH_HL=m
  726. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  727. +CONFIG_IP6_NF_MATCH_MH=m
  728. +CONFIG_IP6_NF_MATCH_RT=m
  729. +CONFIG_IP6_NF_TARGET_HL=m
  730. +CONFIG_IP6_NF_FILTER=m
  731. +CONFIG_IP6_NF_TARGET_REJECT=m
  732. +CONFIG_IP6_NF_MANGLE=m
  733. +CONFIG_IP6_NF_RAW=m
  734. +CONFIG_NF_NAT_IPV6=m
  735. +CONFIG_BRIDGE_NF_EBTABLES=m
  736. +CONFIG_BRIDGE_EBT_BROUTE=m
  737. +CONFIG_BRIDGE_EBT_T_FILTER=m
  738. +CONFIG_BRIDGE_EBT_T_NAT=m
  739. +CONFIG_BRIDGE_EBT_802_3=m
  740. +CONFIG_BRIDGE_EBT_AMONG=m
  741. +CONFIG_BRIDGE_EBT_ARP=m
  742. +CONFIG_BRIDGE_EBT_IP=m
  743. +CONFIG_BRIDGE_EBT_IP6=m
  744. +CONFIG_BRIDGE_EBT_LIMIT=m
  745. +CONFIG_BRIDGE_EBT_MARK=m
  746. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  747. +CONFIG_BRIDGE_EBT_STP=m
  748. +CONFIG_BRIDGE_EBT_VLAN=m
  749. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  750. +CONFIG_BRIDGE_EBT_DNAT=m
  751. +CONFIG_BRIDGE_EBT_MARK_T=m
  752. +CONFIG_BRIDGE_EBT_REDIRECT=m
  753. +CONFIG_BRIDGE_EBT_SNAT=m
  754. +CONFIG_BRIDGE_EBT_LOG=m
  755. +CONFIG_BRIDGE_EBT_ULOG=m
  756. +CONFIG_BRIDGE_EBT_NFLOG=m
  757. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  758. +CONFIG_L2TP=m
  759. +CONFIG_BRIDGE=m
  760. +CONFIG_VLAN_8021Q=m
  761. +CONFIG_VLAN_8021Q_GVRP=y
  762. +CONFIG_ATALK=m
  763. +CONFIG_NET_SCHED=y
  764. +CONFIG_NET_SCH_CBQ=m
  765. +CONFIG_NET_SCH_HTB=m
  766. +CONFIG_NET_SCH_HFSC=m
  767. +CONFIG_NET_SCH_PRIO=m
  768. +CONFIG_NET_SCH_MULTIQ=m
  769. +CONFIG_NET_SCH_RED=m
  770. +CONFIG_NET_SCH_SFB=m
  771. +CONFIG_NET_SCH_SFQ=m
  772. +CONFIG_NET_SCH_TEQL=m
  773. +CONFIG_NET_SCH_TBF=m
  774. +CONFIG_NET_SCH_GRED=m
  775. +CONFIG_NET_SCH_DSMARK=m
  776. +CONFIG_NET_SCH_NETEM=m
  777. +CONFIG_NET_SCH_DRR=m
  778. +CONFIG_NET_SCH_MQPRIO=m
  779. +CONFIG_NET_SCH_CHOKE=m
  780. +CONFIG_NET_SCH_QFQ=m
  781. +CONFIG_NET_SCH_CODEL=m
  782. +CONFIG_NET_SCH_FQ_CODEL=m
  783. +CONFIG_NET_SCH_INGRESS=m
  784. +CONFIG_NET_SCH_PLUG=m
  785. +CONFIG_NET_CLS_BASIC=m
  786. +CONFIG_NET_CLS_TCINDEX=m
  787. +CONFIG_NET_CLS_ROUTE4=m
  788. +CONFIG_NET_CLS_FW=m
  789. +CONFIG_NET_CLS_U32=m
  790. +CONFIG_CLS_U32_MARK=y
  791. +CONFIG_NET_CLS_RSVP=m
  792. +CONFIG_NET_CLS_RSVP6=m
  793. +CONFIG_NET_CLS_FLOW=m
  794. +CONFIG_NET_CLS_CGROUP=m
  795. +CONFIG_NET_EMATCH=y
  796. +CONFIG_NET_EMATCH_CMP=m
  797. +CONFIG_NET_EMATCH_NBYTE=m
  798. +CONFIG_NET_EMATCH_U32=m
  799. +CONFIG_NET_EMATCH_META=m
  800. +CONFIG_NET_EMATCH_TEXT=m
  801. +CONFIG_NET_EMATCH_IPSET=m
  802. +CONFIG_NET_CLS_ACT=y
  803. +CONFIG_NET_ACT_POLICE=m
  804. +CONFIG_NET_ACT_GACT=m
  805. +CONFIG_GACT_PROB=y
  806. +CONFIG_NET_ACT_MIRRED=m
  807. +CONFIG_NET_ACT_IPT=m
  808. +CONFIG_NET_ACT_NAT=m
  809. +CONFIG_NET_ACT_PEDIT=m
  810. +CONFIG_NET_ACT_SIMP=m
  811. +CONFIG_NET_ACT_SKBEDIT=m
  812. +CONFIG_NET_ACT_CSUM=m
  813. +CONFIG_BATMAN_ADV=m
  814. +CONFIG_OPENVSWITCH=m
  815. +CONFIG_NET_PKTGEN=m
  816. +CONFIG_HAMRADIO=y
  817. +CONFIG_AX25=m
  818. +CONFIG_NETROM=m
  819. +CONFIG_ROSE=m
  820. +CONFIG_MKISS=m
  821. +CONFIG_6PACK=m
  822. +CONFIG_BPQETHER=m
  823. +CONFIG_BAYCOM_SER_FDX=m
  824. +CONFIG_BAYCOM_SER_HDX=m
  825. +CONFIG_YAM=m
  826. +CONFIG_IRDA=m
  827. +CONFIG_IRLAN=m
  828. +CONFIG_IRNET=m
  829. +CONFIG_IRCOMM=m
  830. +CONFIG_IRDA_ULTRA=y
  831. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  832. +CONFIG_IRDA_FAST_RR=y
  833. +CONFIG_IRTTY_SIR=m
  834. +CONFIG_KINGSUN_DONGLE=m
  835. +CONFIG_KSDAZZLE_DONGLE=m
  836. +CONFIG_KS959_DONGLE=m
  837. +CONFIG_USB_IRDA=m
  838. +CONFIG_SIGMATEL_FIR=m
  839. +CONFIG_MCS_FIR=m
  840. +CONFIG_BT=m
  841. +CONFIG_BT_RFCOMM=m
  842. +CONFIG_BT_RFCOMM_TTY=y
  843. +CONFIG_BT_BNEP=m
  844. +CONFIG_BT_BNEP_MC_FILTER=y
  845. +CONFIG_BT_BNEP_PROTO_FILTER=y
  846. +CONFIG_BT_HIDP=m
  847. +CONFIG_BT_HCIBTUSB=m
  848. +CONFIG_BT_HCIBCM203X=m
  849. +CONFIG_BT_HCIBPA10X=m
  850. +CONFIG_BT_HCIBFUSB=m
  851. +CONFIG_BT_HCIVHCI=m
  852. +CONFIG_BT_MRVL=m
  853. +CONFIG_BT_MRVL_SDIO=m
  854. +CONFIG_BT_ATH3K=m
  855. +CONFIG_BT_WILINK=m
  856. +CONFIG_CFG80211=m
  857. +CONFIG_CFG80211_WEXT=y
  858. +CONFIG_MAC80211=m
  859. +CONFIG_MAC80211_RC_PID=y
  860. +CONFIG_MAC80211_MESH=y
  861. +CONFIG_WIMAX=m
  862. +CONFIG_RFKILL=m
  863. +CONFIG_RFKILL_INPUT=y
  864. +CONFIG_NET_9P=m
  865. +CONFIG_NFC=m
  866. +CONFIG_NFC_PN533=m
  867. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  868. +CONFIG_DEVTMPFS=y
  869. +CONFIG_DEVTMPFS_MOUNT=y
  870. +CONFIG_CMA=y
  871. +CONFIG_BLK_DEV_LOOP=y
  872. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  873. +CONFIG_BLK_DEV_DRBD=m
  874. +CONFIG_BLK_DEV_NBD=m
  875. +CONFIG_BLK_DEV_RAM=y
  876. +CONFIG_CDROM_PKTCDVD=m
  877. +CONFIG_SCSI=y
  878. +# CONFIG_SCSI_PROC_FS is not set
  879. +CONFIG_BLK_DEV_SD=m
  880. +CONFIG_BLK_DEV_SR=m
  881. +CONFIG_SCSI_MULTI_LUN=y
  882. +# CONFIG_SCSI_LOWLEVEL is not set
  883. +CONFIG_MD=y
  884. +CONFIG_NETDEVICES=y
  885. +CONFIG_DUMMY=m
  886. +CONFIG_NETCONSOLE=m
  887. +CONFIG_TUN=m
  888. +CONFIG_MDIO_BITBANG=m
  889. +CONFIG_PPP=m
  890. +CONFIG_PPP_BSDCOMP=m
  891. +CONFIG_PPP_DEFLATE=m
  892. +CONFIG_PPP_ASYNC=m
  893. +CONFIG_PPP_SYNC_TTY=m
  894. +CONFIG_SLIP=m
  895. +CONFIG_SLIP_COMPRESSED=y
  896. +CONFIG_USB_CATC=m
  897. +CONFIG_USB_KAWETH=m
  898. +CONFIG_USB_PEGASUS=m
  899. +CONFIG_USB_RTL8150=m
  900. +CONFIG_USB_RTL8152=m
  901. +CONFIG_USB_USBNET=y
  902. +CONFIG_USB_NET_AX8817X=m
  903. +CONFIG_USB_NET_CDCETHER=m
  904. +CONFIG_USB_NET_CDC_EEM=m
  905. +CONFIG_USB_NET_CDC_MBIM=m
  906. +CONFIG_USB_NET_DM9601=m
  907. +CONFIG_USB_NET_SMSC75XX=m
  908. +CONFIG_USB_NET_SMSC95XX=y
  909. +CONFIG_USB_NET_GL620A=m
  910. +CONFIG_USB_NET_NET1080=m
  911. +CONFIG_USB_NET_PLUSB=m
  912. +CONFIG_USB_NET_MCS7830=m
  913. +CONFIG_USB_NET_CDC_SUBSET=m
  914. +CONFIG_USB_ALI_M5632=y
  915. +CONFIG_USB_AN2720=y
  916. +CONFIG_USB_EPSON2888=y
  917. +CONFIG_USB_KC2190=y
  918. +CONFIG_USB_NET_ZAURUS=m
  919. +CONFIG_USB_NET_CX82310_ETH=m
  920. +CONFIG_USB_NET_KALMIA=m
  921. +CONFIG_USB_NET_QMI_WWAN=m
  922. +CONFIG_USB_NET_INT51X1=m
  923. +CONFIG_USB_IPHETH=m
  924. +CONFIG_USB_SIERRA_NET=m
  925. +CONFIG_USB_VL600=m
  926. +CONFIG_LIBERTAS_THINFIRM=m
  927. +CONFIG_LIBERTAS_THINFIRM_USB=m
  928. +CONFIG_AT76C50X_USB=m
  929. +CONFIG_USB_ZD1201=m
  930. +CONFIG_USB_NET_RNDIS_WLAN=m
  931. +CONFIG_RTL8187=m
  932. +CONFIG_MAC80211_HWSIM=m
  933. +CONFIG_ATH_CARDS=m
  934. +CONFIG_ATH9K=m
  935. +CONFIG_ATH9K_HTC=m
  936. +CONFIG_CARL9170=m
  937. +CONFIG_ATH6KL=m
  938. +CONFIG_ATH6KL_USB=m
  939. +CONFIG_AR5523=m
  940. +CONFIG_ATH10K=m
  941. +CONFIG_B43=m
  942. +# CONFIG_B43_PHY_N is not set
  943. +CONFIG_B43LEGACY=m
  944. +CONFIG_HOSTAP=m
  945. +CONFIG_LIBERTAS=m
  946. +CONFIG_LIBERTAS_USB=m
  947. +CONFIG_LIBERTAS_SDIO=m
  948. +CONFIG_P54_COMMON=m
  949. +CONFIG_P54_USB=m
  950. +CONFIG_RT2X00=m
  951. +CONFIG_RT2500USB=m
  952. +CONFIG_RT73USB=m
  953. +CONFIG_RT2800USB=m
  954. +CONFIG_RT2800USB_RT53XX=y
  955. +CONFIG_RT2800USB_UNKNOWN=y
  956. +CONFIG_RTL8192CU=m
  957. +CONFIG_ZD1211RW=m
  958. +CONFIG_MWIFIEX=m
  959. +CONFIG_MWIFIEX_SDIO=m
  960. +CONFIG_WIMAX_I2400M_USB=m
  961. +CONFIG_INPUT_POLLDEV=m
  962. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  963. +CONFIG_INPUT_JOYDEV=m
  964. +CONFIG_INPUT_EVDEV=m
  965. +# CONFIG_INPUT_KEYBOARD is not set
  966. +# CONFIG_INPUT_MOUSE is not set
  967. +CONFIG_INPUT_JOYSTICK=y
  968. +CONFIG_JOYSTICK_IFORCE=m
  969. +CONFIG_JOYSTICK_IFORCE_USB=y
  970. +CONFIG_JOYSTICK_XPAD=m
  971. +CONFIG_JOYSTICK_XPAD_FF=y
  972. +CONFIG_INPUT_MISC=y
  973. +CONFIG_INPUT_AD714X=m
  974. +CONFIG_INPUT_ATI_REMOTE2=m
  975. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  976. +CONFIG_INPUT_POWERMATE=m
  977. +CONFIG_INPUT_YEALINK=m
  978. +CONFIG_INPUT_CM109=m
  979. +CONFIG_INPUT_UINPUT=m
  980. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  981. +CONFIG_INPUT_ADXL34X=m
  982. +CONFIG_INPUT_CMA3000=m
  983. +# CONFIG_SERIO is not set
  984. +CONFIG_VT_HW_CONSOLE_BINDING=y
  985. +# CONFIG_LEGACY_PTYS is not set
  986. +# CONFIG_DEVKMEM is not set
  987. +CONFIG_SERIAL_AMBA_PL011=y
  988. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  989. +# CONFIG_HW_RANDOM is not set
  990. +CONFIG_RAW_DRIVER=y
  991. +CONFIG_BRCM_CHAR_DRIVERS=y
  992. +CONFIG_BCM_VC_CMA=y
  993. +CONFIG_I2C=y
  994. +CONFIG_I2C_CHARDEV=m
  995. +CONFIG_I2C_BCM2708=m
  996. +CONFIG_SPI=y
  997. +CONFIG_SPI_BCM2708=m
  998. +CONFIG_SPI_SPIDEV=m
  999. +CONFIG_GPIO_SYSFS=y
  1000. +# CONFIG_HWMON is not set
  1001. +CONFIG_THERMAL=y
  1002. +CONFIG_THERMAL_BCM2835=y
  1003. +CONFIG_WATCHDOG=y
  1004. +CONFIG_BCM2708_WDT=m
  1005. +CONFIG_MEDIA_SUPPORT=m
  1006. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1007. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1008. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1009. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1010. +CONFIG_MEDIA_RC_SUPPORT=y
  1011. +CONFIG_MEDIA_CONTROLLER=y
  1012. +CONFIG_LIRC=m
  1013. +CONFIG_RC_DEVICES=y
  1014. +CONFIG_RC_ATI_REMOTE=m
  1015. +CONFIG_IR_IMON=m
  1016. +CONFIG_IR_MCEUSB=m
  1017. +CONFIG_IR_REDRAT3=m
  1018. +CONFIG_IR_STREAMZAP=m
  1019. +CONFIG_IR_IGUANA=m
  1020. +CONFIG_IR_TTUSBIR=m
  1021. +CONFIG_RC_LOOPBACK=m
  1022. +CONFIG_IR_GPIO_CIR=m
  1023. +CONFIG_MEDIA_USB_SUPPORT=y
  1024. +CONFIG_USB_VIDEO_CLASS=m
  1025. +CONFIG_USB_M5602=m
  1026. +CONFIG_USB_STV06XX=m
  1027. +CONFIG_USB_GL860=m
  1028. +CONFIG_USB_GSPCA_BENQ=m
  1029. +CONFIG_USB_GSPCA_CONEX=m
  1030. +CONFIG_USB_GSPCA_CPIA1=m
  1031. +CONFIG_USB_GSPCA_ETOMS=m
  1032. +CONFIG_USB_GSPCA_FINEPIX=m
  1033. +CONFIG_USB_GSPCA_JEILINJ=m
  1034. +CONFIG_USB_GSPCA_JL2005BCD=m
  1035. +CONFIG_USB_GSPCA_KINECT=m
  1036. +CONFIG_USB_GSPCA_KONICA=m
  1037. +CONFIG_USB_GSPCA_MARS=m
  1038. +CONFIG_USB_GSPCA_MR97310A=m
  1039. +CONFIG_USB_GSPCA_NW80X=m
  1040. +CONFIG_USB_GSPCA_OV519=m
  1041. +CONFIG_USB_GSPCA_OV534=m
  1042. +CONFIG_USB_GSPCA_OV534_9=m
  1043. +CONFIG_USB_GSPCA_PAC207=m
  1044. +CONFIG_USB_GSPCA_PAC7302=m
  1045. +CONFIG_USB_GSPCA_PAC7311=m
  1046. +CONFIG_USB_GSPCA_SE401=m
  1047. +CONFIG_USB_GSPCA_SN9C2028=m
  1048. +CONFIG_USB_GSPCA_SN9C20X=m
  1049. +CONFIG_USB_GSPCA_SONIXB=m
  1050. +CONFIG_USB_GSPCA_SONIXJ=m
  1051. +CONFIG_USB_GSPCA_SPCA500=m
  1052. +CONFIG_USB_GSPCA_SPCA501=m
  1053. +CONFIG_USB_GSPCA_SPCA505=m
  1054. +CONFIG_USB_GSPCA_SPCA506=m
  1055. +CONFIG_USB_GSPCA_SPCA508=m
  1056. +CONFIG_USB_GSPCA_SPCA561=m
  1057. +CONFIG_USB_GSPCA_SPCA1528=m
  1058. +CONFIG_USB_GSPCA_SQ905=m
  1059. +CONFIG_USB_GSPCA_SQ905C=m
  1060. +CONFIG_USB_GSPCA_SQ930X=m
  1061. +CONFIG_USB_GSPCA_STK014=m
  1062. +CONFIG_USB_GSPCA_STV0680=m
  1063. +CONFIG_USB_GSPCA_SUNPLUS=m
  1064. +CONFIG_USB_GSPCA_T613=m
  1065. +CONFIG_USB_GSPCA_TOPRO=m
  1066. +CONFIG_USB_GSPCA_TV8532=m
  1067. +CONFIG_USB_GSPCA_VC032X=m
  1068. +CONFIG_USB_GSPCA_VICAM=m
  1069. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1070. +CONFIG_USB_GSPCA_ZC3XX=m
  1071. +CONFIG_USB_PWC=m
  1072. +CONFIG_VIDEO_CPIA2=m
  1073. +CONFIG_USB_ZR364XX=m
  1074. +CONFIG_USB_STKWEBCAM=m
  1075. +CONFIG_USB_S2255=m
  1076. +CONFIG_USB_SN9C102=m
  1077. +CONFIG_VIDEO_USBTV=m
  1078. +CONFIG_VIDEO_PVRUSB2=m
  1079. +CONFIG_VIDEO_HDPVR=m
  1080. +CONFIG_VIDEO_TLG2300=m
  1081. +CONFIG_VIDEO_USBVISION=m
  1082. +CONFIG_VIDEO_STK1160=m
  1083. +CONFIG_VIDEO_STK1160_AC97=y
  1084. +CONFIG_VIDEO_AU0828=m
  1085. +CONFIG_VIDEO_CX231XX=m
  1086. +CONFIG_VIDEO_CX231XX_ALSA=m
  1087. +CONFIG_VIDEO_CX231XX_DVB=m
  1088. +CONFIG_VIDEO_TM6000=m
  1089. +CONFIG_VIDEO_TM6000_ALSA=m
  1090. +CONFIG_VIDEO_TM6000_DVB=m
  1091. +CONFIG_DVB_USB=m
  1092. +CONFIG_DVB_USB_A800=m
  1093. +CONFIG_DVB_USB_DIBUSB_MB=m
  1094. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1095. +CONFIG_DVB_USB_DIBUSB_MC=m
  1096. +CONFIG_DVB_USB_DIB0700=m
  1097. +CONFIG_DVB_USB_UMT_010=m
  1098. +CONFIG_DVB_USB_CXUSB=m
  1099. +CONFIG_DVB_USB_M920X=m
  1100. +CONFIG_DVB_USB_DIGITV=m
  1101. +CONFIG_DVB_USB_VP7045=m
  1102. +CONFIG_DVB_USB_VP702X=m
  1103. +CONFIG_DVB_USB_GP8PSK=m
  1104. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1105. +CONFIG_DVB_USB_TTUSB2=m
  1106. +CONFIG_DVB_USB_DTT200U=m
  1107. +CONFIG_DVB_USB_OPERA1=m
  1108. +CONFIG_DVB_USB_AF9005=m
  1109. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1110. +CONFIG_DVB_USB_PCTV452E=m
  1111. +CONFIG_DVB_USB_DW2102=m
  1112. +CONFIG_DVB_USB_CINERGY_T2=m
  1113. +CONFIG_DVB_USB_DTV5100=m
  1114. +CONFIG_DVB_USB_FRIIO=m
  1115. +CONFIG_DVB_USB_AZ6027=m
  1116. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1117. +CONFIG_DVB_USB_V2=m
  1118. +CONFIG_DVB_USB_AF9015=m
  1119. +CONFIG_DVB_USB_AF9035=m
  1120. +CONFIG_DVB_USB_ANYSEE=m
  1121. +CONFIG_DVB_USB_AU6610=m
  1122. +CONFIG_DVB_USB_AZ6007=m
  1123. +CONFIG_DVB_USB_CE6230=m
  1124. +CONFIG_DVB_USB_EC168=m
  1125. +CONFIG_DVB_USB_GL861=m
  1126. +CONFIG_DVB_USB_IT913X=m
  1127. +CONFIG_DVB_USB_LME2510=m
  1128. +CONFIG_DVB_USB_MXL111SF=m
  1129. +CONFIG_DVB_USB_RTL28XXU=m
  1130. +CONFIG_SMS_USB_DRV=m
  1131. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1132. +CONFIG_VIDEO_EM28XX=m
  1133. +CONFIG_VIDEO_EM28XX_ALSA=m
  1134. +CONFIG_VIDEO_EM28XX_DVB=m
  1135. +CONFIG_RADIO_SI470X=y
  1136. +CONFIG_USB_SI470X=m
  1137. +CONFIG_USB_MR800=m
  1138. +CONFIG_USB_DSBR=m
  1139. +CONFIG_RADIO_SHARK=m
  1140. +CONFIG_RADIO_SHARK2=m
  1141. +CONFIG_RADIO_SI4713=m
  1142. +CONFIG_USB_KEENE=m
  1143. +CONFIG_USB_MA901=m
  1144. +CONFIG_RADIO_SAA7706H=m
  1145. +CONFIG_RADIO_TEF6862=m
  1146. +CONFIG_RADIO_WL128X=m
  1147. +CONFIG_FB=y
  1148. +CONFIG_FB_BCM2708=y
  1149. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1150. +CONFIG_LOGO=y
  1151. +# CONFIG_LOGO_LINUX_MONO is not set
  1152. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1153. +CONFIG_SOUND=y
  1154. +CONFIG_SND=m
  1155. +CONFIG_SND_SEQUENCER=m
  1156. +CONFIG_SND_SEQ_DUMMY=m
  1157. +CONFIG_SND_MIXER_OSS=m
  1158. +CONFIG_SND_PCM_OSS=m
  1159. +CONFIG_SND_SEQUENCER_OSS=y
  1160. +CONFIG_SND_HRTIMER=m
  1161. +CONFIG_SND_DUMMY=m
  1162. +CONFIG_SND_ALOOP=m
  1163. +CONFIG_SND_VIRMIDI=m
  1164. +CONFIG_SND_MTPAV=m
  1165. +CONFIG_SND_SERIAL_U16550=m
  1166. +CONFIG_SND_MPU401=m
  1167. +CONFIG_SND_BCM2835=m
  1168. +CONFIG_SND_USB_AUDIO=m
  1169. +CONFIG_SND_USB_UA101=m
  1170. +CONFIG_SND_USB_CAIAQ=m
  1171. +CONFIG_SND_USB_6FIRE=m
  1172. +CONFIG_SND_USB_HIFACE=m
  1173. +CONFIG_SOUND_PRIME=m
  1174. +CONFIG_HIDRAW=y
  1175. +CONFIG_HID_A4TECH=m
  1176. +CONFIG_HID_ACRUX=m
  1177. +CONFIG_HID_APPLE=m
  1178. +CONFIG_HID_BELKIN=m
  1179. +CONFIG_HID_CHERRY=m
  1180. +CONFIG_HID_CHICONY=m
  1181. +CONFIG_HID_CYPRESS=m
  1182. +CONFIG_HID_DRAGONRISE=m
  1183. +CONFIG_HID_EMS_FF=m
  1184. +CONFIG_HID_ELECOM=m
  1185. +CONFIG_HID_ELO=m
  1186. +CONFIG_HID_EZKEY=m
  1187. +CONFIG_HID_HOLTEK=m
  1188. +CONFIG_HID_KEYTOUCH=m
  1189. +CONFIG_HID_KYE=m
  1190. +CONFIG_HID_UCLOGIC=m
  1191. +CONFIG_HID_WALTOP=m
  1192. +CONFIG_HID_GYRATION=m
  1193. +CONFIG_HID_TWINHAN=m
  1194. +CONFIG_HID_KENSINGTON=m
  1195. +CONFIG_HID_LCPOWER=m
  1196. +CONFIG_HID_LOGITECH=m
  1197. +CONFIG_HID_MAGICMOUSE=m
  1198. +CONFIG_HID_MICROSOFT=m
  1199. +CONFIG_HID_MONTEREY=m
  1200. +CONFIG_HID_MULTITOUCH=m
  1201. +CONFIG_HID_NTRIG=m
  1202. +CONFIG_HID_ORTEK=m
  1203. +CONFIG_HID_PANTHERLORD=m
  1204. +CONFIG_HID_PETALYNX=m
  1205. +CONFIG_HID_PICOLCD=m
  1206. +CONFIG_HID_ROCCAT=m
  1207. +CONFIG_HID_SAMSUNG=m
  1208. +CONFIG_HID_SONY=m
  1209. +CONFIG_HID_SPEEDLINK=m
  1210. +CONFIG_HID_SUNPLUS=m
  1211. +CONFIG_HID_GREENASIA=m
  1212. +CONFIG_HID_SMARTJOYPLUS=m
  1213. +CONFIG_HID_TOPSEED=m
  1214. +CONFIG_HID_THINGM=m
  1215. +CONFIG_HID_THRUSTMASTER=m
  1216. +CONFIG_HID_WACOM=m
  1217. +CONFIG_HID_WIIMOTE=m
  1218. +CONFIG_HID_ZEROPLUS=m
  1219. +CONFIG_HID_ZYDACRON=m
  1220. +CONFIG_HID_PID=y
  1221. +CONFIG_USB_HIDDEV=y
  1222. +CONFIG_USB=y
  1223. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1224. +CONFIG_USB_MON=m
  1225. +CONFIG_USB_DWCOTG=y
  1226. +CONFIG_USB_PRINTER=m
  1227. +CONFIG_USB_STORAGE=y
  1228. +CONFIG_USB_STORAGE_REALTEK=m
  1229. +CONFIG_USB_STORAGE_DATAFAB=m
  1230. +CONFIG_USB_STORAGE_FREECOM=m
  1231. +CONFIG_USB_STORAGE_ISD200=m
  1232. +CONFIG_USB_STORAGE_USBAT=m
  1233. +CONFIG_USB_STORAGE_SDDR09=m
  1234. +CONFIG_USB_STORAGE_SDDR55=m
  1235. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1236. +CONFIG_USB_STORAGE_ALAUDA=m
  1237. +CONFIG_USB_STORAGE_ONETOUCH=m
  1238. +CONFIG_USB_STORAGE_KARMA=m
  1239. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1240. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1241. +CONFIG_USB_MDC800=m
  1242. +CONFIG_USB_MICROTEK=m
  1243. +CONFIG_USB_SERIAL=m
  1244. +CONFIG_USB_SERIAL_GENERIC=y
  1245. +CONFIG_USB_SERIAL_AIRCABLE=m
  1246. +CONFIG_USB_SERIAL_ARK3116=m
  1247. +CONFIG_USB_SERIAL_BELKIN=m
  1248. +CONFIG_USB_SERIAL_CH341=m
  1249. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1250. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1251. +CONFIG_USB_SERIAL_CP210X=m
  1252. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1253. +CONFIG_USB_SERIAL_EMPEG=m
  1254. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1255. +CONFIG_USB_SERIAL_FUNSOFT=m
  1256. +CONFIG_USB_SERIAL_VISOR=m
  1257. +CONFIG_USB_SERIAL_IPAQ=m
  1258. +CONFIG_USB_SERIAL_IR=m
  1259. +CONFIG_USB_SERIAL_EDGEPORT=m
  1260. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1261. +CONFIG_USB_SERIAL_F81232=m
  1262. +CONFIG_USB_SERIAL_GARMIN=m
  1263. +CONFIG_USB_SERIAL_IPW=m
  1264. +CONFIG_USB_SERIAL_IUU=m
  1265. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1266. +CONFIG_USB_SERIAL_KEYSPAN=m
  1267. +CONFIG_USB_SERIAL_KLSI=m
  1268. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1269. +CONFIG_USB_SERIAL_MCT_U232=m
  1270. +CONFIG_USB_SERIAL_METRO=m
  1271. +CONFIG_USB_SERIAL_MOS7720=m
  1272. +CONFIG_USB_SERIAL_MOS7840=m
  1273. +CONFIG_USB_SERIAL_MOTOROLA=m
  1274. +CONFIG_USB_SERIAL_NAVMAN=m
  1275. +CONFIG_USB_SERIAL_PL2303=m
  1276. +CONFIG_USB_SERIAL_OTI6858=m
  1277. +CONFIG_USB_SERIAL_QCAUX=m
  1278. +CONFIG_USB_SERIAL_QUALCOMM=m
  1279. +CONFIG_USB_SERIAL_SPCP8X5=m
  1280. +CONFIG_USB_SERIAL_HP4X=m
  1281. +CONFIG_USB_SERIAL_SAFE=m
  1282. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1283. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1284. +CONFIG_USB_SERIAL_SYMBOL=m
  1285. +CONFIG_USB_SERIAL_TI=m
  1286. +CONFIG_USB_SERIAL_CYBERJACK=m
  1287. +CONFIG_USB_SERIAL_XIRCOM=m
  1288. +CONFIG_USB_SERIAL_OPTION=m
  1289. +CONFIG_USB_SERIAL_OMNINET=m
  1290. +CONFIG_USB_SERIAL_OPTICON=m
  1291. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1292. +CONFIG_USB_SERIAL_XSENS_MT=m
  1293. +CONFIG_USB_SERIAL_ZIO=m
  1294. +CONFIG_USB_SERIAL_WISHBONE=m
  1295. +CONFIG_USB_SERIAL_ZTE=m
  1296. +CONFIG_USB_SERIAL_SSU100=m
  1297. +CONFIG_USB_SERIAL_QT2=m
  1298. +CONFIG_USB_SERIAL_DEBUG=m
  1299. +CONFIG_USB_EMI62=m
  1300. +CONFIG_USB_EMI26=m
  1301. +CONFIG_USB_ADUTUX=m
  1302. +CONFIG_USB_SEVSEG=m
  1303. +CONFIG_USB_RIO500=m
  1304. +CONFIG_USB_LEGOTOWER=m
  1305. +CONFIG_USB_LCD=m
  1306. +CONFIG_USB_LED=m
  1307. +CONFIG_USB_CYPRESS_CY7C63=m
  1308. +CONFIG_USB_CYTHERM=m
  1309. +CONFIG_USB_IDMOUSE=m
  1310. +CONFIG_USB_FTDI_ELAN=m
  1311. +CONFIG_USB_APPLEDISPLAY=m
  1312. +CONFIG_USB_LD=m
  1313. +CONFIG_USB_TRANCEVIBRATOR=m
  1314. +CONFIG_USB_IOWARRIOR=m
  1315. +CONFIG_USB_TEST=m
  1316. +CONFIG_USB_ISIGHTFW=m
  1317. +CONFIG_USB_YUREX=m
  1318. +CONFIG_MMC=y
  1319. +CONFIG_MMC_BLOCK_MINORS=32
  1320. +CONFIG_MMC_SDHCI=y
  1321. +CONFIG_MMC_SDHCI_PLTFM=y
  1322. +CONFIG_MMC_SDHCI_BCM2708=y
  1323. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1324. +CONFIG_LEDS_GPIO=m
  1325. +CONFIG_LEDS_TRIGGER_TIMER=y
  1326. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1327. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1328. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1329. +CONFIG_LEDS_TRIGGER_CPU=y
  1330. +CONFIG_LEDS_TRIGGER_GPIO=y
  1331. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1332. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1333. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1334. +CONFIG_RTC_CLASS=y
  1335. +CONFIG_RTC_DRV_DS1307=m
  1336. +CONFIG_RTC_DRV_DS1374=m
  1337. +CONFIG_RTC_DRV_DS1672=m
  1338. +CONFIG_RTC_DRV_DS3232=m
  1339. +CONFIG_RTC_DRV_MAX6900=m
  1340. +CONFIG_RTC_DRV_RS5C372=m
  1341. +CONFIG_RTC_DRV_ISL1208=m
  1342. +CONFIG_RTC_DRV_ISL12022=m
  1343. +CONFIG_RTC_DRV_X1205=m
  1344. +CONFIG_RTC_DRV_PCF2127=m
  1345. +CONFIG_RTC_DRV_PCF8523=m
  1346. +CONFIG_RTC_DRV_PCF8563=m
  1347. +CONFIG_RTC_DRV_PCF8583=m
  1348. +CONFIG_RTC_DRV_M41T80=m
  1349. +CONFIG_RTC_DRV_BQ32K=m
  1350. +CONFIG_RTC_DRV_S35390A=m
  1351. +CONFIG_RTC_DRV_FM3130=m
  1352. +CONFIG_RTC_DRV_RX8581=m
  1353. +CONFIG_RTC_DRV_RX8025=m
  1354. +CONFIG_RTC_DRV_EM3027=m
  1355. +CONFIG_RTC_DRV_RV3029C2=m
  1356. +CONFIG_RTC_DRV_M41T93=m
  1357. +CONFIG_RTC_DRV_M41T94=m
  1358. +CONFIG_RTC_DRV_DS1305=m
  1359. +CONFIG_RTC_DRV_DS1390=m
  1360. +CONFIG_RTC_DRV_MAX6902=m
  1361. +CONFIG_RTC_DRV_R9701=m
  1362. +CONFIG_RTC_DRV_RS5C348=m
  1363. +CONFIG_RTC_DRV_DS3234=m
  1364. +CONFIG_RTC_DRV_PCF2123=m
  1365. +CONFIG_RTC_DRV_RX4581=m
  1366. +CONFIG_UIO=m
  1367. +CONFIG_UIO_PDRV=m
  1368. +CONFIG_UIO_PDRV_GENIRQ=m
  1369. +# CONFIG_IOMMU_SUPPORT is not set
  1370. +CONFIG_EXT4_FS=y
  1371. +CONFIG_EXT4_FS_POSIX_ACL=y
  1372. +CONFIG_EXT4_FS_SECURITY=y
  1373. +CONFIG_REISERFS_FS=m
  1374. +CONFIG_REISERFS_FS_XATTR=y
  1375. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1376. +CONFIG_REISERFS_FS_SECURITY=y
  1377. +CONFIG_JFS_FS=m
  1378. +CONFIG_JFS_POSIX_ACL=y
  1379. +CONFIG_JFS_SECURITY=y
  1380. +CONFIG_JFS_STATISTICS=y
  1381. +CONFIG_XFS_FS=m
  1382. +CONFIG_XFS_QUOTA=y
  1383. +CONFIG_XFS_POSIX_ACL=y
  1384. +CONFIG_XFS_RT=y
  1385. +CONFIG_GFS2_FS=m
  1386. +CONFIG_OCFS2_FS=m
  1387. +CONFIG_BTRFS_FS=m
  1388. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1389. +CONFIG_NILFS2_FS=m
  1390. +CONFIG_FANOTIFY=y
  1391. +CONFIG_QFMT_V1=m
  1392. +CONFIG_QFMT_V2=m
  1393. +CONFIG_AUTOFS4_FS=y
  1394. +CONFIG_FUSE_FS=m
  1395. +CONFIG_CUSE=m
  1396. +CONFIG_FSCACHE=y
  1397. +CONFIG_FSCACHE_STATS=y
  1398. +CONFIG_FSCACHE_HISTOGRAM=y
  1399. +CONFIG_CACHEFILES=y
  1400. +CONFIG_ISO9660_FS=m
  1401. +CONFIG_JOLIET=y
  1402. +CONFIG_ZISOFS=y
  1403. +CONFIG_UDF_FS=m
  1404. +CONFIG_MSDOS_FS=y
  1405. +CONFIG_VFAT_FS=y
  1406. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1407. +CONFIG_NTFS_FS=m
  1408. +CONFIG_TMPFS=y
  1409. +CONFIG_TMPFS_POSIX_ACL=y
  1410. +CONFIG_CONFIGFS_FS=y
  1411. +CONFIG_SQUASHFS=m
  1412. +CONFIG_SQUASHFS_XATTR=y
  1413. +CONFIG_SQUASHFS_LZO=y
  1414. +CONFIG_SQUASHFS_XZ=y
  1415. +CONFIG_F2FS_FS=y
  1416. +CONFIG_NFS_FS=y
  1417. +CONFIG_NFS_V3_ACL=y
  1418. +CONFIG_NFS_V4=y
  1419. +CONFIG_ROOT_NFS=y
  1420. +CONFIG_NFS_FSCACHE=y
  1421. +CONFIG_NFSD=m
  1422. +CONFIG_NFSD_V3_ACL=y
  1423. +CONFIG_NFSD_V4=y
  1424. +CONFIG_CIFS=m
  1425. +CONFIG_CIFS_WEAK_PW_HASH=y
  1426. +CONFIG_CIFS_XATTR=y
  1427. +CONFIG_CIFS_POSIX=y
  1428. +CONFIG_9P_FS=m
  1429. +CONFIG_9P_FS_POSIX_ACL=y
  1430. +CONFIG_9P_FS_SECURITY=y
  1431. +CONFIG_NLS_DEFAULT="utf8"
  1432. +CONFIG_NLS_CODEPAGE_437=y
  1433. +CONFIG_NLS_CODEPAGE_737=m
  1434. +CONFIG_NLS_CODEPAGE_775=m
  1435. +CONFIG_NLS_CODEPAGE_850=m
  1436. +CONFIG_NLS_CODEPAGE_852=m
  1437. +CONFIG_NLS_CODEPAGE_855=m
  1438. +CONFIG_NLS_CODEPAGE_857=m
  1439. +CONFIG_NLS_CODEPAGE_860=m
  1440. +CONFIG_NLS_CODEPAGE_861=m
  1441. +CONFIG_NLS_CODEPAGE_862=m
  1442. +CONFIG_NLS_CODEPAGE_863=m
  1443. +CONFIG_NLS_CODEPAGE_864=m
  1444. +CONFIG_NLS_CODEPAGE_865=m
  1445. +CONFIG_NLS_CODEPAGE_866=m
  1446. +CONFIG_NLS_CODEPAGE_869=m
  1447. +CONFIG_NLS_CODEPAGE_936=m
  1448. +CONFIG_NLS_CODEPAGE_950=m
  1449. +CONFIG_NLS_CODEPAGE_932=m
  1450. +CONFIG_NLS_CODEPAGE_949=m
  1451. +CONFIG_NLS_CODEPAGE_874=m
  1452. +CONFIG_NLS_ISO8859_8=m
  1453. +CONFIG_NLS_CODEPAGE_1250=m
  1454. +CONFIG_NLS_CODEPAGE_1251=m
  1455. +CONFIG_NLS_ASCII=y
  1456. +CONFIG_NLS_ISO8859_1=m
  1457. +CONFIG_NLS_ISO8859_2=m
  1458. +CONFIG_NLS_ISO8859_3=m
  1459. +CONFIG_NLS_ISO8859_4=m
  1460. +CONFIG_NLS_ISO8859_5=m
  1461. +CONFIG_NLS_ISO8859_6=m
  1462. +CONFIG_NLS_ISO8859_7=m
  1463. +CONFIG_NLS_ISO8859_9=m
  1464. +CONFIG_NLS_ISO8859_13=m
  1465. +CONFIG_NLS_ISO8859_14=m
  1466. +CONFIG_NLS_ISO8859_15=m
  1467. +CONFIG_NLS_KOI8_R=m
  1468. +CONFIG_NLS_KOI8_U=m
  1469. +CONFIG_NLS_UTF8=m
  1470. +CONFIG_DLM=m
  1471. +CONFIG_PRINTK_TIME=y
  1472. +CONFIG_BOOT_PRINTK_DELAY=y
  1473. +CONFIG_DEBUG_INFO=y
  1474. +CONFIG_DEBUG_STACK_USAGE=y
  1475. +CONFIG_DEBUG_MEMORY_INIT=y
  1476. +CONFIG_DETECT_HUNG_TASK=y
  1477. +CONFIG_TIMER_STATS=y
  1478. +CONFIG_LATENCYTOP=y
  1479. +CONFIG_IRQSOFF_TRACER=y
  1480. +CONFIG_SCHED_TRACER=y
  1481. +CONFIG_STACK_TRACER=y
  1482. +CONFIG_BLK_DEV_IO_TRACE=y
  1483. +CONFIG_FUNCTION_PROFILER=y
  1484. +CONFIG_KGDB=y
  1485. +CONFIG_KGDB_KDB=y
  1486. +CONFIG_KDB_KEYBOARD=y
  1487. +CONFIG_STRICT_DEVMEM=y
  1488. +CONFIG_CRYPTO_SEQIV=m
  1489. +CONFIG_CRYPTO_CBC=y
  1490. +CONFIG_CRYPTO_HMAC=y
  1491. +CONFIG_CRYPTO_XCBC=m
  1492. +CONFIG_CRYPTO_MD5=y
  1493. +CONFIG_CRYPTO_SHA1=y
  1494. +CONFIG_CRYPTO_SHA512=m
  1495. +CONFIG_CRYPTO_TGR192=m
  1496. +CONFIG_CRYPTO_WP512=m
  1497. +CONFIG_CRYPTO_CAST5=m
  1498. +CONFIG_CRYPTO_DES=y
  1499. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1500. +# CONFIG_CRYPTO_HW is not set
  1501. +CONFIG_CRC_ITU_T=y
  1502. +CONFIG_LIBCRC32C=y
  1503. diff -Nur linux-3.11.10.orig/arch/arm/configs/bcmrpi_emergency_defconfig linux-3.11.10/arch/arm/configs/bcmrpi_emergency_defconfig
  1504. --- linux-3.11.10.orig/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1505. +++ linux-3.11.10/arch/arm/configs/bcmrpi_emergency_defconfig 2014-02-07 19:57:28.000000000 +0100
  1506. @@ -0,0 +1,532 @@
  1507. +CONFIG_EXPERIMENTAL=y
  1508. +# CONFIG_LOCALVERSION_AUTO is not set
  1509. +CONFIG_SYSVIPC=y
  1510. +CONFIG_POSIX_MQUEUE=y
  1511. +CONFIG_BSD_PROCESS_ACCT=y
  1512. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1513. +CONFIG_FHANDLE=y
  1514. +CONFIG_AUDIT=y
  1515. +CONFIG_IKCONFIG=y
  1516. +CONFIG_IKCONFIG_PROC=y
  1517. +CONFIG_BLK_DEV_INITRD=y
  1518. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1519. +CONFIG_CGROUP_FREEZER=y
  1520. +CONFIG_CGROUP_DEVICE=y
  1521. +CONFIG_CGROUP_CPUACCT=y
  1522. +CONFIG_RESOURCE_COUNTERS=y
  1523. +CONFIG_BLK_CGROUP=y
  1524. +CONFIG_NAMESPACES=y
  1525. +CONFIG_SCHED_AUTOGROUP=y
  1526. +CONFIG_EMBEDDED=y
  1527. +# CONFIG_COMPAT_BRK is not set
  1528. +CONFIG_SLAB=y
  1529. +CONFIG_PROFILING=y
  1530. +CONFIG_OPROFILE=m
  1531. +CONFIG_KPROBES=y
  1532. +CONFIG_MODULES=y
  1533. +CONFIG_MODULE_UNLOAD=y
  1534. +CONFIG_MODVERSIONS=y
  1535. +CONFIG_MODULE_SRCVERSION_ALL=y
  1536. +# CONFIG_BLK_DEV_BSG is not set
  1537. +CONFIG_BLK_DEV_THROTTLING=y
  1538. +CONFIG_CFQ_GROUP_IOSCHED=y
  1539. +CONFIG_ARCH_BCM2708=y
  1540. +CONFIG_NO_HZ=y
  1541. +CONFIG_HIGH_RES_TIMERS=y
  1542. +CONFIG_AEABI=y
  1543. +CONFIG_SECCOMP=y
  1544. +CONFIG_CC_STACKPROTECTOR=y
  1545. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1546. +CONFIG_ZBOOT_ROM_BSS=0x0
  1547. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1548. +CONFIG_KEXEC=y
  1549. +CONFIG_CPU_IDLE=y
  1550. +CONFIG_VFP=y
  1551. +CONFIG_BINFMT_MISC=m
  1552. +CONFIG_NET=y
  1553. +CONFIG_PACKET=y
  1554. +CONFIG_UNIX=y
  1555. +CONFIG_XFRM_USER=y
  1556. +CONFIG_NET_KEY=m
  1557. +CONFIG_INET=y
  1558. +CONFIG_IP_MULTICAST=y
  1559. +CONFIG_IP_PNP=y
  1560. +CONFIG_IP_PNP_DHCP=y
  1561. +CONFIG_IP_PNP_RARP=y
  1562. +CONFIG_SYN_COOKIES=y
  1563. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1564. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1565. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1566. +# CONFIG_INET_LRO is not set
  1567. +# CONFIG_INET_DIAG is not set
  1568. +# CONFIG_IPV6 is not set
  1569. +CONFIG_NET_PKTGEN=m
  1570. +CONFIG_IRDA=m
  1571. +CONFIG_IRLAN=m
  1572. +CONFIG_IRCOMM=m
  1573. +CONFIG_IRDA_ULTRA=y
  1574. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1575. +CONFIG_IRDA_FAST_RR=y
  1576. +CONFIG_IRTTY_SIR=m
  1577. +CONFIG_KINGSUN_DONGLE=m
  1578. +CONFIG_KSDAZZLE_DONGLE=m
  1579. +CONFIG_KS959_DONGLE=m
  1580. +CONFIG_USB_IRDA=m
  1581. +CONFIG_SIGMATEL_FIR=m
  1582. +CONFIG_MCS_FIR=m
  1583. +CONFIG_BT=m
  1584. +CONFIG_BT_L2CAP=y
  1585. +CONFIG_BT_SCO=y
  1586. +CONFIG_BT_RFCOMM=m
  1587. +CONFIG_BT_RFCOMM_TTY=y
  1588. +CONFIG_BT_BNEP=m
  1589. +CONFIG_BT_BNEP_MC_FILTER=y
  1590. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1591. +CONFIG_BT_HIDP=m
  1592. +CONFIG_BT_HCIBTUSB=m
  1593. +CONFIG_BT_HCIBCM203X=m
  1594. +CONFIG_BT_HCIBPA10X=m
  1595. +CONFIG_BT_HCIBFUSB=m
  1596. +CONFIG_BT_HCIVHCI=m
  1597. +CONFIG_BT_MRVL=m
  1598. +CONFIG_BT_MRVL_SDIO=m
  1599. +CONFIG_BT_ATH3K=m
  1600. +CONFIG_CFG80211=m
  1601. +CONFIG_MAC80211=m
  1602. +CONFIG_MAC80211_RC_PID=y
  1603. +CONFIG_MAC80211_MESH=y
  1604. +CONFIG_WIMAX=m
  1605. +CONFIG_NET_9P=m
  1606. +CONFIG_NFC=m
  1607. +CONFIG_NFC_PN533=m
  1608. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1609. +CONFIG_BLK_DEV_LOOP=y
  1610. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1611. +CONFIG_BLK_DEV_NBD=m
  1612. +CONFIG_BLK_DEV_RAM=y
  1613. +CONFIG_CDROM_PKTCDVD=m
  1614. +CONFIG_MISC_DEVICES=y
  1615. +CONFIG_SCSI=y
  1616. +# CONFIG_SCSI_PROC_FS is not set
  1617. +CONFIG_BLK_DEV_SD=y
  1618. +CONFIG_BLK_DEV_SR=m
  1619. +CONFIG_SCSI_MULTI_LUN=y
  1620. +# CONFIG_SCSI_LOWLEVEL is not set
  1621. +CONFIG_MD=y
  1622. +CONFIG_NETDEVICES=y
  1623. +CONFIG_TUN=m
  1624. +CONFIG_PHYLIB=m
  1625. +CONFIG_MDIO_BITBANG=m
  1626. +CONFIG_NET_ETHERNET=y
  1627. +# CONFIG_NETDEV_1000 is not set
  1628. +# CONFIG_NETDEV_10000 is not set
  1629. +CONFIG_LIBERTAS_THINFIRM=m
  1630. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1631. +CONFIG_AT76C50X_USB=m
  1632. +CONFIG_USB_ZD1201=m
  1633. +CONFIG_USB_NET_RNDIS_WLAN=m
  1634. +CONFIG_RTL8187=m
  1635. +CONFIG_MAC80211_HWSIM=m
  1636. +CONFIG_ATH_COMMON=m
  1637. +CONFIG_ATH9K=m
  1638. +CONFIG_ATH9K_HTC=m
  1639. +CONFIG_CARL9170=m
  1640. +CONFIG_B43=m
  1641. +CONFIG_B43LEGACY=m
  1642. +CONFIG_HOSTAP=m
  1643. +CONFIG_IWM=m
  1644. +CONFIG_LIBERTAS=m
  1645. +CONFIG_LIBERTAS_USB=m
  1646. +CONFIG_LIBERTAS_SDIO=m
  1647. +CONFIG_P54_COMMON=m
  1648. +CONFIG_P54_USB=m
  1649. +CONFIG_RT2X00=m
  1650. +CONFIG_RT2500USB=m
  1651. +CONFIG_RT73USB=m
  1652. +CONFIG_RT2800USB=m
  1653. +CONFIG_RT2800USB_RT53XX=y
  1654. +CONFIG_RTL8192CU=m
  1655. +CONFIG_WL1251=m
  1656. +CONFIG_WL12XX_MENU=m
  1657. +CONFIG_ZD1211RW=m
  1658. +CONFIG_MWIFIEX=m
  1659. +CONFIG_MWIFIEX_SDIO=m
  1660. +CONFIG_WIMAX_I2400M_USB=m
  1661. +CONFIG_USB_CATC=m
  1662. +CONFIG_USB_KAWETH=m
  1663. +CONFIG_USB_PEGASUS=m
  1664. +CONFIG_USB_RTL8150=m
  1665. +CONFIG_USB_USBNET=y
  1666. +CONFIG_USB_NET_AX8817X=m
  1667. +CONFIG_USB_NET_CDCETHER=m
  1668. +CONFIG_USB_NET_CDC_EEM=m
  1669. +CONFIG_USB_NET_DM9601=m
  1670. +CONFIG_USB_NET_SMSC75XX=m
  1671. +CONFIG_USB_NET_SMSC95XX=y
  1672. +CONFIG_USB_NET_GL620A=m
  1673. +CONFIG_USB_NET_NET1080=m
  1674. +CONFIG_USB_NET_PLUSB=m
  1675. +CONFIG_USB_NET_MCS7830=m
  1676. +CONFIG_USB_NET_CDC_SUBSET=m
  1677. +CONFIG_USB_ALI_M5632=y
  1678. +CONFIG_USB_AN2720=y
  1679. +CONFIG_USB_KC2190=y
  1680. +# CONFIG_USB_NET_ZAURUS is not set
  1681. +CONFIG_USB_NET_CX82310_ETH=m
  1682. +CONFIG_USB_NET_KALMIA=m
  1683. +CONFIG_USB_NET_INT51X1=m
  1684. +CONFIG_USB_IPHETH=m
  1685. +CONFIG_USB_SIERRA_NET=m
  1686. +CONFIG_USB_VL600=m
  1687. +CONFIG_PPP=m
  1688. +CONFIG_PPP_ASYNC=m
  1689. +CONFIG_PPP_SYNC_TTY=m
  1690. +CONFIG_PPP_DEFLATE=m
  1691. +CONFIG_PPP_BSDCOMP=m
  1692. +CONFIG_SLIP=m
  1693. +CONFIG_SLIP_COMPRESSED=y
  1694. +CONFIG_NETCONSOLE=m
  1695. +CONFIG_INPUT_POLLDEV=m
  1696. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1697. +CONFIG_INPUT_JOYDEV=m
  1698. +CONFIG_INPUT_EVDEV=m
  1699. +# CONFIG_INPUT_KEYBOARD is not set
  1700. +# CONFIG_INPUT_MOUSE is not set
  1701. +CONFIG_INPUT_MISC=y
  1702. +CONFIG_INPUT_AD714X=m
  1703. +CONFIG_INPUT_ATI_REMOTE=m
  1704. +CONFIG_INPUT_ATI_REMOTE2=m
  1705. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1706. +CONFIG_INPUT_POWERMATE=m
  1707. +CONFIG_INPUT_YEALINK=m
  1708. +CONFIG_INPUT_CM109=m
  1709. +CONFIG_INPUT_UINPUT=m
  1710. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1711. +CONFIG_INPUT_ADXL34X=m
  1712. +CONFIG_INPUT_CMA3000=m
  1713. +CONFIG_SERIO=m
  1714. +CONFIG_SERIO_RAW=m
  1715. +CONFIG_GAMEPORT=m
  1716. +CONFIG_GAMEPORT_NS558=m
  1717. +CONFIG_GAMEPORT_L4=m
  1718. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1719. +# CONFIG_LEGACY_PTYS is not set
  1720. +# CONFIG_DEVKMEM is not set
  1721. +CONFIG_SERIAL_AMBA_PL011=y
  1722. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1723. +# CONFIG_HW_RANDOM is not set
  1724. +CONFIG_RAW_DRIVER=y
  1725. +CONFIG_GPIO_SYSFS=y
  1726. +# CONFIG_HWMON is not set
  1727. +CONFIG_WATCHDOG=y
  1728. +CONFIG_BCM2708_WDT=m
  1729. +# CONFIG_MFD_SUPPORT is not set
  1730. +CONFIG_FB=y
  1731. +CONFIG_FB_BCM2708=y
  1732. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1733. +CONFIG_LOGO=y
  1734. +# CONFIG_LOGO_LINUX_MONO is not set
  1735. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1736. +CONFIG_SOUND=y
  1737. +CONFIG_SND=m
  1738. +CONFIG_SND_SEQUENCER=m
  1739. +CONFIG_SND_SEQ_DUMMY=m
  1740. +CONFIG_SND_MIXER_OSS=m
  1741. +CONFIG_SND_PCM_OSS=m
  1742. +CONFIG_SND_SEQUENCER_OSS=y
  1743. +CONFIG_SND_HRTIMER=m
  1744. +CONFIG_SND_DUMMY=m
  1745. +CONFIG_SND_ALOOP=m
  1746. +CONFIG_SND_VIRMIDI=m
  1747. +CONFIG_SND_MTPAV=m
  1748. +CONFIG_SND_SERIAL_U16550=m
  1749. +CONFIG_SND_MPU401=m
  1750. +CONFIG_SND_BCM2835=m
  1751. +CONFIG_SND_USB_AUDIO=m
  1752. +CONFIG_SND_USB_UA101=m
  1753. +CONFIG_SND_USB_CAIAQ=m
  1754. +CONFIG_SND_USB_6FIRE=m
  1755. +CONFIG_SOUND_PRIME=m
  1756. +CONFIG_HID_PID=y
  1757. +CONFIG_USB_HIDDEV=y
  1758. +CONFIG_HID_A4TECH=m
  1759. +CONFIG_HID_ACRUX=m
  1760. +CONFIG_HID_APPLE=m
  1761. +CONFIG_HID_BELKIN=m
  1762. +CONFIG_HID_CHERRY=m
  1763. +CONFIG_HID_CHICONY=m
  1764. +CONFIG_HID_CYPRESS=m
  1765. +CONFIG_HID_DRAGONRISE=m
  1766. +CONFIG_HID_EMS_FF=m
  1767. +CONFIG_HID_ELECOM=m
  1768. +CONFIG_HID_EZKEY=m
  1769. +CONFIG_HID_HOLTEK=m
  1770. +CONFIG_HID_KEYTOUCH=m
  1771. +CONFIG_HID_KYE=m
  1772. +CONFIG_HID_UCLOGIC=m
  1773. +CONFIG_HID_WALTOP=m
  1774. +CONFIG_HID_GYRATION=m
  1775. +CONFIG_HID_TWINHAN=m
  1776. +CONFIG_HID_KENSINGTON=m
  1777. +CONFIG_HID_LCPOWER=m
  1778. +CONFIG_HID_LOGITECH=m
  1779. +CONFIG_HID_MAGICMOUSE=m
  1780. +CONFIG_HID_MICROSOFT=m
  1781. +CONFIG_HID_MONTEREY=m
  1782. +CONFIG_HID_MULTITOUCH=m
  1783. +CONFIG_HID_NTRIG=m
  1784. +CONFIG_HID_ORTEK=m
  1785. +CONFIG_HID_PANTHERLORD=m
  1786. +CONFIG_HID_PETALYNX=m
  1787. +CONFIG_HID_PICOLCD=m
  1788. +CONFIG_HID_QUANTA=m
  1789. +CONFIG_HID_ROCCAT=m
  1790. +CONFIG_HID_SAMSUNG=m
  1791. +CONFIG_HID_SONY=m
  1792. +CONFIG_HID_SPEEDLINK=m
  1793. +CONFIG_HID_SUNPLUS=m
  1794. +CONFIG_HID_GREENASIA=m
  1795. +CONFIG_HID_SMARTJOYPLUS=m
  1796. +CONFIG_HID_TOPSEED=m
  1797. +CONFIG_HID_THRUSTMASTER=m
  1798. +CONFIG_HID_WACOM=m
  1799. +CONFIG_HID_WIIMOTE=m
  1800. +CONFIG_HID_ZEROPLUS=m
  1801. +CONFIG_HID_ZYDACRON=m
  1802. +CONFIG_USB=y
  1803. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1804. +CONFIG_USB_MON=m
  1805. +CONFIG_USB_DWCOTG=y
  1806. +CONFIG_USB_STORAGE=y
  1807. +CONFIG_USB_STORAGE_REALTEK=m
  1808. +CONFIG_USB_STORAGE_DATAFAB=m
  1809. +CONFIG_USB_STORAGE_FREECOM=m
  1810. +CONFIG_USB_STORAGE_ISD200=m
  1811. +CONFIG_USB_STORAGE_USBAT=m
  1812. +CONFIG_USB_STORAGE_SDDR09=m
  1813. +CONFIG_USB_STORAGE_SDDR55=m
  1814. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1815. +CONFIG_USB_STORAGE_ALAUDA=m
  1816. +CONFIG_USB_STORAGE_ONETOUCH=m
  1817. +CONFIG_USB_STORAGE_KARMA=m
  1818. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1819. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1820. +CONFIG_USB_UAS=y
  1821. +CONFIG_USB_LIBUSUAL=y
  1822. +CONFIG_USB_MDC800=m
  1823. +CONFIG_USB_MICROTEK=m
  1824. +CONFIG_USB_SERIAL=m
  1825. +CONFIG_USB_SERIAL_GENERIC=y
  1826. +CONFIG_USB_SERIAL_AIRCABLE=m
  1827. +CONFIG_USB_SERIAL_ARK3116=m
  1828. +CONFIG_USB_SERIAL_BELKIN=m
  1829. +CONFIG_USB_SERIAL_CH341=m
  1830. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1831. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1832. +CONFIG_USB_SERIAL_CP210X=m
  1833. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1834. +CONFIG_USB_SERIAL_EMPEG=m
  1835. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1836. +CONFIG_USB_SERIAL_FUNSOFT=m
  1837. +CONFIG_USB_SERIAL_VISOR=m
  1838. +CONFIG_USB_SERIAL_IPAQ=m
  1839. +CONFIG_USB_SERIAL_IR=m
  1840. +CONFIG_USB_SERIAL_EDGEPORT=m
  1841. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1842. +CONFIG_USB_SERIAL_GARMIN=m
  1843. +CONFIG_USB_SERIAL_IPW=m
  1844. +CONFIG_USB_SERIAL_IUU=m
  1845. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1846. +CONFIG_USB_SERIAL_KEYSPAN=m
  1847. +CONFIG_USB_SERIAL_KLSI=m
  1848. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1849. +CONFIG_USB_SERIAL_MCT_U232=m
  1850. +CONFIG_USB_SERIAL_MOS7720=m
  1851. +CONFIG_USB_SERIAL_MOS7840=m
  1852. +CONFIG_USB_SERIAL_MOTOROLA=m
  1853. +CONFIG_USB_SERIAL_NAVMAN=m
  1854. +CONFIG_USB_SERIAL_PL2303=m
  1855. +CONFIG_USB_SERIAL_OTI6858=m
  1856. +CONFIG_USB_SERIAL_QCAUX=m
  1857. +CONFIG_USB_SERIAL_QUALCOMM=m
  1858. +CONFIG_USB_SERIAL_SPCP8X5=m
  1859. +CONFIG_USB_SERIAL_HP4X=m
  1860. +CONFIG_USB_SERIAL_SAFE=m
  1861. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1862. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1863. +CONFIG_USB_SERIAL_SYMBOL=m
  1864. +CONFIG_USB_SERIAL_TI=m
  1865. +CONFIG_USB_SERIAL_CYBERJACK=m
  1866. +CONFIG_USB_SERIAL_XIRCOM=m
  1867. +CONFIG_USB_SERIAL_OPTION=m
  1868. +CONFIG_USB_SERIAL_OMNINET=m
  1869. +CONFIG_USB_SERIAL_OPTICON=m
  1870. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1871. +CONFIG_USB_SERIAL_ZIO=m
  1872. +CONFIG_USB_SERIAL_SSU100=m
  1873. +CONFIG_USB_SERIAL_DEBUG=m
  1874. +CONFIG_USB_EMI62=m
  1875. +CONFIG_USB_EMI26=m
  1876. +CONFIG_USB_ADUTUX=m
  1877. +CONFIG_USB_SEVSEG=m
  1878. +CONFIG_USB_RIO500=m
  1879. +CONFIG_USB_LEGOTOWER=m
  1880. +CONFIG_USB_LCD=m
  1881. +CONFIG_USB_LED=m
  1882. +CONFIG_USB_CYPRESS_CY7C63=m
  1883. +CONFIG_USB_CYTHERM=m
  1884. +CONFIG_USB_IDMOUSE=m
  1885. +CONFIG_USB_FTDI_ELAN=m
  1886. +CONFIG_USB_APPLEDISPLAY=m
  1887. +CONFIG_USB_LD=m
  1888. +CONFIG_USB_TRANCEVIBRATOR=m
  1889. +CONFIG_USB_IOWARRIOR=m
  1890. +CONFIG_USB_TEST=m
  1891. +CONFIG_USB_ISIGHTFW=m
  1892. +CONFIG_USB_YUREX=m
  1893. +CONFIG_MMC=y
  1894. +CONFIG_MMC_SDHCI=y
  1895. +CONFIG_MMC_SDHCI_PLTFM=y
  1896. +CONFIG_MMC_SDHCI_BCM2708=y
  1897. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1898. +CONFIG_LEDS_GPIO=y
  1899. +CONFIG_LEDS_TRIGGER_TIMER=m
  1900. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  1901. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  1902. +CONFIG_UIO=m
  1903. +CONFIG_UIO_PDRV=m
  1904. +CONFIG_UIO_PDRV_GENIRQ=m
  1905. +# CONFIG_IOMMU_SUPPORT is not set
  1906. +CONFIG_EXT4_FS=y
  1907. +CONFIG_EXT4_FS_POSIX_ACL=y
  1908. +CONFIG_EXT4_FS_SECURITY=y
  1909. +CONFIG_REISERFS_FS=m
  1910. +CONFIG_REISERFS_FS_XATTR=y
  1911. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1912. +CONFIG_REISERFS_FS_SECURITY=y
  1913. +CONFIG_JFS_FS=m
  1914. +CONFIG_JFS_POSIX_ACL=y
  1915. +CONFIG_JFS_SECURITY=y
  1916. +CONFIG_JFS_STATISTICS=y
  1917. +CONFIG_XFS_FS=m
  1918. +CONFIG_XFS_QUOTA=y
  1919. +CONFIG_XFS_POSIX_ACL=y
  1920. +CONFIG_XFS_RT=y
  1921. +CONFIG_GFS2_FS=m
  1922. +CONFIG_OCFS2_FS=m
  1923. +CONFIG_BTRFS_FS=m
  1924. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1925. +CONFIG_NILFS2_FS=m
  1926. +CONFIG_FANOTIFY=y
  1927. +CONFIG_AUTOFS4_FS=y
  1928. +CONFIG_FUSE_FS=m
  1929. +CONFIG_CUSE=m
  1930. +CONFIG_FSCACHE=y
  1931. +CONFIG_FSCACHE_STATS=y
  1932. +CONFIG_FSCACHE_HISTOGRAM=y
  1933. +CONFIG_CACHEFILES=y
  1934. +CONFIG_ISO9660_FS=m
  1935. +CONFIG_JOLIET=y
  1936. +CONFIG_ZISOFS=y
  1937. +CONFIG_UDF_FS=m
  1938. +CONFIG_MSDOS_FS=y
  1939. +CONFIG_VFAT_FS=y
  1940. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1941. +CONFIG_NTFS_FS=m
  1942. +CONFIG_TMPFS=y
  1943. +CONFIG_TMPFS_POSIX_ACL=y
  1944. +CONFIG_CONFIGFS_FS=y
  1945. +CONFIG_SQUASHFS=m
  1946. +CONFIG_SQUASHFS_XATTR=y
  1947. +CONFIG_SQUASHFS_LZO=y
  1948. +CONFIG_SQUASHFS_XZ=y
  1949. +CONFIG_NFS_FS=y
  1950. +CONFIG_NFS_V3=y
  1951. +CONFIG_NFS_V3_ACL=y
  1952. +CONFIG_NFS_V4=y
  1953. +CONFIG_ROOT_NFS=y
  1954. +CONFIG_NFS_FSCACHE=y
  1955. +CONFIG_CIFS=m
  1956. +CONFIG_CIFS_WEAK_PW_HASH=y
  1957. +CONFIG_CIFS_XATTR=y
  1958. +CONFIG_CIFS_POSIX=y
  1959. +CONFIG_9P_FS=m
  1960. +CONFIG_9P_FS_POSIX_ACL=y
  1961. +CONFIG_PARTITION_ADVANCED=y
  1962. +CONFIG_MAC_PARTITION=y
  1963. +CONFIG_EFI_PARTITION=y
  1964. +CONFIG_NLS_DEFAULT="utf8"
  1965. +CONFIG_NLS_CODEPAGE_437=y
  1966. +CONFIG_NLS_CODEPAGE_737=m
  1967. +CONFIG_NLS_CODEPAGE_775=m
  1968. +CONFIG_NLS_CODEPAGE_850=m
  1969. +CONFIG_NLS_CODEPAGE_852=m
  1970. +CONFIG_NLS_CODEPAGE_855=m
  1971. +CONFIG_NLS_CODEPAGE_857=m
  1972. +CONFIG_NLS_CODEPAGE_860=m
  1973. +CONFIG_NLS_CODEPAGE_861=m
  1974. +CONFIG_NLS_CODEPAGE_862=m
  1975. +CONFIG_NLS_CODEPAGE_863=m
  1976. +CONFIG_NLS_CODEPAGE_864=m
  1977. +CONFIG_NLS_CODEPAGE_865=m
  1978. +CONFIG_NLS_CODEPAGE_866=m
  1979. +CONFIG_NLS_CODEPAGE_869=m
  1980. +CONFIG_NLS_CODEPAGE_936=m
  1981. +CONFIG_NLS_CODEPAGE_950=m
  1982. +CONFIG_NLS_CODEPAGE_932=m
  1983. +CONFIG_NLS_CODEPAGE_949=m
  1984. +CONFIG_NLS_CODEPAGE_874=m
  1985. +CONFIG_NLS_ISO8859_8=m
  1986. +CONFIG_NLS_CODEPAGE_1250=m
  1987. +CONFIG_NLS_CODEPAGE_1251=m
  1988. +CONFIG_NLS_ASCII=y
  1989. +CONFIG_NLS_ISO8859_1=m
  1990. +CONFIG_NLS_ISO8859_2=m
  1991. +CONFIG_NLS_ISO8859_3=m
  1992. +CONFIG_NLS_ISO8859_4=m
  1993. +CONFIG_NLS_ISO8859_5=m
  1994. +CONFIG_NLS_ISO8859_6=m
  1995. +CONFIG_NLS_ISO8859_7=m
  1996. +CONFIG_NLS_ISO8859_9=m
  1997. +CONFIG_NLS_ISO8859_13=m
  1998. +CONFIG_NLS_ISO8859_14=m
  1999. +CONFIG_NLS_ISO8859_15=m
  2000. +CONFIG_NLS_KOI8_R=m
  2001. +CONFIG_NLS_KOI8_U=m
  2002. +CONFIG_NLS_UTF8=m
  2003. +CONFIG_PRINTK_TIME=y
  2004. +CONFIG_DETECT_HUNG_TASK=y
  2005. +CONFIG_TIMER_STATS=y
  2006. +CONFIG_DEBUG_STACK_USAGE=y
  2007. +CONFIG_DEBUG_INFO=y
  2008. +CONFIG_DEBUG_MEMORY_INIT=y
  2009. +CONFIG_BOOT_PRINTK_DELAY=y
  2010. +CONFIG_LATENCYTOP=y
  2011. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2012. +CONFIG_IRQSOFF_TRACER=y
  2013. +CONFIG_SCHED_TRACER=y
  2014. +CONFIG_STACK_TRACER=y
  2015. +CONFIG_BLK_DEV_IO_TRACE=y
  2016. +CONFIG_FUNCTION_PROFILER=y
  2017. +CONFIG_KGDB=y
  2018. +CONFIG_KGDB_KDB=y
  2019. +CONFIG_KDB_KEYBOARD=y
  2020. +CONFIG_STRICT_DEVMEM=y
  2021. +CONFIG_CRYPTO_AUTHENC=m
  2022. +CONFIG_CRYPTO_SEQIV=m
  2023. +CONFIG_CRYPTO_CBC=y
  2024. +CONFIG_CRYPTO_HMAC=y
  2025. +CONFIG_CRYPTO_XCBC=m
  2026. +CONFIG_CRYPTO_MD5=y
  2027. +CONFIG_CRYPTO_SHA1=y
  2028. +CONFIG_CRYPTO_SHA256=m
  2029. +CONFIG_CRYPTO_SHA512=m
  2030. +CONFIG_CRYPTO_TGR192=m
  2031. +CONFIG_CRYPTO_WP512=m
  2032. +CONFIG_CRYPTO_CAST5=m
  2033. +CONFIG_CRYPTO_DES=y
  2034. +CONFIG_CRYPTO_DEFLATE=m
  2035. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2036. +# CONFIG_CRYPTO_HW is not set
  2037. +CONFIG_CRC_ITU_T=y
  2038. +CONFIG_LIBCRC32C=y
  2039. diff -Nur linux-3.11.10.orig/arch/arm/configs/bcmrpi_quick_defconfig linux-3.11.10/arch/arm/configs/bcmrpi_quick_defconfig
  2040. --- linux-3.11.10.orig/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2041. +++ linux-3.11.10/arch/arm/configs/bcmrpi_quick_defconfig 2014-02-07 19:57:28.000000000 +0100
  2042. @@ -0,0 +1,197 @@
  2043. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2044. +CONFIG_LOCALVERSION="-quick"
  2045. +# CONFIG_LOCALVERSION_AUTO is not set
  2046. +# CONFIG_SWAP is not set
  2047. +CONFIG_SYSVIPC=y
  2048. +CONFIG_POSIX_MQUEUE=y
  2049. +CONFIG_NO_HZ=y
  2050. +CONFIG_HIGH_RES_TIMERS=y
  2051. +CONFIG_IKCONFIG=y
  2052. +CONFIG_IKCONFIG_PROC=y
  2053. +CONFIG_KALLSYMS_ALL=y
  2054. +CONFIG_EMBEDDED=y
  2055. +CONFIG_PERF_EVENTS=y
  2056. +# CONFIG_COMPAT_BRK is not set
  2057. +CONFIG_SLAB=y
  2058. +CONFIG_MODULES=y
  2059. +CONFIG_MODULE_UNLOAD=y
  2060. +CONFIG_MODVERSIONS=y
  2061. +CONFIG_MODULE_SRCVERSION_ALL=y
  2062. +# CONFIG_BLK_DEV_BSG is not set
  2063. +CONFIG_ARCH_BCM2708=y
  2064. +CONFIG_PREEMPT=y
  2065. +CONFIG_AEABI=y
  2066. +CONFIG_UACCESS_WITH_MEMCPY=y
  2067. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2068. +CONFIG_ZBOOT_ROM_BSS=0x0
  2069. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2070. +CONFIG_CPU_FREQ=y
  2071. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2072. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2073. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2074. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2075. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2076. +CONFIG_CPU_IDLE=y
  2077. +CONFIG_VFP=y
  2078. +CONFIG_BINFMT_MISC=y
  2079. +CONFIG_NET=y
  2080. +CONFIG_PACKET=y
  2081. +CONFIG_UNIX=y
  2082. +CONFIG_INET=y
  2083. +CONFIG_IP_MULTICAST=y
  2084. +CONFIG_IP_PNP=y
  2085. +CONFIG_IP_PNP_DHCP=y
  2086. +CONFIG_IP_PNP_RARP=y
  2087. +CONFIG_SYN_COOKIES=y
  2088. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2089. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2090. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2091. +# CONFIG_INET_LRO is not set
  2092. +# CONFIG_INET_DIAG is not set
  2093. +# CONFIG_IPV6 is not set
  2094. +# CONFIG_WIRELESS is not set
  2095. +CONFIG_DEVTMPFS=y
  2096. +CONFIG_DEVTMPFS_MOUNT=y
  2097. +CONFIG_BLK_DEV_LOOP=y
  2098. +CONFIG_BLK_DEV_RAM=y
  2099. +CONFIG_SCSI=y
  2100. +# CONFIG_SCSI_PROC_FS is not set
  2101. +# CONFIG_SCSI_LOWLEVEL is not set
  2102. +CONFIG_NETDEVICES=y
  2103. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2104. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2105. +# CONFIG_NET_VENDOR_FARADAY is not set
  2106. +# CONFIG_NET_VENDOR_INTEL is not set
  2107. +# CONFIG_NET_VENDOR_MARVELL is not set
  2108. +# CONFIG_NET_VENDOR_MICREL is not set
  2109. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2110. +# CONFIG_NET_VENDOR_SEEQ is not set
  2111. +# CONFIG_NET_VENDOR_STMICRO is not set
  2112. +# CONFIG_NET_VENDOR_WIZNET is not set
  2113. +CONFIG_USB_USBNET=y
  2114. +# CONFIG_USB_NET_AX8817X is not set
  2115. +# CONFIG_USB_NET_CDCETHER is not set
  2116. +# CONFIG_USB_NET_CDC_NCM is not set
  2117. +CONFIG_USB_NET_SMSC95XX=y
  2118. +# CONFIG_USB_NET_NET1080 is not set
  2119. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2120. +# CONFIG_USB_NET_ZAURUS is not set
  2121. +# CONFIG_WLAN is not set
  2122. +# CONFIG_INPUT_MOUSEDEV is not set
  2123. +CONFIG_INPUT_EVDEV=y
  2124. +# CONFIG_INPUT_KEYBOARD is not set
  2125. +# CONFIG_INPUT_MOUSE is not set
  2126. +# CONFIG_SERIO is not set
  2127. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2128. +# CONFIG_LEGACY_PTYS is not set
  2129. +# CONFIG_DEVKMEM is not set
  2130. +CONFIG_SERIAL_AMBA_PL011=y
  2131. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2132. +CONFIG_TTY_PRINTK=y
  2133. +CONFIG_HW_RANDOM=y
  2134. +CONFIG_HW_RANDOM_BCM2708=y
  2135. +CONFIG_RAW_DRIVER=y
  2136. +CONFIG_THERMAL=y
  2137. +CONFIG_THERMAL_BCM2835=y
  2138. +CONFIG_WATCHDOG=y
  2139. +CONFIG_BCM2708_WDT=y
  2140. +CONFIG_REGULATOR=y
  2141. +CONFIG_REGULATOR_DEBUG=y
  2142. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2143. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2144. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2145. +CONFIG_FB=y
  2146. +CONFIG_FB_BCM2708=y
  2147. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2148. +CONFIG_LOGO=y
  2149. +# CONFIG_LOGO_LINUX_MONO is not set
  2150. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2151. +CONFIG_SOUND=y
  2152. +CONFIG_SND=y
  2153. +CONFIG_SND_BCM2835=y
  2154. +# CONFIG_SND_USB is not set
  2155. +CONFIG_USB=y
  2156. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2157. +CONFIG_USB_DWCOTG=y
  2158. +CONFIG_MMC=y
  2159. +CONFIG_MMC_SDHCI=y
  2160. +CONFIG_MMC_SDHCI_PLTFM=y
  2161. +CONFIG_MMC_SDHCI_BCM2708=y
  2162. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2163. +CONFIG_NEW_LEDS=y
  2164. +CONFIG_LEDS_CLASS=y
  2165. +CONFIG_LEDS_TRIGGERS=y
  2166. +# CONFIG_IOMMU_SUPPORT is not set
  2167. +CONFIG_EXT4_FS=y
  2168. +CONFIG_EXT4_FS_POSIX_ACL=y
  2169. +CONFIG_EXT4_FS_SECURITY=y
  2170. +CONFIG_AUTOFS4_FS=y
  2171. +CONFIG_FSCACHE=y
  2172. +CONFIG_CACHEFILES=y
  2173. +CONFIG_MSDOS_FS=y
  2174. +CONFIG_VFAT_FS=y
  2175. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2176. +CONFIG_TMPFS=y
  2177. +CONFIG_TMPFS_POSIX_ACL=y
  2178. +CONFIG_CONFIGFS_FS=y
  2179. +# CONFIG_MISC_FILESYSTEMS is not set
  2180. +CONFIG_NFS_FS=y
  2181. +CONFIG_NFS_V3_ACL=y
  2182. +CONFIG_NFS_V4=y
  2183. +CONFIG_ROOT_NFS=y
  2184. +CONFIG_NFS_FSCACHE=y
  2185. +CONFIG_NLS_DEFAULT="utf8"
  2186. +CONFIG_NLS_CODEPAGE_437=y
  2187. +CONFIG_NLS_CODEPAGE_737=y
  2188. +CONFIG_NLS_CODEPAGE_775=y
  2189. +CONFIG_NLS_CODEPAGE_850=y
  2190. +CONFIG_NLS_CODEPAGE_852=y
  2191. +CONFIG_NLS_CODEPAGE_855=y
  2192. +CONFIG_NLS_CODEPAGE_857=y
  2193. +CONFIG_NLS_CODEPAGE_860=y
  2194. +CONFIG_NLS_CODEPAGE_861=y
  2195. +CONFIG_NLS_CODEPAGE_862=y
  2196. +CONFIG_NLS_CODEPAGE_863=y
  2197. +CONFIG_NLS_CODEPAGE_864=y
  2198. +CONFIG_NLS_CODEPAGE_865=y
  2199. +CONFIG_NLS_CODEPAGE_866=y
  2200. +CONFIG_NLS_CODEPAGE_869=y
  2201. +CONFIG_NLS_CODEPAGE_936=y
  2202. +CONFIG_NLS_CODEPAGE_950=y
  2203. +CONFIG_NLS_CODEPAGE_932=y
  2204. +CONFIG_NLS_CODEPAGE_949=y
  2205. +CONFIG_NLS_CODEPAGE_874=y
  2206. +CONFIG_NLS_ISO8859_8=y
  2207. +CONFIG_NLS_CODEPAGE_1250=y
  2208. +CONFIG_NLS_CODEPAGE_1251=y
  2209. +CONFIG_NLS_ASCII=y
  2210. +CONFIG_NLS_ISO8859_1=y
  2211. +CONFIG_NLS_ISO8859_2=y
  2212. +CONFIG_NLS_ISO8859_3=y
  2213. +CONFIG_NLS_ISO8859_4=y
  2214. +CONFIG_NLS_ISO8859_5=y
  2215. +CONFIG_NLS_ISO8859_6=y
  2216. +CONFIG_NLS_ISO8859_7=y
  2217. +CONFIG_NLS_ISO8859_9=y
  2218. +CONFIG_NLS_ISO8859_13=y
  2219. +CONFIG_NLS_ISO8859_14=y
  2220. +CONFIG_NLS_ISO8859_15=y
  2221. +CONFIG_NLS_UTF8=y
  2222. +CONFIG_PRINTK_TIME=y
  2223. +CONFIG_DEBUG_FS=y
  2224. +CONFIG_DETECT_HUNG_TASK=y
  2225. +# CONFIG_DEBUG_PREEMPT is not set
  2226. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2227. +# CONFIG_FTRACE is not set
  2228. +CONFIG_KGDB=y
  2229. +CONFIG_KGDB_KDB=y
  2230. +# CONFIG_ARM_UNWIND is not set
  2231. +CONFIG_CRYPTO_CBC=y
  2232. +CONFIG_CRYPTO_HMAC=y
  2233. +CONFIG_CRYPTO_MD5=y
  2234. +CONFIG_CRYPTO_SHA1=y
  2235. +CONFIG_CRYPTO_DES=y
  2236. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2237. +# CONFIG_CRYPTO_HW is not set
  2238. +CONFIG_CRC_ITU_T=y
  2239. +CONFIG_LIBCRC32C=y
  2240. diff -Nur linux-3.11.10.orig/arch/arm/include/asm/fiq.h linux-3.11.10/arch/arm/include/asm/fiq.h
  2241. --- linux-3.11.10.orig/arch/arm/include/asm/fiq.h 2013-11-29 19:42:37.000000000 +0100
  2242. +++ linux-3.11.10/arch/arm/include/asm/fiq.h 2014-02-07 19:57:28.000000000 +0100
  2243. @@ -42,6 +42,7 @@
  2244. /* helpers defined in fiqasm.S: */
  2245. extern void __set_fiq_regs(unsigned long const *regs);
  2246. extern void __get_fiq_regs(unsigned long *regs);
  2247. +extern void __FIQ_Branch(unsigned long *regs);
  2248. static inline void set_fiq_regs(struct pt_regs const *regs)
  2249. {
  2250. diff -Nur linux-3.11.10.orig/arch/arm/Kconfig linux-3.11.10/arch/arm/Kconfig
  2251. --- linux-3.11.10.orig/arch/arm/Kconfig 2013-11-29 19:42:37.000000000 +0100
  2252. +++ linux-3.11.10/arch/arm/Kconfig 2014-02-07 19:57:28.000000000 +0100
  2253. @@ -366,6 +366,23 @@
  2254. This enables support for systems based on Atmel
  2255. AT91RM9200 and AT91SAM9* processors.
  2256. +config ARCH_BCM2708
  2257. + bool "Broadcom BCM2708 family"
  2258. + select CPU_V6
  2259. + select ARM_AMBA
  2260. + select HAVE_CLK
  2261. + select HAVE_SCHED_CLOCK
  2262. + select NEED_MACH_MEMORY_H
  2263. + select CLKDEV_LOOKUP
  2264. + select ARCH_HAS_CPUFREQ
  2265. + select GENERIC_CLOCKEVENTS
  2266. + select ARM_ERRATA_411920
  2267. + select MACH_BCM2708
  2268. + select VC4
  2269. + select FIQ
  2270. + help
  2271. + This enables support for Broadcom BCM2708 boards.
  2272. +
  2273. config ARCH_CLPS711X
  2274. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2275. select ARCH_REQUIRE_GPIOLIB
  2276. @@ -1041,6 +1058,7 @@
  2277. source "arch/arm/mach-vt8500/Kconfig"
  2278. source "arch/arm/mach-w90x900/Kconfig"
  2279. +source "arch/arm/mach-bcm2708/Kconfig"
  2280. source "arch/arm/mach-zynq/Kconfig"
  2281. diff -Nur linux-3.11.10.orig/arch/arm/Kconfig.debug linux-3.11.10/arch/arm/Kconfig.debug
  2282. --- linux-3.11.10.orig/arch/arm/Kconfig.debug 2013-11-29 19:42:37.000000000 +0100
  2283. +++ linux-3.11.10/arch/arm/Kconfig.debug 2014-02-07 19:57:28.000000000 +0100
  2284. @@ -610,6 +610,14 @@
  2285. For more details about semihosting, please see
  2286. chapter 8 of DUI0203I_rvct_developer_guide.pdf from ARM Ltd.
  2287. + config DEBUG_BCM2708_UART0
  2288. + bool "Broadcom BCM2708 UART0 (PL011)"
  2289. + depends on MACH_BCM2708
  2290. + help
  2291. + Say Y here if you want the debug print routines to direct
  2292. + their output to UART 0. The port must have been initialised
  2293. + by the boot-loader before use.
  2294. +
  2295. endchoice
  2296. config DEBUG_EXYNOS_UART
  2297. diff -Nur linux-3.11.10.orig/arch/arm/kernel/fiqasm.S linux-3.11.10/arch/arm/kernel/fiqasm.S
  2298. --- linux-3.11.10.orig/arch/arm/kernel/fiqasm.S 2013-11-29 19:42:37.000000000 +0100
  2299. +++ linux-3.11.10/arch/arm/kernel/fiqasm.S 2014-02-07 19:57:28.000000000 +0100
  2300. @@ -25,6 +25,9 @@
  2301. ENTRY(__set_fiq_regs)
  2302. mov r2, #PSR_I_BIT | PSR_F_BIT | FIQ_MODE
  2303. mrs r1, cpsr
  2304. +@@@@@@@@@@@@@@@ hack: enable the fiq here to keep usb driver happy
  2305. + and r1, #~PSR_F_BIT
  2306. +@@@@@@@@@@@@@@@ endhack: (need to find better place for this to happen)
  2307. msr cpsr_c, r2 @ select FIQ mode
  2308. mov r0, r0 @ avoid hazard prior to ARMv4
  2309. ldmia r0!, {r8 - r12}
  2310. @@ -47,3 +50,7 @@
  2311. mov r0, r0 @ avoid hazard prior to ARMv4
  2312. mov pc, lr
  2313. ENDPROC(__get_fiq_regs)
  2314. +
  2315. +ENTRY(__FIQ_Branch)
  2316. + mov pc, r8
  2317. +ENDPROC(__FIQ_Branch)
  2318. diff -Nur linux-3.11.10.orig/arch/arm/kernel/fiq.c linux-3.11.10/arch/arm/kernel/fiq.c
  2319. --- linux-3.11.10.orig/arch/arm/kernel/fiq.c 2013-11-29 19:42:37.000000000 +0100
  2320. +++ linux-3.11.10/arch/arm/kernel/fiq.c 2014-02-07 19:57:28.000000000 +0100
  2321. @@ -142,6 +142,7 @@
  2322. EXPORT_SYMBOL(set_fiq_handler);
  2323. EXPORT_SYMBOL(__set_fiq_regs); /* defined in fiqasm.S */
  2324. EXPORT_SYMBOL(__get_fiq_regs); /* defined in fiqasm.S */
  2325. +EXPORT_SYMBOL(__FIQ_Branch); /* defined in fiqasm.S */
  2326. EXPORT_SYMBOL(claim_fiq);
  2327. EXPORT_SYMBOL(release_fiq);
  2328. EXPORT_SYMBOL(enable_fiq);
  2329. diff -Nur linux-3.11.10.orig/arch/arm/kernel/process.c linux-3.11.10/arch/arm/kernel/process.c
  2330. --- linux-3.11.10.orig/arch/arm/kernel/process.c 2013-11-29 19:42:37.000000000 +0100
  2331. +++ linux-3.11.10/arch/arm/kernel/process.c 2014-02-07 19:57:28.000000000 +0100
  2332. @@ -176,6 +176,16 @@
  2333. default_idle();
  2334. }
  2335. +char bcm2708_reboot_mode = 'h';
  2336. +
  2337. +int __init reboot_setup(char *str)
  2338. +{
  2339. + bcm2708_reboot_mode = str[0];
  2340. + return 1;
  2341. +}
  2342. +
  2343. +__setup("reboot=", reboot_setup);
  2344. +
  2345. /*
  2346. * Called by kexec, immediately prior to machine_kexec().
  2347. *
  2348. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/armctrl.c linux-3.11.10/arch/arm/mach-bcm2708/armctrl.c
  2349. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2350. +++ linux-3.11.10/arch/arm/mach-bcm2708/armctrl.c 2014-02-07 19:57:28.000000000 +0100
  2351. @@ -0,0 +1,219 @@
  2352. +/*
  2353. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2354. + *
  2355. + * Copyright (C) 2010 Broadcom
  2356. + *
  2357. + * This program is free software; you can redistribute it and/or modify
  2358. + * it under the terms of the GNU General Public License as published by
  2359. + * the Free Software Foundation; either version 2 of the License, or
  2360. + * (at your option) any later version.
  2361. + *
  2362. + * This program is distributed in the hope that it will be useful,
  2363. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2364. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2365. + * GNU General Public License for more details.
  2366. + *
  2367. + * You should have received a copy of the GNU General Public License
  2368. + * along with this program; if not, write to the Free Software
  2369. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2370. + */
  2371. +#include <linux/init.h>
  2372. +#include <linux/list.h>
  2373. +#include <linux/io.h>
  2374. +#include <linux/version.h>
  2375. +#include <linux/syscore_ops.h>
  2376. +#include <linux/interrupt.h>
  2377. +
  2378. +#include <asm/mach/irq.h>
  2379. +#include <mach/hardware.h>
  2380. +#include "armctrl.h"
  2381. +
  2382. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2383. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2384. + INTERRUPT_VC_JPEG,
  2385. + INTERRUPT_VC_USB,
  2386. + INTERRUPT_VC_3D,
  2387. + INTERRUPT_VC_DMA2,
  2388. + INTERRUPT_VC_DMA3,
  2389. + INTERRUPT_VC_I2C,
  2390. + INTERRUPT_VC_SPI,
  2391. + INTERRUPT_VC_I2SPCM,
  2392. + INTERRUPT_VC_SDIO,
  2393. + INTERRUPT_VC_UART,
  2394. + INTERRUPT_VC_ARASANSDIO
  2395. +};
  2396. +
  2397. +static void armctrl_mask_irq(struct irq_data *d)
  2398. +{
  2399. + static const unsigned int disables[4] = {
  2400. + ARM_IRQ_DIBL1,
  2401. + ARM_IRQ_DIBL2,
  2402. + ARM_IRQ_DIBL3,
  2403. + 0
  2404. + };
  2405. +
  2406. + if (d->irq >= FIQ_START) {
  2407. + writel(0, __io_address(ARM_IRQ_FAST));
  2408. + } else {
  2409. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2410. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2411. + }
  2412. +}
  2413. +
  2414. +static void armctrl_unmask_irq(struct irq_data *d)
  2415. +{
  2416. + static const unsigned int enables[4] = {
  2417. + ARM_IRQ_ENBL1,
  2418. + ARM_IRQ_ENBL2,
  2419. + ARM_IRQ_ENBL3,
  2420. + 0
  2421. + };
  2422. +
  2423. + if (d->irq >= FIQ_START) {
  2424. + unsigned int data =
  2425. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2426. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2427. + } else {
  2428. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2429. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2430. + }
  2431. +}
  2432. +
  2433. +#if defined(CONFIG_PM)
  2434. +
  2435. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2436. +
  2437. +/* Static defines
  2438. + * struct armctrl_device - VIC PM device (< 3.xx)
  2439. + * @sysdev: The system device which is registered. (< 3.xx)
  2440. + * @irq: The IRQ number for the base of the VIC.
  2441. + * @base: The register base for the VIC.
  2442. + * @resume_sources: A bitmask of interrupts for resume.
  2443. + * @resume_irqs: The IRQs enabled for resume.
  2444. + * @int_select: Save for VIC_INT_SELECT.
  2445. + * @int_enable: Save for VIC_INT_ENABLE.
  2446. + * @soft_int: Save for VIC_INT_SOFT.
  2447. + * @protect: Save for VIC_PROTECT.
  2448. + */
  2449. +struct armctrl_info {
  2450. + void __iomem *base;
  2451. + int irq;
  2452. + u32 resume_sources;
  2453. + u32 resume_irqs;
  2454. + u32 int_select;
  2455. + u32 int_enable;
  2456. + u32 soft_int;
  2457. + u32 protect;
  2458. +} armctrl;
  2459. +
  2460. +static int armctrl_suspend(void)
  2461. +{
  2462. + return 0;
  2463. +}
  2464. +
  2465. +static void armctrl_resume(void)
  2466. +{
  2467. + return;
  2468. +}
  2469. +
  2470. +/**
  2471. + * armctrl_pm_register - Register a VIC for later power management control
  2472. + * @base: The base address of the VIC.
  2473. + * @irq: The base IRQ for the VIC.
  2474. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2475. + *
  2476. + * For older kernels (< 3.xx) do -
  2477. + * Register the VIC with the system device tree so that it can be notified
  2478. + * of suspend and resume requests and ensure that the correct actions are
  2479. + * taken to re-instate the settings on resume.
  2480. + */
  2481. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2482. + u32 resume_sources)
  2483. +{
  2484. + armctrl.base = base;
  2485. + armctrl.resume_sources = resume_sources;
  2486. + armctrl.irq = irq;
  2487. +}
  2488. +
  2489. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2490. +{
  2491. + unsigned int off = d->irq & 31;
  2492. + u32 bit = 1 << off;
  2493. +
  2494. + if (!(bit & armctrl.resume_sources))
  2495. + return -EINVAL;
  2496. +
  2497. + if (on)
  2498. + armctrl.resume_irqs |= bit;
  2499. + else
  2500. + armctrl.resume_irqs &= ~bit;
  2501. +
  2502. + return 0;
  2503. +}
  2504. +
  2505. +#else
  2506. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2507. + u32 arg1)
  2508. +{
  2509. +}
  2510. +
  2511. +#define armctrl_suspend NULL
  2512. +#define armctrl_resume NULL
  2513. +#define armctrl_set_wake NULL
  2514. +#endif /* CONFIG_PM */
  2515. +
  2516. +static struct syscore_ops armctrl_syscore_ops = {
  2517. + .suspend = armctrl_suspend,
  2518. + .resume = armctrl_resume,
  2519. +};
  2520. +
  2521. +/**
  2522. + * armctrl_syscore_init - initicall to register VIC pm functions
  2523. + *
  2524. + * This is called via late_initcall() to register
  2525. + * the resources for the VICs due to the early
  2526. + * nature of the VIC's registration.
  2527. +*/
  2528. +static int __init armctrl_syscore_init(void)
  2529. +{
  2530. + register_syscore_ops(&armctrl_syscore_ops);
  2531. + return 0;
  2532. +}
  2533. +
  2534. +late_initcall(armctrl_syscore_init);
  2535. +
  2536. +static struct irq_chip armctrl_chip = {
  2537. + .name = "ARMCTRL",
  2538. + .irq_ack = armctrl_mask_irq,
  2539. + .irq_mask = armctrl_mask_irq,
  2540. + .irq_unmask = armctrl_unmask_irq,
  2541. + .irq_set_wake = armctrl_set_wake,
  2542. +};
  2543. +
  2544. +/**
  2545. + * armctrl_init - initialise a vectored interrupt controller
  2546. + * @base: iomem base address
  2547. + * @irq_start: starting interrupt number, must be muliple of 32
  2548. + * @armctrl_sources: bitmask of interrupt sources to allow
  2549. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2550. + */
  2551. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2552. + u32 armctrl_sources, u32 resume_sources)
  2553. +{
  2554. + unsigned int irq;
  2555. +
  2556. + for (irq = 0; irq < NR_IRQS; irq++) {
  2557. + unsigned int data = irq;
  2558. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2559. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2560. +
  2561. + irq_set_chip(irq, &armctrl_chip);
  2562. + irq_set_chip_data(irq, (void *)data);
  2563. + irq_set_handler(irq, handle_level_irq);
  2564. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2565. + }
  2566. +
  2567. + armctrl_pm_register(base, irq_start, resume_sources);
  2568. + init_FIQ(FIQ_START);
  2569. + return 0;
  2570. +}
  2571. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/armctrl.h linux-3.11.10/arch/arm/mach-bcm2708/armctrl.h
  2572. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2573. +++ linux-3.11.10/arch/arm/mach-bcm2708/armctrl.h 2014-02-07 19:57:28.000000000 +0100
  2574. @@ -0,0 +1,27 @@
  2575. +/*
  2576. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2577. + *
  2578. + * Copyright (C) 2010 Broadcom
  2579. + *
  2580. + * This program is free software; you can redistribute it and/or modify
  2581. + * it under the terms of the GNU General Public License as published by
  2582. + * the Free Software Foundation; either version 2 of the License, or
  2583. + * (at your option) any later version.
  2584. + *
  2585. + * This program is distributed in the hope that it will be useful,
  2586. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2587. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2588. + * GNU General Public License for more details.
  2589. + *
  2590. + * You should have received a copy of the GNU General Public License
  2591. + * along with this program; if not, write to the Free Software
  2592. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2593. + */
  2594. +
  2595. +#ifndef __BCM2708_ARMCTRL_H
  2596. +#define __BCM2708_ARMCTRL_H
  2597. +
  2598. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2599. + u32 armctrl_sources, u32 resume_sources);
  2600. +
  2601. +#endif
  2602. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708.c linux-3.11.10/arch/arm/mach-bcm2708/bcm2708.c
  2603. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2604. +++ linux-3.11.10/arch/arm/mach-bcm2708/bcm2708.c 2014-02-07 19:57:28.000000000 +0100
  2605. @@ -0,0 +1,917 @@
  2606. +/*
  2607. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2608. + *
  2609. + * Copyright (C) 2010 Broadcom
  2610. + *
  2611. + * This program is free software; you can redistribute it and/or modify
  2612. + * it under the terms of the GNU General Public License as published by
  2613. + * the Free Software Foundation; either version 2 of the License, or
  2614. + * (at your option) any later version.
  2615. + *
  2616. + * This program is distributed in the hope that it will be useful,
  2617. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2618. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2619. + * GNU General Public License for more details.
  2620. + *
  2621. + * You should have received a copy of the GNU General Public License
  2622. + * along with this program; if not, write to the Free Software
  2623. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2624. + */
  2625. +
  2626. +#include <linux/init.h>
  2627. +#include <linux/device.h>
  2628. +#include <linux/dma-mapping.h>
  2629. +#include <linux/serial_8250.h>
  2630. +#include <linux/platform_device.h>
  2631. +#include <linux/syscore_ops.h>
  2632. +#include <linux/interrupt.h>
  2633. +#include <linux/amba/bus.h>
  2634. +#include <linux/amba/clcd.h>
  2635. +#include <linux/clockchips.h>
  2636. +#include <linux/cnt32_to_63.h>
  2637. +#include <linux/io.h>
  2638. +#include <linux/module.h>
  2639. +#include <linux/spi/spi.h>
  2640. +#include <linux/w1-gpio.h>
  2641. +
  2642. +#include <linux/version.h>
  2643. +#include <linux/clkdev.h>
  2644. +#include <asm/system.h>
  2645. +#include <mach/hardware.h>
  2646. +#include <asm/irq.h>
  2647. +#include <linux/leds.h>
  2648. +#include <asm/mach-types.h>
  2649. +#include <asm/sched_clock.h>
  2650. +
  2651. +#include <asm/mach/arch.h>
  2652. +#include <asm/mach/flash.h>
  2653. +#include <asm/mach/irq.h>
  2654. +#include <asm/mach/time.h>
  2655. +#include <asm/mach/map.h>
  2656. +
  2657. +#include <mach/timex.h>
  2658. +#include <mach/dma.h>
  2659. +#include <mach/vcio.h>
  2660. +#include <mach/system.h>
  2661. +
  2662. +#include <linux/delay.h>
  2663. +
  2664. +#include "bcm2708.h"
  2665. +#include "armctrl.h"
  2666. +#include "clock.h"
  2667. +
  2668. +#ifdef CONFIG_BCM_VC_CMA
  2669. +#include <linux/broadcom/vc_cma.h>
  2670. +#endif
  2671. +
  2672. +
  2673. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2674. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2675. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2676. + * we're not going to use addresses outside this range (they're not in real
  2677. + * memory) so we don't bother.
  2678. + *
  2679. + * In the future we might include code to use this IOMMU to remap other
  2680. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2681. + * more legitimate.
  2682. + */
  2683. +#define DMA_MASK_BITS_COMMON 32
  2684. +
  2685. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2686. +#define W1_GPIO 4
  2687. +
  2688. +/* command line parameters */
  2689. +static unsigned boardrev, serial;
  2690. +static unsigned uart_clock;
  2691. +static unsigned reboot_part = 0;
  2692. +
  2693. +static void __init bcm2708_init_led(void);
  2694. +
  2695. +void __init bcm2708_init_irq(void)
  2696. +{
  2697. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2698. +}
  2699. +
  2700. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2701. + {
  2702. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2703. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2704. + .length = SZ_4K,
  2705. + .type = MT_DEVICE},
  2706. + {
  2707. + .virtual = IO_ADDRESS(UART0_BASE),
  2708. + .pfn = __phys_to_pfn(UART0_BASE),
  2709. + .length = SZ_4K,
  2710. + .type = MT_DEVICE},
  2711. + {
  2712. + .virtual = IO_ADDRESS(UART1_BASE),
  2713. + .pfn = __phys_to_pfn(UART1_BASE),
  2714. + .length = SZ_4K,
  2715. + .type = MT_DEVICE},
  2716. + {
  2717. + .virtual = IO_ADDRESS(DMA_BASE),
  2718. + .pfn = __phys_to_pfn(DMA_BASE),
  2719. + .length = SZ_4K,
  2720. + .type = MT_DEVICE},
  2721. + {
  2722. + .virtual = IO_ADDRESS(MCORE_BASE),
  2723. + .pfn = __phys_to_pfn(MCORE_BASE),
  2724. + .length = SZ_4K,
  2725. + .type = MT_DEVICE},
  2726. + {
  2727. + .virtual = IO_ADDRESS(ST_BASE),
  2728. + .pfn = __phys_to_pfn(ST_BASE),
  2729. + .length = SZ_4K,
  2730. + .type = MT_DEVICE},
  2731. + {
  2732. + .virtual = IO_ADDRESS(USB_BASE),
  2733. + .pfn = __phys_to_pfn(USB_BASE),
  2734. + .length = SZ_128K,
  2735. + .type = MT_DEVICE},
  2736. + {
  2737. + .virtual = IO_ADDRESS(PM_BASE),
  2738. + .pfn = __phys_to_pfn(PM_BASE),
  2739. + .length = SZ_4K,
  2740. + .type = MT_DEVICE},
  2741. + {
  2742. + .virtual = IO_ADDRESS(GPIO_BASE),
  2743. + .pfn = __phys_to_pfn(GPIO_BASE),
  2744. + .length = SZ_4K,
  2745. + .type = MT_DEVICE}
  2746. +};
  2747. +
  2748. +void __init bcm2708_map_io(void)
  2749. +{
  2750. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2751. +}
  2752. +
  2753. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2754. +#define STC_FREQ_HZ 1000000
  2755. +
  2756. +static inline uint32_t timer_read(void)
  2757. +{
  2758. + /* STC: a free running counter that increments at the rate of 1MHz */
  2759. + return readl(__io_address(ST_BASE + 0x04));
  2760. +}
  2761. +
  2762. +static unsigned long bcm2708_read_current_timer(void)
  2763. +{
  2764. + return timer_read();
  2765. +}
  2766. +
  2767. +static u32 notrace bcm2708_read_sched_clock(void)
  2768. +{
  2769. + return timer_read();
  2770. +}
  2771. +
  2772. +static cycle_t clksrc_read(struct clocksource *cs)
  2773. +{
  2774. + return timer_read();
  2775. +}
  2776. +
  2777. +static struct clocksource clocksource_stc = {
  2778. + .name = "stc",
  2779. + .rating = 300,
  2780. + .read = clksrc_read,
  2781. + .mask = CLOCKSOURCE_MASK(32),
  2782. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2783. +};
  2784. +
  2785. +unsigned long frc_clock_ticks32(void)
  2786. +{
  2787. + return timer_read();
  2788. +}
  2789. +
  2790. +static void __init bcm2708_clocksource_init(void)
  2791. +{
  2792. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2793. + printk(KERN_ERR "timer: failed to initialize clock "
  2794. + "source %s\n", clocksource_stc.name);
  2795. + }
  2796. +}
  2797. +
  2798. +
  2799. +/*
  2800. + * These are fixed clocks.
  2801. + */
  2802. +static struct clk ref24_clk = {
  2803. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2804. +};
  2805. +
  2806. +static struct clk osc_clk = {
  2807. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2808. + .rate = 27000000,
  2809. +#else
  2810. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2811. +#endif
  2812. +};
  2813. +
  2814. +/* warning - the USB needs a clock > 34MHz */
  2815. +
  2816. +static struct clk sdhost_clk = {
  2817. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2818. + .rate = 4000000, /* 4MHz */
  2819. +#else
  2820. + .rate = 250000000, /* 250MHz */
  2821. +#endif
  2822. +};
  2823. +
  2824. +static struct clk_lookup lookups[] = {
  2825. + { /* UART0 */
  2826. + .dev_id = "dev:f1",
  2827. + .clk = &ref24_clk,
  2828. + },
  2829. + { /* USB */
  2830. + .dev_id = "bcm2708_usb",
  2831. + .clk = &osc_clk,
  2832. + }, { /* SPI */
  2833. + .dev_id = "bcm2708_spi.0",
  2834. + .clk = &sdhost_clk,
  2835. + }, { /* BSC0 */
  2836. + .dev_id = "bcm2708_i2c.0",
  2837. + .clk = &sdhost_clk,
  2838. + }, { /* BSC1 */
  2839. + .dev_id = "bcm2708_i2c.1",
  2840. + .clk = &sdhost_clk,
  2841. + }
  2842. +};
  2843. +
  2844. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2845. +#define UART0_DMA { 15, 14 }
  2846. +
  2847. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2848. +
  2849. +static struct amba_device *amba_devs[] __initdata = {
  2850. + &uart0_device,
  2851. +};
  2852. +
  2853. +static struct resource bcm2708_dmaman_resources[] = {
  2854. + {
  2855. + .start = DMA_BASE,
  2856. + .end = DMA_BASE + SZ_4K - 1,
  2857. + .flags = IORESOURCE_MEM,
  2858. + }
  2859. +};
  2860. +
  2861. +static struct platform_device bcm2708_dmaman_device = {
  2862. + .name = BCM_DMAMAN_DRIVER_NAME,
  2863. + .id = 0, /* first bcm2708_dma */
  2864. + .resource = bcm2708_dmaman_resources,
  2865. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2866. +};
  2867. +
  2868. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2869. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2870. + .pin = W1_GPIO,
  2871. + .is_open_drain = 0,
  2872. +};
  2873. +
  2874. +static struct platform_device w1_device = {
  2875. + .name = "w1-gpio",
  2876. + .id = -1,
  2877. + .dev.platform_data = &w1_gpio_pdata,
  2878. +};
  2879. +#endif
  2880. +
  2881. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2882. +
  2883. +static struct platform_device bcm2708_fb_device = {
  2884. + .name = "bcm2708_fb",
  2885. + .id = -1, /* only one bcm2708_fb */
  2886. + .resource = NULL,
  2887. + .num_resources = 0,
  2888. + .dev = {
  2889. + .dma_mask = &fb_dmamask,
  2890. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2891. + },
  2892. +};
  2893. +
  2894. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  2895. + {
  2896. + .mapbase = UART1_BASE + 0x40,
  2897. + .irq = IRQ_AUX,
  2898. + .uartclk = 125000000,
  2899. + .regshift = 2,
  2900. + .iotype = UPIO_MEM,
  2901. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  2902. + .type = PORT_8250,
  2903. + },
  2904. + {},
  2905. +};
  2906. +
  2907. +static struct platform_device bcm2708_uart1_device = {
  2908. + .name = "serial8250",
  2909. + .id = PLAT8250_DEV_PLATFORM,
  2910. + .dev = {
  2911. + .platform_data = bcm2708_uart1_platform_data,
  2912. + },
  2913. +};
  2914. +
  2915. +static struct resource bcm2708_usb_resources[] = {
  2916. + [0] = {
  2917. + .start = USB_BASE,
  2918. + .end = USB_BASE + SZ_128K - 1,
  2919. + .flags = IORESOURCE_MEM,
  2920. + },
  2921. + [1] = {
  2922. + .start = MPHI_BASE,
  2923. + .end = MPHI_BASE + SZ_4K - 1,
  2924. + .flags = IORESOURCE_MEM,
  2925. + },
  2926. + [2] = {
  2927. + .start = IRQ_HOSTPORT,
  2928. + .end = IRQ_HOSTPORT,
  2929. + .flags = IORESOURCE_IRQ,
  2930. + },
  2931. +};
  2932. +
  2933. +bool fiq_fix_enable = true;
  2934. +
  2935. +static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
  2936. + [0] = {
  2937. + .start = USB_BASE,
  2938. + .end = USB_BASE + SZ_128K - 1,
  2939. + .flags = IORESOURCE_MEM,
  2940. + },
  2941. + [1] = {
  2942. + .start = IRQ_USB,
  2943. + .end = IRQ_USB,
  2944. + .flags = IORESOURCE_IRQ,
  2945. + },
  2946. +};
  2947. +
  2948. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2949. +
  2950. +static struct platform_device bcm2708_usb_device = {
  2951. + .name = "bcm2708_usb",
  2952. + .id = -1, /* only one bcm2708_usb */
  2953. + .resource = bcm2708_usb_resources,
  2954. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  2955. + .dev = {
  2956. + .dma_mask = &usb_dmamask,
  2957. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2958. + },
  2959. +};
  2960. +
  2961. +static struct resource bcm2708_vcio_resources[] = {
  2962. + [0] = { /* mailbox/semaphore/doorbell access */
  2963. + .start = MCORE_BASE,
  2964. + .end = MCORE_BASE + SZ_4K - 1,
  2965. + .flags = IORESOURCE_MEM,
  2966. + },
  2967. +};
  2968. +
  2969. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2970. +
  2971. +static struct platform_device bcm2708_vcio_device = {
  2972. + .name = BCM_VCIO_DRIVER_NAME,
  2973. + .id = -1, /* only one VideoCore I/O area */
  2974. + .resource = bcm2708_vcio_resources,
  2975. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  2976. + .dev = {
  2977. + .dma_mask = &vcio_dmamask,
  2978. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2979. + },
  2980. +};
  2981. +
  2982. +#ifdef CONFIG_BCM2708_GPIO
  2983. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  2984. +
  2985. +static struct resource bcm2708_gpio_resources[] = {
  2986. + [0] = { /* general purpose I/O */
  2987. + .start = GPIO_BASE,
  2988. + .end = GPIO_BASE + SZ_4K - 1,
  2989. + .flags = IORESOURCE_MEM,
  2990. + },
  2991. +};
  2992. +
  2993. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2994. +
  2995. +static struct platform_device bcm2708_gpio_device = {
  2996. + .name = BCM_GPIO_DRIVER_NAME,
  2997. + .id = -1, /* only one VideoCore I/O area */
  2998. + .resource = bcm2708_gpio_resources,
  2999. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3000. + .dev = {
  3001. + .dma_mask = &gpio_dmamask,
  3002. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3003. + },
  3004. +};
  3005. +#endif
  3006. +
  3007. +static struct resource bcm2708_systemtimer_resources[] = {
  3008. + [0] = { /* system timer access */
  3009. + .start = ST_BASE,
  3010. + .end = ST_BASE + SZ_4K - 1,
  3011. + .flags = IORESOURCE_MEM,
  3012. + },
  3013. + {
  3014. + .start = IRQ_TIMER3,
  3015. + .end = IRQ_TIMER3,
  3016. + .flags = IORESOURCE_IRQ,
  3017. + }
  3018. +
  3019. +};
  3020. +
  3021. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3022. +
  3023. +static struct platform_device bcm2708_systemtimer_device = {
  3024. + .name = "bcm2708_systemtimer",
  3025. + .id = -1, /* only one VideoCore I/O area */
  3026. + .resource = bcm2708_systemtimer_resources,
  3027. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3028. + .dev = {
  3029. + .dma_mask = &systemtimer_dmamask,
  3030. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3031. + },
  3032. +};
  3033. +
  3034. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3035. +static struct resource bcm2708_emmc_resources[] = {
  3036. + [0] = {
  3037. + .start = EMMC_BASE,
  3038. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3039. + /* the memory map actually makes SZ_4K available */
  3040. + .flags = IORESOURCE_MEM,
  3041. + },
  3042. + [1] = {
  3043. + .start = IRQ_ARASANSDIO,
  3044. + .end = IRQ_ARASANSDIO,
  3045. + .flags = IORESOURCE_IRQ,
  3046. + },
  3047. +};
  3048. +
  3049. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3050. +
  3051. +struct platform_device bcm2708_emmc_device = {
  3052. + .name = "bcm2708_sdhci",
  3053. + .id = 0,
  3054. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3055. + .resource = bcm2708_emmc_resources,
  3056. + .dev = {
  3057. + .dma_mask = &bcm2708_emmc_dmamask,
  3058. + .coherent_dma_mask = 0xffffffffUL},
  3059. +};
  3060. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3061. +
  3062. +static struct resource bcm2708_powerman_resources[] = {
  3063. + [0] = {
  3064. + .start = PM_BASE,
  3065. + .end = PM_BASE + SZ_256 - 1,
  3066. + .flags = IORESOURCE_MEM,
  3067. + },
  3068. +};
  3069. +
  3070. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3071. +
  3072. +struct platform_device bcm2708_powerman_device = {
  3073. + .name = "bcm2708_powerman",
  3074. + .id = 0,
  3075. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3076. + .resource = bcm2708_powerman_resources,
  3077. + .dev = {
  3078. + .dma_mask = &powerman_dmamask,
  3079. + .coherent_dma_mask = 0xffffffffUL},
  3080. +};
  3081. +
  3082. +
  3083. +static struct platform_device bcm2708_alsa_devices[] = {
  3084. + [0] = {
  3085. + .name = "bcm2835_AUD0",
  3086. + .id = 0, /* first audio device */
  3087. + .resource = 0,
  3088. + .num_resources = 0,
  3089. + },
  3090. + [1] = {
  3091. + .name = "bcm2835_AUD1",
  3092. + .id = 1, /* second audio device */
  3093. + .resource = 0,
  3094. + .num_resources = 0,
  3095. + },
  3096. + [2] = {
  3097. + .name = "bcm2835_AUD2",
  3098. + .id = 2, /* third audio device */
  3099. + .resource = 0,
  3100. + .num_resources = 0,
  3101. + },
  3102. + [3] = {
  3103. + .name = "bcm2835_AUD3",
  3104. + .id = 3, /* forth audio device */
  3105. + .resource = 0,
  3106. + .num_resources = 0,
  3107. + },
  3108. + [4] = {
  3109. + .name = "bcm2835_AUD4",
  3110. + .id = 4, /* fifth audio device */
  3111. + .resource = 0,
  3112. + .num_resources = 0,
  3113. + },
  3114. + [5] = {
  3115. + .name = "bcm2835_AUD5",
  3116. + .id = 5, /* sixth audio device */
  3117. + .resource = 0,
  3118. + .num_resources = 0,
  3119. + },
  3120. + [6] = {
  3121. + .name = "bcm2835_AUD6",
  3122. + .id = 6, /* seventh audio device */
  3123. + .resource = 0,
  3124. + .num_resources = 0,
  3125. + },
  3126. + [7] = {
  3127. + .name = "bcm2835_AUD7",
  3128. + .id = 7, /* eighth audio device */
  3129. + .resource = 0,
  3130. + .num_resources = 0,
  3131. + },
  3132. +};
  3133. +
  3134. +static struct resource bcm2708_spi_resources[] = {
  3135. + {
  3136. + .start = SPI0_BASE,
  3137. + .end = SPI0_BASE + SZ_256 - 1,
  3138. + .flags = IORESOURCE_MEM,
  3139. + }, {
  3140. + .start = IRQ_SPI,
  3141. + .end = IRQ_SPI,
  3142. + .flags = IORESOURCE_IRQ,
  3143. + }
  3144. +};
  3145. +
  3146. +
  3147. +static struct platform_device bcm2708_spi_device = {
  3148. + .name = "bcm2708_spi",
  3149. + .id = 0,
  3150. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3151. + .resource = bcm2708_spi_resources,
  3152. +};
  3153. +
  3154. +#ifdef CONFIG_BCM2708_SPIDEV
  3155. +static struct spi_board_info bcm2708_spi_devices[] = {
  3156. +#ifdef CONFIG_SPI_SPIDEV
  3157. + {
  3158. + .modalias = "spidev",
  3159. + .max_speed_hz = 500000,
  3160. + .bus_num = 0,
  3161. + .chip_select = 0,
  3162. + .mode = SPI_MODE_0,
  3163. + }, {
  3164. + .modalias = "spidev",
  3165. + .max_speed_hz = 500000,
  3166. + .bus_num = 0,
  3167. + .chip_select = 1,
  3168. + .mode = SPI_MODE_0,
  3169. + }
  3170. +#endif
  3171. +};
  3172. +#endif
  3173. +
  3174. +static struct resource bcm2708_bsc0_resources[] = {
  3175. + {
  3176. + .start = BSC0_BASE,
  3177. + .end = BSC0_BASE + SZ_256 - 1,
  3178. + .flags = IORESOURCE_MEM,
  3179. + }, {
  3180. + .start = INTERRUPT_I2C,
  3181. + .end = INTERRUPT_I2C,
  3182. + .flags = IORESOURCE_IRQ,
  3183. + }
  3184. +};
  3185. +
  3186. +static struct platform_device bcm2708_bsc0_device = {
  3187. + .name = "bcm2708_i2c",
  3188. + .id = 0,
  3189. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3190. + .resource = bcm2708_bsc0_resources,
  3191. +};
  3192. +
  3193. +
  3194. +static struct resource bcm2708_bsc1_resources[] = {
  3195. + {
  3196. + .start = BSC1_BASE,
  3197. + .end = BSC1_BASE + SZ_256 - 1,
  3198. + .flags = IORESOURCE_MEM,
  3199. + }, {
  3200. + .start = INTERRUPT_I2C,
  3201. + .end = INTERRUPT_I2C,
  3202. + .flags = IORESOURCE_IRQ,
  3203. + }
  3204. +};
  3205. +
  3206. +static struct platform_device bcm2708_bsc1_device = {
  3207. + .name = "bcm2708_i2c",
  3208. + .id = 1,
  3209. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3210. + .resource = bcm2708_bsc1_resources,
  3211. +};
  3212. +
  3213. +static struct platform_device bcm2835_hwmon_device = {
  3214. + .name = "bcm2835_hwmon",
  3215. +};
  3216. +
  3217. +static struct platform_device bcm2835_thermal_device = {
  3218. + .name = "bcm2835_thermal",
  3219. +};
  3220. +
  3221. +int __init bcm_register_device(struct platform_device *pdev)
  3222. +{
  3223. + int ret;
  3224. +
  3225. + ret = platform_device_register(pdev);
  3226. + if (ret)
  3227. + pr_debug("Unable to register platform device '%s': %d\n",
  3228. + pdev->name, ret);
  3229. +
  3230. + return ret;
  3231. +}
  3232. +
  3233. +int calc_rsts(int partition)
  3234. +{
  3235. + return PM_PASSWORD |
  3236. + ((partition & (1 << 0)) << 0) |
  3237. + ((partition & (1 << 1)) << 1) |
  3238. + ((partition & (1 << 2)) << 2) |
  3239. + ((partition & (1 << 3)) << 3) |
  3240. + ((partition & (1 << 4)) << 4) |
  3241. + ((partition & (1 << 5)) << 5);
  3242. +}
  3243. +
  3244. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3245. +{
  3246. + extern char bcm2708_reboot_mode;
  3247. + uint32_t pm_rstc, pm_wdog;
  3248. + uint32_t timeout = 10;
  3249. + uint32_t pm_rsts = 0;
  3250. +
  3251. + if(bcm2708_reboot_mode == 'q')
  3252. + {
  3253. + // NOOBS < 1.3 booting with reboot=q
  3254. + pm_rsts = readl(__io_address(PM_RSTS));
  3255. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3256. + }
  3257. + else if(bcm2708_reboot_mode == 'p')
  3258. + {
  3259. + // NOOBS < 1.3 halting
  3260. + pm_rsts = readl(__io_address(PM_RSTS));
  3261. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3262. + }
  3263. + else
  3264. + {
  3265. + pm_rsts = calc_rsts(reboot_part);
  3266. + }
  3267. +
  3268. + writel(pm_rsts, __io_address(PM_RSTS));
  3269. +
  3270. + /* Setup watchdog for reset */
  3271. + pm_rstc = readl(__io_address(PM_RSTC));
  3272. +
  3273. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3274. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3275. +
  3276. + writel(pm_wdog, __io_address(PM_WDOG));
  3277. + writel(pm_rstc, __io_address(PM_RSTC));
  3278. +}
  3279. +
  3280. +/* We can't really power off, but if we do the normal reset scheme, and indicate to bootcode.bin not to reboot, then most of the chip will be powered off */
  3281. +static void bcm2708_power_off(void)
  3282. +{
  3283. + extern char bcm2708_reboot_mode;
  3284. + if(bcm2708_reboot_mode == 'q')
  3285. + {
  3286. + // NOOBS < v1.3
  3287. + bcm2708_restart('p', "");
  3288. + }
  3289. + else
  3290. + {
  3291. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3292. + reboot_part = 63;
  3293. + /* continue with normal reset mechanism */
  3294. + bcm2708_restart(0, "");
  3295. + }
  3296. +}
  3297. +
  3298. +void __init bcm2708_init(void)
  3299. +{
  3300. + int i;
  3301. +
  3302. +#if defined(CONFIG_BCM_VC_CMA)
  3303. + vc_cma_early_init();
  3304. +#endif
  3305. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3306. + pm_power_off = bcm2708_power_off;
  3307. +
  3308. + if (uart_clock)
  3309. + lookups[0].clk->rate = uart_clock;
  3310. +
  3311. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3312. + clkdev_add(&lookups[i]);
  3313. +
  3314. + bcm_register_device(&bcm2708_dmaman_device);
  3315. + bcm_register_device(&bcm2708_vcio_device);
  3316. +#ifdef CONFIG_BCM2708_GPIO
  3317. + bcm_register_device(&bcm2708_gpio_device);
  3318. +#endif
  3319. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3320. + platform_device_register(&w1_device);
  3321. +#endif
  3322. + bcm_register_device(&bcm2708_systemtimer_device);
  3323. + bcm_register_device(&bcm2708_fb_device);
  3324. + if (!fiq_fix_enable)
  3325. + {
  3326. + bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
  3327. + bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
  3328. + }
  3329. + bcm_register_device(&bcm2708_usb_device);
  3330. + bcm_register_device(&bcm2708_uart1_device);
  3331. + bcm_register_device(&bcm2708_powerman_device);
  3332. +
  3333. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3334. + bcm_register_device(&bcm2708_emmc_device);
  3335. +#endif
  3336. + bcm2708_init_led();
  3337. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3338. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3339. +
  3340. + bcm_register_device(&bcm2708_spi_device);
  3341. + bcm_register_device(&bcm2708_bsc0_device);
  3342. + bcm_register_device(&bcm2708_bsc1_device);
  3343. +
  3344. + bcm_register_device(&bcm2835_hwmon_device);
  3345. + bcm_register_device(&bcm2835_thermal_device);
  3346. +
  3347. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3348. + struct amba_device *d = amba_devs[i];
  3349. + amba_device_register(d, &iomem_resource);
  3350. + }
  3351. + system_rev = boardrev;
  3352. + system_serial_low = serial;
  3353. +
  3354. +#ifdef CONFIG_BCM2708_SPIDEV
  3355. + spi_register_board_info(bcm2708_spi_devices,
  3356. + ARRAY_SIZE(bcm2708_spi_devices));
  3357. +#endif
  3358. +}
  3359. +
  3360. +static void timer_set_mode(enum clock_event_mode mode,
  3361. + struct clock_event_device *clk)
  3362. +{
  3363. + switch (mode) {
  3364. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3365. + case CLOCK_EVT_MODE_SHUTDOWN:
  3366. + break;
  3367. + case CLOCK_EVT_MODE_PERIODIC:
  3368. +
  3369. + case CLOCK_EVT_MODE_UNUSED:
  3370. + case CLOCK_EVT_MODE_RESUME:
  3371. +
  3372. + default:
  3373. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3374. + (int)mode);
  3375. + break;
  3376. + }
  3377. +
  3378. +}
  3379. +
  3380. +static int timer_set_next_event(unsigned long cycles,
  3381. + struct clock_event_device *unused)
  3382. +{
  3383. + unsigned long stc;
  3384. +
  3385. + stc = readl(__io_address(ST_BASE + 0x04));
  3386. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3387. + return 0;
  3388. +}
  3389. +
  3390. +static struct clock_event_device timer0_clockevent = {
  3391. + .name = "timer0",
  3392. + .shift = 32,
  3393. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3394. + .set_mode = timer_set_mode,
  3395. + .set_next_event = timer_set_next_event,
  3396. +};
  3397. +
  3398. +/*
  3399. + * IRQ handler for the timer
  3400. + */
  3401. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3402. +{
  3403. + struct clock_event_device *evt = &timer0_clockevent;
  3404. +
  3405. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3406. +
  3407. + evt->event_handler(evt);
  3408. +
  3409. + return IRQ_HANDLED;
  3410. +}
  3411. +
  3412. +static struct irqaction bcm2708_timer_irq = {
  3413. + .name = "BCM2708 Timer Tick",
  3414. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3415. + .handler = bcm2708_timer_interrupt,
  3416. +};
  3417. +
  3418. +/*
  3419. + * Set up timer interrupt, and return the current time in seconds.
  3420. + */
  3421. +
  3422. +static struct delay_timer bcm2708_delay_timer = {
  3423. + .read_current_timer = bcm2708_read_current_timer,
  3424. + .freq = STC_FREQ_HZ,
  3425. +};
  3426. +
  3427. +static void __init bcm2708_timer_init(void)
  3428. +{
  3429. + /* init high res timer */
  3430. + bcm2708_clocksource_init();
  3431. +
  3432. + /*
  3433. + * Initialise to a known state (all timers off)
  3434. + */
  3435. + writel(0, __io_address(ARM_T_CONTROL));
  3436. + /*
  3437. + * Make irqs happen for the system timer
  3438. + */
  3439. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3440. +
  3441. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3442. +
  3443. + timer0_clockevent.mult =
  3444. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3445. + timer0_clockevent.max_delta_ns =
  3446. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3447. + timer0_clockevent.min_delta_ns =
  3448. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3449. +
  3450. + timer0_clockevent.cpumask = cpumask_of(0);
  3451. + clockevents_register_device(&timer0_clockevent);
  3452. +
  3453. + register_current_timer_delay(&bcm2708_delay_timer);
  3454. +}
  3455. +
  3456. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3457. +#include <linux/leds.h>
  3458. +
  3459. +static struct gpio_led bcm2708_leds[] = {
  3460. + [0] = {
  3461. + .gpio = 16,
  3462. + .name = "led0",
  3463. + .default_trigger = "mmc0",
  3464. + .active_low = 1,
  3465. + },
  3466. +};
  3467. +
  3468. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3469. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3470. + .leds = bcm2708_leds,
  3471. +};
  3472. +
  3473. +static struct platform_device bcm2708_led_device = {
  3474. + .name = "leds-gpio",
  3475. + .id = -1,
  3476. + .dev = {
  3477. + .platform_data = &bcm2708_led_pdata,
  3478. + },
  3479. +};
  3480. +
  3481. +static void __init bcm2708_init_led(void)
  3482. +{
  3483. + platform_device_register(&bcm2708_led_device);
  3484. +}
  3485. +#else
  3486. +static inline void bcm2708_init_led(void)
  3487. +{
  3488. +}
  3489. +#endif
  3490. +
  3491. +void __init bcm2708_init_early(void)
  3492. +{
  3493. + /*
  3494. + * Some devices allocate their coherent buffers from atomic
  3495. + * context. Increase size of atomic coherent pool to make sure such
  3496. + * the allocations won't fail.
  3497. + */
  3498. + init_dma_coherent_pool_size(SZ_4M);
  3499. +}
  3500. +
  3501. +static void __init board_reserve(void)
  3502. +{
  3503. +#if defined(CONFIG_BCM_VC_CMA)
  3504. + vc_cma_reserve();
  3505. +#endif
  3506. +}
  3507. +
  3508. +MACHINE_START(BCM2708, "BCM2708")
  3509. + /* Maintainer: Broadcom Europe Ltd. */
  3510. + .map_io = bcm2708_map_io,
  3511. + .init_irq = bcm2708_init_irq,
  3512. + .init_time = bcm2708_timer_init,
  3513. + .init_machine = bcm2708_init,
  3514. + .init_early = bcm2708_init_early,
  3515. + .reserve = board_reserve,
  3516. + .restart = bcm2708_restart,
  3517. +MACHINE_END
  3518. +
  3519. +module_param(boardrev, uint, 0644);
  3520. +module_param(serial, uint, 0644);
  3521. +module_param(uart_clock, uint, 0644);
  3522. +module_param(reboot_part, uint, 0644);
  3523. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-3.11.10/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3524. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3525. +++ linux-3.11.10/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-02-07 19:57:28.000000000 +0100
  3526. @@ -0,0 +1,339 @@
  3527. +/*
  3528. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3529. + *
  3530. + * Copyright (C) 2010 Broadcom
  3531. + *
  3532. + * This program is free software; you can redistribute it and/or modify
  3533. + * it under the terms of the GNU General Public License version 2 as
  3534. + * published by the Free Software Foundation.
  3535. + *
  3536. + */
  3537. +
  3538. +#include <linux/spinlock.h>
  3539. +#include <linux/module.h>
  3540. +#include <linux/list.h>
  3541. +#include <linux/io.h>
  3542. +#include <linux/irq.h>
  3543. +#include <linux/interrupt.h>
  3544. +#include <linux/slab.h>
  3545. +#include <mach/gpio.h>
  3546. +#include <linux/gpio.h>
  3547. +#include <linux/platform_device.h>
  3548. +#include <mach/platform.h>
  3549. +
  3550. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3551. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3552. +#define BCM_GPIO_USE_IRQ 1
  3553. +
  3554. +#define GPIOFSEL(x) (0x00+(x)*4)
  3555. +#define GPIOSET(x) (0x1c+(x)*4)
  3556. +#define GPIOCLR(x) (0x28+(x)*4)
  3557. +#define GPIOLEV(x) (0x34+(x)*4)
  3558. +#define GPIOEDS(x) (0x40+(x)*4)
  3559. +#define GPIOREN(x) (0x4c+(x)*4)
  3560. +#define GPIOFEN(x) (0x58+(x)*4)
  3561. +#define GPIOHEN(x) (0x64+(x)*4)
  3562. +#define GPIOLEN(x) (0x70+(x)*4)
  3563. +#define GPIOAREN(x) (0x7c+(x)*4)
  3564. +#define GPIOAFEN(x) (0x88+(x)*4)
  3565. +#define GPIOUD(x) (0x94+(x)*4)
  3566. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3567. +
  3568. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3569. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3570. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3571. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3572. +};
  3573. +
  3574. + /* Each of the two spinlocks protects a different set of hardware
  3575. + * regiters and data structurs. This decouples the code of the IRQ from
  3576. + * the GPIO code. This also makes the case of a GPIO routine call from
  3577. + * the IRQ code simpler.
  3578. + */
  3579. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3580. +
  3581. +struct bcm2708_gpio {
  3582. + struct list_head list;
  3583. + void __iomem *base;
  3584. + struct gpio_chip gc;
  3585. + unsigned long rising;
  3586. + unsigned long falling;
  3587. +};
  3588. +
  3589. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3590. + int function)
  3591. +{
  3592. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3593. + unsigned long flags;
  3594. + unsigned gpiodir;
  3595. + unsigned gpio_bank = offset / 10;
  3596. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3597. +
  3598. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3599. + if (offset >= ARCH_NR_GPIOS)
  3600. + return -EINVAL;
  3601. +
  3602. + spin_lock_irqsave(&lock, flags);
  3603. +
  3604. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3605. + gpiodir &= ~(7 << gpio_field_offset);
  3606. + gpiodir |= function << gpio_field_offset;
  3607. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3608. + spin_unlock_irqrestore(&lock, flags);
  3609. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3610. +
  3611. + return 0;
  3612. +}
  3613. +
  3614. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3615. +{
  3616. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3617. +}
  3618. +
  3619. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3620. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3621. + int value)
  3622. +{
  3623. + int ret;
  3624. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3625. + if (ret >= 0)
  3626. + bcm2708_gpio_set(gc, offset, value);
  3627. + return ret;
  3628. +}
  3629. +
  3630. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3631. +{
  3632. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3633. + unsigned gpio_bank = offset / 32;
  3634. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3635. + unsigned lev;
  3636. +
  3637. + if (offset >= ARCH_NR_GPIOS)
  3638. + return 0;
  3639. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3640. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3641. + return 0x1 & (lev >> gpio_field_offset);
  3642. +}
  3643. +
  3644. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3645. +{
  3646. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3647. + unsigned gpio_bank = offset / 32;
  3648. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3649. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3650. + if (offset >= ARCH_NR_GPIOS)
  3651. + return;
  3652. + if (value)
  3653. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3654. + else
  3655. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3656. +}
  3657. +
  3658. +/*************************************************************************************************************************
  3659. + * bcm2708 GPIO IRQ
  3660. + */
  3661. +
  3662. +#if BCM_GPIO_USE_IRQ
  3663. +
  3664. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3665. +{
  3666. + return gpio_to_irq(gpio);
  3667. +}
  3668. +
  3669. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3670. +{
  3671. + unsigned irq = d->irq;
  3672. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3673. +
  3674. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
  3675. + return -EINVAL;
  3676. +
  3677. + if (type & IRQ_TYPE_EDGE_RISING) {
  3678. + gpio->rising |= (1 << irq_to_gpio(irq));
  3679. + } else {
  3680. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3681. + }
  3682. +
  3683. + if (type & IRQ_TYPE_EDGE_FALLING) {
  3684. + gpio->falling |= (1 << irq_to_gpio(irq));
  3685. + } else {
  3686. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3687. + }
  3688. + return 0;
  3689. +}
  3690. +
  3691. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3692. +{
  3693. + unsigned irq = d->irq;
  3694. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3695. + unsigned gn = irq_to_gpio(irq);
  3696. + unsigned gb = gn / 32;
  3697. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3698. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3699. +
  3700. + gn = gn % 32;
  3701. +
  3702. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3703. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3704. +}
  3705. +
  3706. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3707. +{
  3708. + unsigned irq = d->irq;
  3709. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3710. + unsigned gn = irq_to_gpio(irq);
  3711. + unsigned gb = gn / 32;
  3712. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3713. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3714. +
  3715. + gn = gn % 32;
  3716. +
  3717. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3718. +
  3719. + if (gpio->rising & (1 << gn)) {
  3720. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3721. + } else {
  3722. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3723. + }
  3724. +
  3725. + if (gpio->falling & (1 << gn)) {
  3726. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3727. + } else {
  3728. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3729. + }
  3730. +}
  3731. +
  3732. +static struct irq_chip bcm2708_irqchip = {
  3733. + .name = "GPIO",
  3734. + .irq_enable = bcm2708_gpio_irq_unmask,
  3735. + .irq_disable = bcm2708_gpio_irq_mask,
  3736. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3737. + .irq_mask = bcm2708_gpio_irq_mask,
  3738. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3739. +};
  3740. +
  3741. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3742. +{
  3743. + unsigned long edsr;
  3744. + unsigned bank;
  3745. + int i;
  3746. + unsigned gpio;
  3747. + for (bank = 0; bank <= 1; bank++) {
  3748. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3749. + for_each_set_bit(i, &edsr, 32) {
  3750. + gpio = i + bank * 32;
  3751. + generic_handle_irq(gpio_to_irq(gpio));
  3752. + }
  3753. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3754. + }
  3755. + return IRQ_HANDLED;
  3756. +}
  3757. +
  3758. +static struct irqaction bcm2708_gpio_irq = {
  3759. + .name = "BCM2708 GPIO catchall handler",
  3760. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3761. + .handler = bcm2708_gpio_interrupt,
  3762. +};
  3763. +
  3764. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  3765. +{
  3766. + unsigned irq;
  3767. +
  3768. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  3769. +
  3770. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  3771. + irq_set_chip_data(irq, ucb);
  3772. + irq_set_chip(irq, &bcm2708_irqchip);
  3773. + set_irq_flags(irq, IRQF_VALID);
  3774. + }
  3775. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  3776. +}
  3777. +
  3778. +#else
  3779. +
  3780. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  3781. +{
  3782. +}
  3783. +
  3784. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  3785. +
  3786. +static int bcm2708_gpio_probe(struct platform_device *dev)
  3787. +{
  3788. + struct bcm2708_gpio *ucb;
  3789. + struct resource *res;
  3790. + int err = 0;
  3791. +
  3792. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  3793. +
  3794. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  3795. + if (NULL == ucb) {
  3796. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  3797. + "mailbox memory\n");
  3798. + err = -ENOMEM;
  3799. + goto err;
  3800. + }
  3801. +
  3802. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  3803. +
  3804. + platform_set_drvdata(dev, ucb);
  3805. + ucb->base = __io_address(GPIO_BASE);
  3806. +
  3807. + ucb->gc.label = "bcm2708_gpio";
  3808. + ucb->gc.base = 0;
  3809. + ucb->gc.ngpio = ARCH_NR_GPIOS;
  3810. + ucb->gc.owner = THIS_MODULE;
  3811. +
  3812. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  3813. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  3814. + ucb->gc.get = bcm2708_gpio_get;
  3815. + ucb->gc.set = bcm2708_gpio_set;
  3816. + ucb->gc.can_sleep = 0;
  3817. +
  3818. + bcm2708_gpio_irq_init(ucb);
  3819. +
  3820. + err = gpiochip_add(&ucb->gc);
  3821. + if (err)
  3822. + goto err;
  3823. +
  3824. +err:
  3825. + return err;
  3826. +
  3827. +}
  3828. +
  3829. +static int bcm2708_gpio_remove(struct platform_device *dev)
  3830. +{
  3831. + int err = 0;
  3832. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  3833. +
  3834. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  3835. +
  3836. + err = gpiochip_remove(&ucb->gc);
  3837. +
  3838. + platform_set_drvdata(dev, NULL);
  3839. + kfree(ucb);
  3840. +
  3841. + return err;
  3842. +}
  3843. +
  3844. +static struct platform_driver bcm2708_gpio_driver = {
  3845. + .probe = bcm2708_gpio_probe,
  3846. + .remove = bcm2708_gpio_remove,
  3847. + .driver = {
  3848. + .name = "bcm2708_gpio"},
  3849. +};
  3850. +
  3851. +static int __init bcm2708_gpio_init(void)
  3852. +{
  3853. + return platform_driver_register(&bcm2708_gpio_driver);
  3854. +}
  3855. +
  3856. +static void __exit bcm2708_gpio_exit(void)
  3857. +{
  3858. + platform_driver_unregister(&bcm2708_gpio_driver);
  3859. +}
  3860. +
  3861. +module_init(bcm2708_gpio_init);
  3862. +module_exit(bcm2708_gpio_exit);
  3863. +
  3864. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  3865. +MODULE_LICENSE("GPL");
  3866. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708.h linux-3.11.10/arch/arm/mach-bcm2708/bcm2708.h
  3867. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  3868. +++ linux-3.11.10/arch/arm/mach-bcm2708/bcm2708.h 2014-02-07 19:57:28.000000000 +0100
  3869. @@ -0,0 +1,51 @@
  3870. +/*
  3871. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  3872. + *
  3873. + * BCM2708 machine support header
  3874. + *
  3875. + * Copyright (C) 2010 Broadcom
  3876. + *
  3877. + * This program is free software; you can redistribute it and/or modify
  3878. + * it under the terms of the GNU General Public License as published by
  3879. + * the Free Software Foundation; either version 2 of the License, or
  3880. + * (at your option) any later version.
  3881. + *
  3882. + * This program is distributed in the hope that it will be useful,
  3883. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3884. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3885. + * GNU General Public License for more details.
  3886. + *
  3887. + * You should have received a copy of the GNU General Public License
  3888. + * along with this program; if not, write to the Free Software
  3889. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  3890. + */
  3891. +
  3892. +#ifndef __BCM2708_BCM2708_H
  3893. +#define __BCM2708_BCM2708_H
  3894. +
  3895. +#include <linux/amba/bus.h>
  3896. +
  3897. +extern void __init bcm2708_init(void);
  3898. +extern void __init bcm2708_init_irq(void);
  3899. +extern void __init bcm2708_map_io(void);
  3900. +extern struct sys_timer bcm2708_timer;
  3901. +extern unsigned int mmc_status(struct device *dev);
  3902. +
  3903. +#define AMBA_DEVICE(name, busid, base, plat) \
  3904. +static struct amba_device name##_device = { \
  3905. + .dev = { \
  3906. + .coherent_dma_mask = ~0, \
  3907. + .init_name = busid, \
  3908. + .platform_data = plat, \
  3909. + }, \
  3910. + .res = { \
  3911. + .start = base##_BASE, \
  3912. + .end = (base##_BASE) + SZ_4K - 1,\
  3913. + .flags = IORESOURCE_MEM, \
  3914. + }, \
  3915. + .dma_mask = ~0, \
  3916. + .irq = base##_IRQ, \
  3917. + /* .dma = base##_DMA,*/ \
  3918. +}
  3919. +
  3920. +#endif
  3921. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/clock.c linux-3.11.10/arch/arm/mach-bcm2708/clock.c
  3922. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  3923. +++ linux-3.11.10/arch/arm/mach-bcm2708/clock.c 2014-02-07 19:57:28.000000000 +0100
  3924. @@ -0,0 +1,61 @@
  3925. +/*
  3926. + * linux/arch/arm/mach-bcm2708/clock.c
  3927. + *
  3928. + * Copyright (C) 2010 Broadcom
  3929. + *
  3930. + * This program is free software; you can redistribute it and/or modify
  3931. + * it under the terms of the GNU General Public License as published by
  3932. + * the Free Software Foundation; either version 2 of the License, or
  3933. + * (at your option) any later version.
  3934. + *
  3935. + * This program is distributed in the hope that it will be useful,
  3936. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3937. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3938. + * GNU General Public License for more details.
  3939. + *
  3940. + * You should have received a copy of the GNU General Public License
  3941. + * along with this program; if not, write to the Free Software
  3942. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  3943. + */
  3944. +#include <linux/module.h>
  3945. +#include <linux/kernel.h>
  3946. +#include <linux/device.h>
  3947. +#include <linux/list.h>
  3948. +#include <linux/errno.h>
  3949. +#include <linux/err.h>
  3950. +#include <linux/string.h>
  3951. +#include <linux/clk.h>
  3952. +#include <linux/mutex.h>
  3953. +
  3954. +#include <asm/clkdev.h>
  3955. +
  3956. +#include "clock.h"
  3957. +
  3958. +int clk_enable(struct clk *clk)
  3959. +{
  3960. + return 0;
  3961. +}
  3962. +EXPORT_SYMBOL(clk_enable);
  3963. +
  3964. +void clk_disable(struct clk *clk)
  3965. +{
  3966. +}
  3967. +EXPORT_SYMBOL(clk_disable);
  3968. +
  3969. +unsigned long clk_get_rate(struct clk *clk)
  3970. +{
  3971. + return clk->rate;
  3972. +}
  3973. +EXPORT_SYMBOL(clk_get_rate);
  3974. +
  3975. +long clk_round_rate(struct clk *clk, unsigned long rate)
  3976. +{
  3977. + return clk->rate;
  3978. +}
  3979. +EXPORT_SYMBOL(clk_round_rate);
  3980. +
  3981. +int clk_set_rate(struct clk *clk, unsigned long rate)
  3982. +{
  3983. + return -EIO;
  3984. +}
  3985. +EXPORT_SYMBOL(clk_set_rate);
  3986. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/clock.h linux-3.11.10/arch/arm/mach-bcm2708/clock.h
  3987. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  3988. +++ linux-3.11.10/arch/arm/mach-bcm2708/clock.h 2014-02-07 19:57:28.000000000 +0100
  3989. @@ -0,0 +1,24 @@
  3990. +/*
  3991. + * linux/arch/arm/mach-bcm2708/clock.h
  3992. + *
  3993. + * Copyright (C) 2010 Broadcom
  3994. + *
  3995. + * This program is free software; you can redistribute it and/or modify
  3996. + * it under the terms of the GNU General Public License as published by
  3997. + * the Free Software Foundation; either version 2 of the License, or
  3998. + * (at your option) any later version.
  3999. + *
  4000. + * This program is distributed in the hope that it will be useful,
  4001. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4002. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4003. + * GNU General Public License for more details.
  4004. + *
  4005. + * You should have received a copy of the GNU General Public License
  4006. + * along with this program; if not, write to the Free Software
  4007. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4008. + */
  4009. +struct module;
  4010. +
  4011. +struct clk {
  4012. + unsigned long rate;
  4013. +};
  4014. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/dma.c linux-3.11.10/arch/arm/mach-bcm2708/dma.c
  4015. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4016. +++ linux-3.11.10/arch/arm/mach-bcm2708/dma.c 2014-02-07 19:57:28.000000000 +0100
  4017. @@ -0,0 +1,399 @@
  4018. +/*
  4019. + * linux/arch/arm/mach-bcm2708/dma.c
  4020. + *
  4021. + * Copyright (C) 2010 Broadcom
  4022. + *
  4023. + * This program is free software; you can redistribute it and/or modify
  4024. + * it under the terms of the GNU General Public License version 2 as
  4025. + * published by the Free Software Foundation.
  4026. + */
  4027. +
  4028. +#include <linux/slab.h>
  4029. +#include <linux/device.h>
  4030. +#include <linux/platform_device.h>
  4031. +#include <linux/module.h>
  4032. +#include <linux/scatterlist.h>
  4033. +
  4034. +#include <mach/dma.h>
  4035. +#include <mach/irqs.h>
  4036. +
  4037. +/*****************************************************************************\
  4038. + * *
  4039. + * Configuration *
  4040. + * *
  4041. +\*****************************************************************************/
  4042. +
  4043. +#define CACHE_LINE_MASK 31
  4044. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4045. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4046. +
  4047. +/* valid only for channels 0 - 14, 15 has its own base address */
  4048. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4049. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4050. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4051. +
  4052. +
  4053. +/*****************************************************************************\
  4054. + * *
  4055. + * DMA Auxilliary Functions *
  4056. + * *
  4057. +\*****************************************************************************/
  4058. +
  4059. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4060. + section inside the DMA buffer and another section outside it.
  4061. + Even if we flush DMA buffers from the cache there is always the chance that
  4062. + during a DMA someone will access the part of a cache line that is outside
  4063. + the DMA buffer - which will then bring in unwelcome data.
  4064. + Without being able to dictate our own buffer pools we must insist that
  4065. + DMA buffers consist of a whole number of cache lines.
  4066. +*/
  4067. +
  4068. +extern int
  4069. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4070. +{
  4071. + int i;
  4072. +
  4073. + for (i = 0; i < sg_len; i++) {
  4074. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4075. + sg_ptr[i].length & CACHE_LINE_MASK)
  4076. + return 0;
  4077. + }
  4078. +
  4079. + return 1;
  4080. +}
  4081. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4082. +
  4083. +extern void
  4084. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4085. +{
  4086. + dsb(); /* ARM data synchronization (push) operation */
  4087. +
  4088. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4089. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4090. +}
  4091. +
  4092. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4093. +{
  4094. + dsb();
  4095. +
  4096. + /* ugly busy wait only option for now */
  4097. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4098. + cpu_relax();
  4099. +}
  4100. +
  4101. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4102. +
  4103. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4104. + Does nothing if there is no DMA in progress.
  4105. + This routine waits for the current AXI transfer to complete before
  4106. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4107. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4108. + case the routine times out and return a non-zero error code.
  4109. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4110. + does not produce an interrupt.
  4111. +*/
  4112. +extern int
  4113. +bcm_dma_abort(void __iomem *dma_chan_base)
  4114. +{
  4115. + unsigned long int cs;
  4116. + int rc = 0;
  4117. +
  4118. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4119. +
  4120. + if (BCM2708_DMA_ACTIVE & cs) {
  4121. + long int timeout = 10000;
  4122. +
  4123. + /* write 0 to the active bit - pause the DMA */
  4124. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4125. +
  4126. + /* wait for any current AXI transfer to complete */
  4127. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4128. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4129. +
  4130. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4131. + /* we'll un-pause when we set of our next DMA */
  4132. + rc = -ETIMEDOUT;
  4133. +
  4134. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4135. + /* terminate the control block chain */
  4136. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4137. +
  4138. + /* abort the whole DMA */
  4139. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4140. + dma_chan_base + BCM2708_DMA_CS);
  4141. + }
  4142. + }
  4143. +
  4144. + return rc;
  4145. +}
  4146. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4147. +
  4148. +
  4149. +/***************************************************************************** \
  4150. + * *
  4151. + * DMA Manager Device Methods *
  4152. + * *
  4153. +\*****************************************************************************/
  4154. +
  4155. +struct vc_dmaman {
  4156. + void __iomem *dma_base;
  4157. + u32 chan_available; /* bitmap of available channels */
  4158. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4159. +};
  4160. +
  4161. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4162. + u32 chans_available)
  4163. +{
  4164. + dmaman->dma_base = dma_base;
  4165. + dmaman->chan_available = chans_available;
  4166. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4167. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4168. +}
  4169. +
  4170. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4171. + unsigned preferred_feature_set)
  4172. +{
  4173. + u32 chans;
  4174. + int feature;
  4175. +
  4176. + chans = dmaman->chan_available;
  4177. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4178. + /* select the subset of available channels with the desired
  4179. + feature so long as some of the candidate channels have that
  4180. + feature */
  4181. + if ((preferred_feature_set & (1 << feature)) &&
  4182. + (chans & dmaman->has_feature[feature]))
  4183. + chans &= dmaman->has_feature[feature];
  4184. +
  4185. + if (chans) {
  4186. + int chan = 0;
  4187. + /* return the ordinal of the first channel in the bitmap */
  4188. + while (chans != 0 && (chans & 1) == 0) {
  4189. + chans >>= 1;
  4190. + chan++;
  4191. + }
  4192. + /* claim the channel */
  4193. + dmaman->chan_available &= ~(1 << chan);
  4194. + return chan;
  4195. + } else
  4196. + return -ENOMEM;
  4197. +}
  4198. +
  4199. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4200. +{
  4201. + if (chan < 0)
  4202. + return -EINVAL;
  4203. + else if ((1 << chan) & dmaman->chan_available)
  4204. + return -EIDRM;
  4205. + else {
  4206. + dmaman->chan_available |= (1 << chan);
  4207. + return 0;
  4208. + }
  4209. +}
  4210. +
  4211. +/*****************************************************************************\
  4212. + * *
  4213. + * DMA IRQs *
  4214. + * *
  4215. +\*****************************************************************************/
  4216. +
  4217. +static unsigned char bcm_dma_irqs[] = {
  4218. + IRQ_DMA0,
  4219. + IRQ_DMA1,
  4220. + IRQ_DMA2,
  4221. + IRQ_DMA3,
  4222. + IRQ_DMA4,
  4223. + IRQ_DMA5,
  4224. + IRQ_DMA6,
  4225. + IRQ_DMA7,
  4226. + IRQ_DMA8,
  4227. + IRQ_DMA9,
  4228. + IRQ_DMA10,
  4229. + IRQ_DMA11,
  4230. + IRQ_DMA12
  4231. +};
  4232. +
  4233. +
  4234. +/***************************************************************************** \
  4235. + * *
  4236. + * DMA Manager Monitor *
  4237. + * *
  4238. +\*****************************************************************************/
  4239. +
  4240. +static struct device *dmaman_dev; /* we assume there's only one! */
  4241. +
  4242. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4243. + void __iomem **out_dma_base, int *out_dma_irq)
  4244. +{
  4245. + if (!dmaman_dev)
  4246. + return -ENODEV;
  4247. + else {
  4248. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4249. + int rc;
  4250. +
  4251. + device_lock(dmaman_dev);
  4252. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4253. + if (rc >= 0) {
  4254. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4255. + rc);
  4256. + *out_dma_irq = bcm_dma_irqs[rc];
  4257. + }
  4258. + device_unlock(dmaman_dev);
  4259. +
  4260. + return rc;
  4261. + }
  4262. +}
  4263. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4264. +
  4265. +extern int bcm_dma_chan_free(int channel)
  4266. +{
  4267. + if (dmaman_dev) {
  4268. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4269. + int rc;
  4270. +
  4271. + device_lock(dmaman_dev);
  4272. + rc = vc_dmaman_chan_free(dmaman, channel);
  4273. + device_unlock(dmaman_dev);
  4274. +
  4275. + return rc;
  4276. + } else
  4277. + return -ENODEV;
  4278. +}
  4279. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4280. +
  4281. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4282. +{
  4283. + int rc = dmaman_dev ? -EINVAL : 0;
  4284. + dmaman_dev = dev;
  4285. + return rc;
  4286. +}
  4287. +
  4288. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4289. +{
  4290. + dmaman_dev = NULL;
  4291. +}
  4292. +
  4293. +/*****************************************************************************\
  4294. + * *
  4295. + * DMA Device *
  4296. + * *
  4297. +\*****************************************************************************/
  4298. +
  4299. +static int dmachans = -1; /* module parameter */
  4300. +
  4301. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4302. +{
  4303. + int ret = 0;
  4304. + struct vc_dmaman *dmaman;
  4305. + struct resource *dma_res = NULL;
  4306. + void __iomem *dma_base = NULL;
  4307. + int have_dma_region = 0;
  4308. +
  4309. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4310. + if (NULL == dmaman) {
  4311. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4312. + "DMA management memory\n");
  4313. + ret = -ENOMEM;
  4314. + } else {
  4315. +
  4316. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4317. + if (dma_res == NULL) {
  4318. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4319. + "resource\n");
  4320. + ret = -ENODEV;
  4321. + } else if (!request_mem_region(dma_res->start,
  4322. + resource_size(dma_res),
  4323. + DRIVER_NAME)) {
  4324. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4325. + ret = -EBUSY;
  4326. + } else {
  4327. + have_dma_region = 1;
  4328. + dma_base = ioremap(dma_res->start,
  4329. + resource_size(dma_res));
  4330. + if (!dma_base) {
  4331. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4332. + ret = -ENOMEM;
  4333. + } else {
  4334. + /* use module parameter if one was provided */
  4335. + if (dmachans > 0)
  4336. + vc_dmaman_init(dmaman, dma_base,
  4337. + dmachans);
  4338. + else
  4339. + vc_dmaman_init(dmaman, dma_base,
  4340. + DEFAULT_DMACHAN_BITMAP);
  4341. +
  4342. + platform_set_drvdata(pdev, dmaman);
  4343. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4344. +
  4345. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4346. + "at %p\n", dma_base);
  4347. + }
  4348. + }
  4349. + }
  4350. + if (ret != 0) {
  4351. + if (dma_base)
  4352. + iounmap(dma_base);
  4353. + if (dma_res && have_dma_region)
  4354. + release_mem_region(dma_res->start,
  4355. + resource_size(dma_res));
  4356. + if (dmaman)
  4357. + kfree(dmaman);
  4358. + }
  4359. + return ret;
  4360. +}
  4361. +
  4362. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4363. +{
  4364. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4365. +
  4366. + platform_set_drvdata(pdev, NULL);
  4367. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4368. + kfree(dmaman);
  4369. +
  4370. + return 0;
  4371. +}
  4372. +
  4373. +static struct platform_driver bcm_dmaman_driver = {
  4374. + .probe = bcm_dmaman_probe,
  4375. + .remove = bcm_dmaman_remove,
  4376. +
  4377. + .driver = {
  4378. + .name = DRIVER_NAME,
  4379. + .owner = THIS_MODULE,
  4380. + },
  4381. +};
  4382. +
  4383. +/*****************************************************************************\
  4384. + * *
  4385. + * Driver init/exit *
  4386. + * *
  4387. +\*****************************************************************************/
  4388. +
  4389. +static int __init bcm_dmaman_drv_init(void)
  4390. +{
  4391. + int ret;
  4392. +
  4393. + ret = platform_driver_register(&bcm_dmaman_driver);
  4394. + if (ret != 0) {
  4395. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4396. + "on platform\n");
  4397. + }
  4398. +
  4399. + return ret;
  4400. +}
  4401. +
  4402. +static void __exit bcm_dmaman_drv_exit(void)
  4403. +{
  4404. + platform_driver_unregister(&bcm_dmaman_driver);
  4405. +}
  4406. +
  4407. +module_init(bcm_dmaman_drv_init);
  4408. +module_exit(bcm_dmaman_drv_exit);
  4409. +
  4410. +module_param(dmachans, int, 0644);
  4411. +
  4412. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4413. +MODULE_DESCRIPTION("DMA channel manager driver");
  4414. +MODULE_LICENSE("GPL");
  4415. +
  4416. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4417. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/dmaer.c linux-3.11.10/arch/arm/mach-bcm2708/dmaer.c
  4418. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/dmaer.c 1970-01-01 01:00:00.000000000 +0100
  4419. +++ linux-3.11.10/arch/arm/mach-bcm2708/dmaer.c 2014-02-07 19:57:28.000000000 +0100
  4420. @@ -0,0 +1,886 @@
  4421. +#include <linux/init.h>
  4422. +#include <linux/sched.h>
  4423. +#include <linux/module.h>
  4424. +#include <linux/types.h>
  4425. +#include <linux/kdev_t.h>
  4426. +#include <linux/fs.h>
  4427. +#include <linux/cdev.h>
  4428. +#include <linux/mm.h>
  4429. +#include <linux/slab.h>
  4430. +#include <linux/pagemap.h>
  4431. +#include <linux/device.h>
  4432. +#include <linux/jiffies.h>
  4433. +#include <linux/timex.h>
  4434. +#include <linux/dma-mapping.h>
  4435. +
  4436. +#include <asm/uaccess.h>
  4437. +#include <asm/atomic.h>
  4438. +#include <asm/cacheflush.h>
  4439. +#include <asm/io.h>
  4440. +
  4441. +#include <mach/dma.h>
  4442. +#include <mach/vc_support.h>
  4443. +
  4444. +#ifdef ECLIPSE_IGNORE
  4445. +
  4446. +#define __user
  4447. +#define __init
  4448. +#define __exit
  4449. +#define __iomem
  4450. +#define KERN_DEBUG
  4451. +#define KERN_ERR
  4452. +#define KERN_WARNING
  4453. +#define KERN_INFO
  4454. +#define _IOWR(a, b, c) b
  4455. +#define _IOW(a, b, c) b
  4456. +#define _IO(a, b) b
  4457. +
  4458. +#endif
  4459. +
  4460. +//#define inline
  4461. +
  4462. +#define PRINTK(args...) printk(args)
  4463. +//#define PRINTK_VERBOSE(args...) printk(args)
  4464. +//#define PRINTK(args...)
  4465. +#define PRINTK_VERBOSE(args...)
  4466. +
  4467. +/***** TYPES ****/
  4468. +#define PAGES_PER_LIST 500
  4469. +struct PageList
  4470. +{
  4471. + struct page *m_pPages[PAGES_PER_LIST];
  4472. + unsigned int m_used;
  4473. + struct PageList *m_pNext;
  4474. +};
  4475. +
  4476. +struct VmaPageList
  4477. +{
  4478. + //each vma has a linked list of pages associated with it
  4479. + struct PageList *m_pPageHead;
  4480. + struct PageList *m_pPageTail;
  4481. + unsigned int m_refCount;
  4482. +};
  4483. +
  4484. +struct DmaControlBlock
  4485. +{
  4486. + unsigned int m_transferInfo;
  4487. + void __user *m_pSourceAddr;
  4488. + void __user *m_pDestAddr;
  4489. + unsigned int m_xferLen;
  4490. + unsigned int m_tdStride;
  4491. + struct DmaControlBlock *m_pNext;
  4492. + unsigned int m_blank1, m_blank2;
  4493. +};
  4494. +
  4495. +/***** DEFINES ******/
  4496. +//magic number defining the module
  4497. +#define DMA_MAGIC 0xdd
  4498. +
  4499. +//do user virtual to physical translation of the CB chain
  4500. +#define DMA_PREPARE _IOWR(DMA_MAGIC, 0, struct DmaControlBlock *)
  4501. +
  4502. +//kick the pre-prepared CB chain
  4503. +#define DMA_KICK _IOW(DMA_MAGIC, 1, struct DmaControlBlock *)
  4504. +
  4505. +//prepare it, kick it, wait for it
  4506. +#define DMA_PREPARE_KICK_WAIT _IOWR(DMA_MAGIC, 2, struct DmaControlBlock *)
  4507. +
  4508. +//prepare it, kick it, don't wait for it
  4509. +#define DMA_PREPARE_KICK _IOWR(DMA_MAGIC, 3, struct DmaControlBlock *)
  4510. +
  4511. +//not currently implemented
  4512. +#define DMA_WAIT_ONE _IO(DMA_MAGIC, 4, struct DmaControlBlock *)
  4513. +
  4514. +//wait on all kicked CB chains
  4515. +#define DMA_WAIT_ALL _IO(DMA_MAGIC, 5)
  4516. +
  4517. +//in order to discover the largest AXI burst that should be programmed into the transfer params
  4518. +#define DMA_MAX_BURST _IO(DMA_MAGIC, 6)
  4519. +
  4520. +//set the address range through which the user address is assumed to already by a physical address
  4521. +#define DMA_SET_MIN_PHYS _IOW(DMA_MAGIC, 7, unsigned long)
  4522. +#define DMA_SET_MAX_PHYS _IOW(DMA_MAGIC, 8, unsigned long)
  4523. +#define DMA_SET_PHYS_OFFSET _IOW(DMA_MAGIC, 9, unsigned long)
  4524. +
  4525. +//used to define the size for the CMA-based allocation *in pages*, can only be done once once the file is opened
  4526. +#define DMA_CMA_SET_SIZE _IOW(DMA_MAGIC, 10, unsigned long)
  4527. +
  4528. +//used to get the version of the module, to test for a capability
  4529. +#define DMA_GET_VERSION _IO(DMA_MAGIC, 99)
  4530. +
  4531. +#define VERSION_NUMBER 1
  4532. +
  4533. +#define VIRT_TO_BUS_CACHE_SIZE 8
  4534. +
  4535. +/***** FILE OPS *****/
  4536. +static int Open(struct inode *pInode, struct file *pFile);
  4537. +static int Release(struct inode *pInode, struct file *pFile);
  4538. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg);
  4539. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp);
  4540. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma);
  4541. +
  4542. +/***** VMA OPS ****/
  4543. +static void VmaOpen4k(struct vm_area_struct *pVma);
  4544. +static void VmaClose4k(struct vm_area_struct *pVma);
  4545. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf);
  4546. +
  4547. +/**** DMA PROTOTYPES */
  4548. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError);
  4549. +static int DmaKick(struct DmaControlBlock __user *pUserCB);
  4550. +static void DmaWaitAll(void);
  4551. +
  4552. +/**** GENERIC ****/
  4553. +static int __init dmaer_init(void);
  4554. +static void __exit dmaer_exit(void);
  4555. +
  4556. +/*** OPS ***/
  4557. +static struct vm_operations_struct g_vmOps4k = {
  4558. + .open = VmaOpen4k,
  4559. + .close = VmaClose4k,
  4560. + .fault = VmaFault4k,
  4561. +};
  4562. +
  4563. +static struct file_operations g_fOps = {
  4564. + .owner = THIS_MODULE,
  4565. + .llseek = 0,
  4566. + .read = Read,
  4567. + .write = 0,
  4568. + .unlocked_ioctl = Ioctl,
  4569. + .open = Open,
  4570. + .release = Release,
  4571. + .mmap = Mmap,
  4572. +};
  4573. +
  4574. +/***** GLOBALS ******/
  4575. +static dev_t g_majorMinor;
  4576. +
  4577. +//tracking usage of the two files
  4578. +static atomic_t g_oneLock4k = ATOMIC_INIT(1);
  4579. +
  4580. +//device operations
  4581. +static struct cdev g_cDev;
  4582. +static int g_trackedPages = 0;
  4583. +
  4584. +//dma control
  4585. +static unsigned int *g_pDmaChanBase;
  4586. +static int g_dmaIrq;
  4587. +static int g_dmaChan;
  4588. +
  4589. +//cma allocation
  4590. +static int g_cmaHandle;
  4591. +
  4592. +//user virtual to bus address translation acceleration
  4593. +static unsigned long g_virtAddr[VIRT_TO_BUS_CACHE_SIZE];
  4594. +static unsigned long g_busAddr[VIRT_TO_BUS_CACHE_SIZE];
  4595. +static unsigned long g_cbVirtAddr;
  4596. +static unsigned long g_cbBusAddr;
  4597. +static int g_cacheInsertAt;
  4598. +static int g_cacheHit, g_cacheMiss;
  4599. +
  4600. +//off by default
  4601. +static void __user *g_pMinPhys;
  4602. +static void __user *g_pMaxPhys;
  4603. +static unsigned long g_physOffset;
  4604. +
  4605. +/****** CACHE OPERATIONS ********/
  4606. +static inline void FlushAddrCache(void)
  4607. +{
  4608. + int count = 0;
  4609. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4610. + g_virtAddr[count] = 0xffffffff; //never going to match as we always chop the bottom bits anyway
  4611. +
  4612. + g_cbVirtAddr = 0xffffffff;
  4613. +
  4614. + g_cacheInsertAt = 0;
  4615. +}
  4616. +
  4617. +//translate from a user virtual address to a bus address by mapping the page
  4618. +//NB this won't lock a page in memory, so to avoid potential paging issues using kernel logical addresses
  4619. +static inline void __iomem *UserVirtualToBus(void __user *pUser)
  4620. +{
  4621. + int mapped;
  4622. + struct page *pPage;
  4623. + void *phys;
  4624. +
  4625. + //map it (requiring that the pointer points to something that does not hang off the page boundary)
  4626. + mapped = get_user_pages(current, current->mm,
  4627. + (unsigned long)pUser, 1,
  4628. + 1, 0,
  4629. + &pPage,
  4630. + 0);
  4631. +
  4632. + if (mapped <= 0) //error
  4633. + return 0;
  4634. +
  4635. + PRINTK_VERBOSE(KERN_DEBUG "user virtual %p arm phys %p bus %p\n",
  4636. + pUser, page_address(pPage), (void __iomem *)__virt_to_bus(page_address(pPage)));
  4637. +
  4638. + //get the arm physical address
  4639. + phys = page_address(pPage) + offset_in_page(pUser);
  4640. + page_cache_release(pPage);
  4641. +
  4642. + //and now the bus address
  4643. + return (void __iomem *)__virt_to_bus(phys);
  4644. +}
  4645. +
  4646. +static inline void __iomem *UserVirtualToBusViaCbCache(void __user *pUser)
  4647. +{
  4648. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4649. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4650. + unsigned long bus_addr;
  4651. +
  4652. + if (g_cbVirtAddr == virtual_page)
  4653. + {
  4654. + bus_addr = g_cbBusAddr + page_offset;
  4655. + g_cacheHit++;
  4656. + return (void __iomem *)bus_addr;
  4657. + }
  4658. + else
  4659. + {
  4660. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4661. +
  4662. + if (!bus_addr)
  4663. + return 0;
  4664. +
  4665. + g_cbVirtAddr = virtual_page;
  4666. + g_cbBusAddr = bus_addr & ~4095;
  4667. + g_cacheMiss++;
  4668. +
  4669. + return (void __iomem *)bus_addr;
  4670. + }
  4671. +}
  4672. +
  4673. +//do the same as above, by query our virt->bus cache
  4674. +static inline void __iomem *UserVirtualToBusViaCache(void __user *pUser)
  4675. +{
  4676. + int count;
  4677. + //get the page and its offset
  4678. + unsigned long virtual_page = (unsigned long)pUser & ~4095;
  4679. + unsigned long page_offset = (unsigned long)pUser & 4095;
  4680. + unsigned long bus_addr;
  4681. +
  4682. + if (pUser >= g_pMinPhys && pUser < g_pMaxPhys)
  4683. + {
  4684. + PRINTK_VERBOSE(KERN_DEBUG "user->phys passthrough on %p\n", pUser);
  4685. + return (void __iomem *)((unsigned long)pUser + g_physOffset);
  4686. + }
  4687. +
  4688. + //check the cache for our entry
  4689. + for (count = 0; count < VIRT_TO_BUS_CACHE_SIZE; count++)
  4690. + if (g_virtAddr[count] == virtual_page)
  4691. + {
  4692. + bus_addr = g_busAddr[count] + page_offset;
  4693. + g_cacheHit++;
  4694. + return (void __iomem *)bus_addr;
  4695. + }
  4696. +
  4697. + //not found, look up manually and then insert its page address
  4698. + bus_addr = (unsigned long)UserVirtualToBus(pUser);
  4699. +
  4700. + if (!bus_addr)
  4701. + return 0;
  4702. +
  4703. + g_virtAddr[g_cacheInsertAt] = virtual_page;
  4704. + g_busAddr[g_cacheInsertAt] = bus_addr & ~4095;
  4705. +
  4706. + //round robin
  4707. + g_cacheInsertAt++;
  4708. + if (g_cacheInsertAt == VIRT_TO_BUS_CACHE_SIZE)
  4709. + g_cacheInsertAt = 0;
  4710. +
  4711. + g_cacheMiss++;
  4712. +
  4713. + return (void __iomem *)bus_addr;
  4714. +}
  4715. +
  4716. +/***** FILE OPERATIONS ****/
  4717. +static int Open(struct inode *pInode, struct file *pFile)
  4718. +{
  4719. + PRINTK(KERN_DEBUG "file opening: %d/%d\n", imajor(pInode), iminor(pInode));
  4720. +
  4721. + //check which device we are
  4722. + if (iminor(pInode) == 0) //4k
  4723. + {
  4724. + //only one at a time
  4725. + if (!atomic_dec_and_test(&g_oneLock4k))
  4726. + {
  4727. + atomic_inc(&g_oneLock4k);
  4728. + return -EBUSY;
  4729. + }
  4730. + }
  4731. + else
  4732. + return -EINVAL;
  4733. +
  4734. + //todo there will be trouble if two different processes open the files
  4735. +
  4736. + //reset after any file is opened
  4737. + g_pMinPhys = (void __user *)-1;
  4738. + g_pMaxPhys = (void __user *)0;
  4739. + g_physOffset = 0;
  4740. + g_cmaHandle = 0;
  4741. +
  4742. + return 0;
  4743. +}
  4744. +
  4745. +static int Release(struct inode *pInode, struct file *pFile)
  4746. +{
  4747. + PRINTK(KERN_DEBUG "file closing, %d pages tracked\n", g_trackedPages);
  4748. + if (g_trackedPages)
  4749. + PRINTK(KERN_ERR "we\'re leaking memory!\n");
  4750. +
  4751. + //wait for any dmas to finish
  4752. + DmaWaitAll();
  4753. +
  4754. + //free this memory on the application closing the file or it crashing (implicitly closing the file)
  4755. + if (g_cmaHandle)
  4756. + {
  4757. + PRINTK(KERN_DEBUG "unlocking vc memory\n");
  4758. + if (UnlockVcMemory(g_cmaHandle))
  4759. + PRINTK(KERN_ERR "uh-oh, unable to unlock vc memory!\n");
  4760. + PRINTK(KERN_DEBUG "releasing vc memory\n");
  4761. + if (ReleaseVcMemory(g_cmaHandle))
  4762. + PRINTK(KERN_ERR "uh-oh, unable to release vc memory!\n");
  4763. + }
  4764. +
  4765. + if (iminor(pInode) == 0)
  4766. + atomic_inc(&g_oneLock4k);
  4767. + else
  4768. + return -EINVAL;
  4769. +
  4770. + return 0;
  4771. +}
  4772. +
  4773. +static struct DmaControlBlock __user *DmaPrepare(struct DmaControlBlock __user *pUserCB, int *pError)
  4774. +{
  4775. + struct DmaControlBlock kernCB;
  4776. + struct DmaControlBlock __user *pUNext;
  4777. + void __iomem *pSourceBus, __iomem *pDestBus;
  4778. +
  4779. + //get the control block into kernel memory so we can work on it
  4780. + if (copy_from_user(&kernCB, pUserCB, sizeof(struct DmaControlBlock)) != 0)
  4781. + {
  4782. + PRINTK(KERN_ERR "copy_from_user failed for user cb %p\n", pUserCB);
  4783. + *pError = 1;
  4784. + return 0;
  4785. + }
  4786. +
  4787. + if (kernCB.m_pSourceAddr == 0 || kernCB.m_pDestAddr == 0)
  4788. + {
  4789. + PRINTK(KERN_ERR "faulty source (%p) dest (%p) addresses for user cb %p\n",
  4790. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr, pUserCB);
  4791. + *pError = 1;
  4792. + return 0;
  4793. + }
  4794. +
  4795. + pSourceBus = UserVirtualToBusViaCache(kernCB.m_pSourceAddr);
  4796. + pDestBus = UserVirtualToBusViaCache(kernCB.m_pDestAddr);
  4797. +
  4798. + if (!pSourceBus || !pDestBus)
  4799. + {
  4800. + PRINTK(KERN_ERR "virtual to bus translation failure for source/dest %p/%p->%p/%p\n",
  4801. + kernCB.m_pSourceAddr, kernCB.m_pDestAddr,
  4802. + pSourceBus, pDestBus);
  4803. + *pError = 1;
  4804. + return 0;
  4805. + }
  4806. +
  4807. + //update the user structure with the new bus addresses
  4808. + kernCB.m_pSourceAddr = pSourceBus;
  4809. + kernCB.m_pDestAddr = pDestBus;
  4810. +
  4811. + PRINTK_VERBOSE(KERN_DEBUG "final source %p dest %p\n", kernCB.m_pSourceAddr, kernCB.m_pDestAddr);
  4812. +
  4813. + //sort out the bus address for the next block
  4814. + pUNext = kernCB.m_pNext;
  4815. +
  4816. + if (kernCB.m_pNext)
  4817. + {
  4818. + void __iomem *pNextBus;
  4819. + pNextBus = UserVirtualToBusViaCbCache(kernCB.m_pNext);
  4820. +
  4821. + if (!pNextBus)
  4822. + {
  4823. + PRINTK(KERN_ERR "virtual to bus translation failure for m_pNext\n");
  4824. + *pError = 1;
  4825. + return 0;
  4826. + }
  4827. +
  4828. + //update the pointer with the bus address
  4829. + kernCB.m_pNext = pNextBus;
  4830. + }
  4831. +
  4832. + //write it back to user space
  4833. + if (copy_to_user(pUserCB, &kernCB, sizeof(struct DmaControlBlock)) != 0)
  4834. + {
  4835. + PRINTK(KERN_ERR "copy_to_user failed for cb %p\n", pUserCB);
  4836. + *pError = 1;
  4837. + return 0;
  4838. + }
  4839. +
  4840. + __cpuc_flush_dcache_area(pUserCB, 32);
  4841. +
  4842. + *pError = 0;
  4843. + return pUNext;
  4844. +}
  4845. +
  4846. +static int DmaKick(struct DmaControlBlock __user *pUserCB)
  4847. +{
  4848. + void __iomem *pBusCB;
  4849. +
  4850. + pBusCB = UserVirtualToBusViaCbCache(pUserCB);
  4851. + if (!pBusCB)
  4852. + {
  4853. + PRINTK(KERN_ERR "virtual to bus translation failure for cb\n");
  4854. + return 1;
  4855. + }
  4856. +
  4857. + //flush_cache_all();
  4858. +
  4859. + bcm_dma_start(g_pDmaChanBase, (dma_addr_t)pBusCB);
  4860. +
  4861. + return 0;
  4862. +}
  4863. +
  4864. +static void DmaWaitAll(void)
  4865. +{
  4866. + int counter = 0;
  4867. + volatile int inner_count;
  4868. + volatile unsigned int cs;
  4869. + unsigned long time_before, time_after;
  4870. +
  4871. + time_before = jiffies;
  4872. + //bcm_dma_wait_idle(g_pDmaChanBase);
  4873. + dsb();
  4874. +
  4875. + cs = readl(g_pDmaChanBase);
  4876. +
  4877. + while ((cs & 1) == 1)
  4878. + {
  4879. + cs = readl(g_pDmaChanBase);
  4880. + counter++;
  4881. +
  4882. + for (inner_count = 0; inner_count < 32; inner_count++);
  4883. +
  4884. + asm volatile ("MCR p15,0,r0,c7,c0,4 \n");
  4885. + //cpu_do_idle();
  4886. + if (counter >= 1000000)
  4887. + {
  4888. + PRINTK(KERN_WARNING "DMA failed to finish in a timely fashion\n");
  4889. + break;
  4890. + }
  4891. + }
  4892. + time_after = jiffies;
  4893. + PRINTK_VERBOSE(KERN_DEBUG "done, counter %d, cs %08x", counter, cs);
  4894. + PRINTK_VERBOSE(KERN_DEBUG "took %ld jiffies, %d HZ\n", time_after - time_before, HZ);
  4895. +}
  4896. +
  4897. +static long Ioctl(struct file *pFile, unsigned int cmd, unsigned long arg)
  4898. +{
  4899. + int error = 0;
  4900. + PRINTK_VERBOSE(KERN_DEBUG "ioctl cmd %x arg %lx\n", cmd, arg);
  4901. +
  4902. + switch (cmd)
  4903. + {
  4904. + case DMA_PREPARE:
  4905. + case DMA_PREPARE_KICK:
  4906. + case DMA_PREPARE_KICK_WAIT:
  4907. + {
  4908. + struct DmaControlBlock __user *pUCB = (struct DmaControlBlock *)arg;
  4909. + int steps = 0;
  4910. + unsigned long start_time = jiffies;
  4911. + (void)start_time;
  4912. +
  4913. + //flush our address cache
  4914. + FlushAddrCache();
  4915. +
  4916. + PRINTK_VERBOSE(KERN_DEBUG "dma prepare\n");
  4917. +
  4918. + //do virtual to bus translation for each entry
  4919. + do
  4920. + {
  4921. + pUCB = DmaPrepare(pUCB, &error);
  4922. + } while (error == 0 && ++steps && pUCB);
  4923. + PRINTK_VERBOSE(KERN_DEBUG "prepare done in %d steps, %ld\n", steps, jiffies - start_time);
  4924. +
  4925. + //carry straight on if we want to kick too
  4926. + if (cmd == DMA_PREPARE || error)
  4927. + {
  4928. + PRINTK_VERBOSE(KERN_DEBUG "falling out\n");
  4929. + return error ? -EINVAL : 0;
  4930. + }
  4931. + }
  4932. + case DMA_KICK:
  4933. + PRINTK_VERBOSE(KERN_DEBUG "dma begin\n");
  4934. +
  4935. + if (cmd == DMA_KICK)
  4936. + FlushAddrCache();
  4937. +
  4938. + DmaKick((struct DmaControlBlock __user *)arg);
  4939. +
  4940. + if (cmd != DMA_PREPARE_KICK_WAIT)
  4941. + break;
  4942. +/* case DMA_WAIT_ONE:
  4943. + //PRINTK(KERN_DEBUG "dma wait one\n");
  4944. + break;*/
  4945. + case DMA_WAIT_ALL:
  4946. + //PRINTK(KERN_DEBUG "dma wait all\n");
  4947. + DmaWaitAll();
  4948. + break;
  4949. + case DMA_MAX_BURST:
  4950. + if (g_dmaChan == 0)
  4951. + return 10;
  4952. + else
  4953. + return 5;
  4954. + case DMA_SET_MIN_PHYS:
  4955. + g_pMinPhys = (void __user *)arg;
  4956. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  4957. + break;
  4958. + case DMA_SET_MAX_PHYS:
  4959. + g_pMaxPhys = (void __user *)arg;
  4960. + PRINTK(KERN_DEBUG "min/max user/phys bypass set to %p %p\n", g_pMinPhys, g_pMaxPhys);
  4961. + break;
  4962. + case DMA_SET_PHYS_OFFSET:
  4963. + g_physOffset = arg;
  4964. + PRINTK(KERN_DEBUG "user/phys bypass offset set to %ld\n", g_physOffset);
  4965. + break;
  4966. + case DMA_CMA_SET_SIZE:
  4967. + {
  4968. + unsigned int pBusAddr;
  4969. +
  4970. + if (g_cmaHandle)
  4971. + {
  4972. + PRINTK(KERN_ERR "memory has already been allocated (handle %d)\n", g_cmaHandle);
  4973. + return -EINVAL;
  4974. + }
  4975. +
  4976. + PRINTK(KERN_INFO "allocating %ld bytes of VC memory\n", arg * 4096);
  4977. +
  4978. + //get the memory
  4979. + if (AllocateVcMemory(&g_cmaHandle, arg * 4096, 4096, MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_NO_INIT | MEM_FLAG_HINT_PERMALOCK))
  4980. + {
  4981. + PRINTK(KERN_ERR "failed to allocate %ld bytes of VC memory\n", arg * 4096);
  4982. + g_cmaHandle = 0;
  4983. + return -EINVAL;
  4984. + }
  4985. +
  4986. + //get an address for it
  4987. + PRINTK(KERN_INFO "trying to map VC memory\n");
  4988. +
  4989. + if (LockVcMemory(&pBusAddr, g_cmaHandle))
  4990. + {
  4991. + PRINTK(KERN_ERR "failed to map CMA handle %d, releasing memory\n", g_cmaHandle);
  4992. + ReleaseVcMemory(g_cmaHandle);
  4993. + g_cmaHandle = 0;
  4994. + }
  4995. +
  4996. + PRINTK(KERN_INFO "bus address for CMA memory is %x\n", pBusAddr);
  4997. + return pBusAddr;
  4998. + }
  4999. + case DMA_GET_VERSION:
  5000. + PRINTK(KERN_DEBUG "returning version number, %d\n", VERSION_NUMBER);
  5001. + return VERSION_NUMBER;
  5002. + default:
  5003. + PRINTK(KERN_DEBUG "unknown ioctl: %d\n", cmd);
  5004. + return -EINVAL;
  5005. + }
  5006. +
  5007. + return 0;
  5008. +}
  5009. +
  5010. +static ssize_t Read(struct file *pFile, char __user *pUser, size_t count, loff_t *offp)
  5011. +{
  5012. + return -EIO;
  5013. +}
  5014. +
  5015. +static int Mmap(struct file *pFile, struct vm_area_struct *pVma)
  5016. +{
  5017. + struct PageList *pPages;
  5018. + struct VmaPageList *pVmaList;
  5019. +
  5020. + PRINTK_VERBOSE(KERN_DEBUG "MMAP vma %p, length %ld (%s %d)\n",
  5021. + pVma, pVma->vm_end - pVma->vm_start,
  5022. + current->comm, current->pid);
  5023. + PRINTK_VERBOSE(KERN_DEBUG "MMAP %p %d (tracked %d)\n", pVma, current->pid, g_trackedPages);
  5024. +
  5025. + //make a new page list
  5026. + pPages = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5027. + if (!pPages)
  5028. + {
  5029. + PRINTK(KERN_ERR "couldn\'t allocate a new page list (%s %d)\n",
  5030. + current->comm, current->pid);
  5031. + return -ENOMEM;
  5032. + }
  5033. +
  5034. + //clear the page list
  5035. + pPages->m_used = 0;
  5036. + pPages->m_pNext = 0;
  5037. +
  5038. + //insert our vma and new page list somewhere
  5039. + if (!pVma->vm_private_data)
  5040. + {
  5041. + struct VmaPageList *pList;
  5042. +
  5043. + PRINTK_VERBOSE(KERN_DEBUG "new vma list, making new one (%s %d)\n",
  5044. + current->comm, current->pid);
  5045. +
  5046. + //make a new vma list
  5047. + pList = (struct VmaPageList *)kmalloc(sizeof(struct VmaPageList), GFP_KERNEL);
  5048. + if (!pList)
  5049. + {
  5050. + PRINTK(KERN_ERR "couldn\'t allocate vma page list (%s %d)\n",
  5051. + current->comm, current->pid);
  5052. + kfree(pPages);
  5053. + return -ENOMEM;
  5054. + }
  5055. +
  5056. + //clear this list
  5057. + pVma->vm_private_data = (void *)pList;
  5058. + pList->m_refCount = 0;
  5059. + }
  5060. +
  5061. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5062. +
  5063. + //add it to the vma list
  5064. + pVmaList->m_pPageHead = pPages;
  5065. + pVmaList->m_pPageTail = pPages;
  5066. +
  5067. + pVma->vm_ops = &g_vmOps4k;
  5068. + pVma->vm_flags |= VM_IO;
  5069. +
  5070. + VmaOpen4k(pVma);
  5071. +
  5072. + return 0;
  5073. +}
  5074. +
  5075. +/****** VMA OPERATIONS ******/
  5076. +
  5077. +static void VmaOpen4k(struct vm_area_struct *pVma)
  5078. +{
  5079. + struct VmaPageList *pVmaList;
  5080. +
  5081. + PRINTK_VERBOSE(KERN_DEBUG "vma open %p private %p (%s %d), %d live pages\n", pVma, pVma->vm_private_data, current->comm, current->pid, g_trackedPages);
  5082. + PRINTK_VERBOSE(KERN_DEBUG "OPEN %p %d %ld pages (tracked pages %d)\n",
  5083. + pVma, current->pid, (pVma->vm_end - pVma->vm_start) >> 12,
  5084. + g_trackedPages);
  5085. +
  5086. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5087. +
  5088. + if (pVmaList)
  5089. + {
  5090. + pVmaList->m_refCount++;
  5091. + PRINTK_VERBOSE(KERN_DEBUG "ref count is now %d\n", pVmaList->m_refCount);
  5092. + }
  5093. + else
  5094. + {
  5095. + PRINTK_VERBOSE(KERN_DEBUG "err, open but no vma page list\n");
  5096. + }
  5097. +}
  5098. +
  5099. +static void VmaClose4k(struct vm_area_struct *pVma)
  5100. +{
  5101. + struct VmaPageList *pVmaList;
  5102. + int freed = 0;
  5103. +
  5104. + PRINTK_VERBOSE(KERN_DEBUG "vma close %p private %p (%s %d)\n", pVma, pVma->vm_private_data, current->comm, current->pid);
  5105. +
  5106. + //wait for any dmas to finish
  5107. + DmaWaitAll();
  5108. +
  5109. + //find our vma in the list
  5110. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5111. +
  5112. + //may be a fork
  5113. + if (pVmaList)
  5114. + {
  5115. + struct PageList *pPages;
  5116. +
  5117. + pVmaList->m_refCount--;
  5118. +
  5119. + if (pVmaList->m_refCount == 0)
  5120. + {
  5121. + PRINTK_VERBOSE(KERN_DEBUG "found vma, freeing pages (%s %d)\n",
  5122. + current->comm, current->pid);
  5123. +
  5124. + pPages = pVmaList->m_pPageHead;
  5125. +
  5126. + if (!pPages)
  5127. + {
  5128. + PRINTK(KERN_ERR "no page list (%s %d)!\n",
  5129. + current->comm, current->pid);
  5130. + return;
  5131. + }
  5132. +
  5133. + while (pPages)
  5134. + {
  5135. + struct PageList *next;
  5136. + int count;
  5137. +
  5138. + PRINTK_VERBOSE(KERN_DEBUG "page list (%s %d)\n",
  5139. + current->comm, current->pid);
  5140. +
  5141. + next = pPages->m_pNext;
  5142. + for (count = 0; count < pPages->m_used; count++)
  5143. + {
  5144. + PRINTK_VERBOSE(KERN_DEBUG "freeing page %p (%s %d)\n",
  5145. + pPages->m_pPages[count],
  5146. + current->comm, current->pid);
  5147. + __free_pages(pPages->m_pPages[count], 0);
  5148. + g_trackedPages--;
  5149. + freed++;
  5150. + }
  5151. +
  5152. + PRINTK_VERBOSE(KERN_DEBUG "freeing page list (%s %d)\n",
  5153. + current->comm, current->pid);
  5154. + kfree(pPages);
  5155. + pPages = next;
  5156. + }
  5157. +
  5158. + //remove our vma from the list
  5159. + kfree(pVmaList);
  5160. + pVma->vm_private_data = 0;
  5161. + }
  5162. + else
  5163. + {
  5164. + PRINTK_VERBOSE(KERN_DEBUG "ref count is %d, not closing\n", pVmaList->m_refCount);
  5165. + }
  5166. + }
  5167. + else
  5168. + {
  5169. + PRINTK_VERBOSE(KERN_ERR "uh-oh, vma %p not found (%s %d)!\n", pVma, current->comm, current->pid);
  5170. + PRINTK_VERBOSE(KERN_ERR "CLOSE ERR\n");
  5171. + }
  5172. +
  5173. + PRINTK_VERBOSE(KERN_DEBUG "CLOSE %p %d %d pages (tracked pages %d)",
  5174. + pVma, current->pid, freed, g_trackedPages);
  5175. +
  5176. + PRINTK_VERBOSE(KERN_DEBUG "%d pages open\n", g_trackedPages);
  5177. +}
  5178. +
  5179. +static int VmaFault4k(struct vm_area_struct *pVma, struct vm_fault *pVmf)
  5180. +{
  5181. + PRINTK_VERBOSE(KERN_DEBUG "vma fault for vma %p private %p at offset %ld (%s %d)\n", pVma, pVma->vm_private_data, pVmf->pgoff,
  5182. + current->comm, current->pid);
  5183. + PRINTK_VERBOSE(KERN_DEBUG "FAULT\n");
  5184. + pVmf->page = alloc_page(GFP_KERNEL);
  5185. +
  5186. + if (pVmf->page)
  5187. + {
  5188. + PRINTK_VERBOSE(KERN_DEBUG "alloc page virtual %p\n", page_address(pVmf->page));
  5189. + }
  5190. +
  5191. + if (!pVmf->page)
  5192. + {
  5193. + PRINTK(KERN_ERR "vma fault oom (%s %d)\n", current->comm, current->pid);
  5194. + return VM_FAULT_OOM;
  5195. + }
  5196. + else
  5197. + {
  5198. + struct VmaPageList *pVmaList;
  5199. +
  5200. + get_page(pVmf->page);
  5201. + g_trackedPages++;
  5202. +
  5203. + //find our vma in the list
  5204. + pVmaList = (struct VmaPageList *)pVma->vm_private_data;
  5205. +
  5206. + if (pVmaList)
  5207. + {
  5208. + PRINTK_VERBOSE(KERN_DEBUG "vma found (%s %d)\n", current->comm, current->pid);
  5209. +
  5210. + if (pVmaList->m_pPageTail->m_used == PAGES_PER_LIST)
  5211. + {
  5212. + PRINTK_VERBOSE(KERN_DEBUG "making new page list (%s %d)\n", current->comm, current->pid);
  5213. + //making a new page list
  5214. + pVmaList->m_pPageTail->m_pNext = (struct PageList *)kmalloc(sizeof(struct PageList), GFP_KERNEL);
  5215. + if (!pVmaList->m_pPageTail->m_pNext)
  5216. + return -ENOMEM;
  5217. +
  5218. + //update the tail pointer
  5219. + pVmaList->m_pPageTail = pVmaList->m_pPageTail->m_pNext;
  5220. + pVmaList->m_pPageTail->m_used = 0;
  5221. + pVmaList->m_pPageTail->m_pNext = 0;
  5222. + }
  5223. +
  5224. + PRINTK_VERBOSE(KERN_DEBUG "adding page to list (%s %d)\n", current->comm, current->pid);
  5225. +
  5226. + pVmaList->m_pPageTail->m_pPages[pVmaList->m_pPageTail->m_used] = pVmf->page;
  5227. + pVmaList->m_pPageTail->m_used++;
  5228. + }
  5229. + else
  5230. + PRINTK(KERN_ERR "returned page for vma we don\'t know %p (%s %d)\n", pVma, current->comm, current->pid);
  5231. +
  5232. + return 0;
  5233. + }
  5234. +}
  5235. +
  5236. +/****** GENERIC FUNCTIONS ******/
  5237. +static int __init dmaer_init(void)
  5238. +{
  5239. + int result = alloc_chrdev_region(&g_majorMinor, 0, 1, "dmaer");
  5240. + if (result < 0)
  5241. + {
  5242. + PRINTK(KERN_ERR "unable to get major device number\n");
  5243. + return result;
  5244. + }
  5245. + else
  5246. + PRINTK(KERN_DEBUG "major device number %d\n", MAJOR(g_majorMinor));
  5247. +
  5248. + PRINTK(KERN_DEBUG "vma list size %d, page list size %d, page size %ld\n",
  5249. + sizeof(struct VmaPageList), sizeof(struct PageList), PAGE_SIZE);
  5250. +
  5251. + //get a dma channel to work with
  5252. + result = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST, (void **)&g_pDmaChanBase, &g_dmaIrq);
  5253. +
  5254. + //uncomment to force to channel 0
  5255. + //result = 0;
  5256. + //g_pDmaChanBase = 0xce808000;
  5257. +
  5258. + if (result < 0)
  5259. + {
  5260. + PRINTK(KERN_ERR "failed to allocate dma channel\n");
  5261. + cdev_del(&g_cDev);
  5262. + unregister_chrdev_region(g_majorMinor, 1);
  5263. + }
  5264. +
  5265. + //reset the channel
  5266. + PRINTK(KERN_DEBUG "allocated dma channel %d (%p), initial state %08x\n", result, g_pDmaChanBase, *g_pDmaChanBase);
  5267. + *g_pDmaChanBase = 1 << 31;
  5268. + PRINTK(KERN_DEBUG "post-reset %08x\n", *g_pDmaChanBase);
  5269. +
  5270. + g_dmaChan = result;
  5271. +
  5272. + //clear the cache stats
  5273. + g_cacheHit = 0;
  5274. + g_cacheMiss = 0;
  5275. +
  5276. + //register our device - after this we are go go go
  5277. + cdev_init(&g_cDev, &g_fOps);
  5278. + g_cDev.owner = THIS_MODULE;
  5279. + g_cDev.ops = &g_fOps;
  5280. +
  5281. + result = cdev_add(&g_cDev, g_majorMinor, 1);
  5282. + if (result < 0)
  5283. + {
  5284. + PRINTK(KERN_ERR "failed to add character device\n");
  5285. + unregister_chrdev_region(g_majorMinor, 1);
  5286. + bcm_dma_chan_free(g_dmaChan);
  5287. + return result;
  5288. + }
  5289. +
  5290. + return 0;
  5291. +}
  5292. +
  5293. +static void __exit dmaer_exit(void)
  5294. +{
  5295. + PRINTK(KERN_INFO "closing dmaer device, cache stats: %d hits %d misses\n", g_cacheHit, g_cacheMiss);
  5296. + //unregister the device
  5297. + cdev_del(&g_cDev);
  5298. + unregister_chrdev_region(g_majorMinor, 1);
  5299. + //free the dma channel
  5300. + bcm_dma_chan_free(g_dmaChan);
  5301. +}
  5302. +
  5303. +MODULE_LICENSE("Dual BSD/GPL");
  5304. +MODULE_AUTHOR("Simon Hall");
  5305. +module_init(dmaer_init);
  5306. +module_exit(dmaer_exit);
  5307. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/arm_control.h
  5308. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  5309. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-02-07 19:57:28.000000000 +0100
  5310. @@ -0,0 +1,419 @@
  5311. +/*
  5312. + * linux/arch/arm/mach-bcm2708/arm_control.h
  5313. + *
  5314. + * Copyright (C) 2010 Broadcom
  5315. + *
  5316. + * This program is free software; you can redistribute it and/or modify
  5317. + * it under the terms of the GNU General Public License as published by
  5318. + * the Free Software Foundation; either version 2 of the License, or
  5319. + * (at your option) any later version.
  5320. + *
  5321. + * This program is distributed in the hope that it will be useful,
  5322. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5323. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5324. + * GNU General Public License for more details.
  5325. + *
  5326. + * You should have received a copy of the GNU General Public License
  5327. + * along with this program; if not, write to the Free Software
  5328. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5329. + */
  5330. +
  5331. +#ifndef __BCM2708_ARM_CONTROL_H
  5332. +#define __BCM2708_ARM_CONTROL_H
  5333. +
  5334. +/*
  5335. + * Definitions and addresses for the ARM CONTROL logic
  5336. + * This file is manually generated.
  5337. + */
  5338. +
  5339. +#define ARM_BASE 0x7E00B000
  5340. +
  5341. +/* Basic configuration */
  5342. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  5343. +#define ARM_C0_SIZ128M 0x00000000
  5344. +#define ARM_C0_SIZ256M 0x00000001
  5345. +#define ARM_C0_SIZ512M 0x00000002
  5346. +#define ARM_C0_SIZ1G 0x00000003
  5347. +#define ARM_C0_BRESP0 0x00000000
  5348. +#define ARM_C0_BRESP1 0x00000004
  5349. +#define ARM_C0_BRESP2 0x00000008
  5350. +#define ARM_C0_BOOTHI 0x00000010
  5351. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  5352. +#define ARM_C0_FULLPERI 0x00000040
  5353. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  5354. +#define ARM_C0_JTAGMASK 0x00000E00
  5355. +#define ARM_C0_JTAGOFF 0x00000000
  5356. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  5357. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  5358. +#define ARM_C0_APROTMSK 0x0000F000
  5359. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  5360. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  5361. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  5362. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  5363. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  5364. +#define ARM_C0_PRIO_L2 0x0F000000
  5365. +#define ARM_C0_PRIO_UC 0xF0000000
  5366. +
  5367. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  5368. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  5369. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  5370. +
  5371. +
  5372. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  5373. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  5374. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  5375. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  5376. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  5377. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  5378. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  5379. +
  5380. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  5381. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  5382. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  5383. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  5384. +
  5385. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  5386. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  5387. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  5388. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  5389. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  5390. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  5391. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  5392. +
  5393. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  5394. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  5395. +#define ARM_IDVAL 0x364D5241
  5396. +
  5397. +/* Translation memory */
  5398. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  5399. +/* 32 locations: 0x100.. 0x17F */
  5400. +/* 32 spare means we CAN go to 64 pages.... */
  5401. +
  5402. +
  5403. +/* Interrupts */
  5404. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  5405. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  5406. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  5407. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  5408. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  5409. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  5410. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  5411. +
  5412. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  5413. +/* todo: all I1_interrupt sources */
  5414. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  5415. +/* todo: all I2_interrupt sources */
  5416. +
  5417. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  5418. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  5419. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  5420. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  5421. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  5422. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  5423. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  5424. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  5425. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  5426. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  5427. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  5428. +
  5429. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  5430. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  5431. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  5432. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  5433. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  5434. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  5435. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  5436. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  5437. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  5438. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  5439. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  5440. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  5441. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  5442. +
  5443. +/* Timer */
  5444. +/* For reg. fields see sp804 spec. */
  5445. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  5446. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  5447. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  5448. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  5449. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  5450. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  5451. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  5452. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  5453. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  5454. +
  5455. +#define TIMER_CTRL_ONESHOT (1 << 0)
  5456. +#define TIMER_CTRL_32BIT (1 << 1)
  5457. +#define TIMER_CTRL_DIV1 (0 << 2)
  5458. +#define TIMER_CTRL_DIV16 (1 << 2)
  5459. +#define TIMER_CTRL_DIV256 (2 << 2)
  5460. +#define TIMER_CTRL_IE (1 << 5)
  5461. +#define TIMER_CTRL_PERIODIC (1 << 6)
  5462. +#define TIMER_CTRL_ENABLE (1 << 7)
  5463. +#define TIMER_CTRL_DBGHALT (1 << 8)
  5464. +#define TIMER_CTRL_ENAFREE (1 << 9)
  5465. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  5466. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  5467. +
  5468. +/* Semaphores, Doorbells, Mailboxes */
  5469. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  5470. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  5471. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  5472. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  5473. +
  5474. +/* MAILBOXES
  5475. + * Register flags are common across all
  5476. + * owner registers. See end of this section
  5477. + *
  5478. + * Semaphores, Doorbells, Mailboxes Owner 0
  5479. + *
  5480. + */
  5481. +
  5482. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5483. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  5484. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  5485. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  5486. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  5487. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  5488. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  5489. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  5490. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  5491. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  5492. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  5493. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  5494. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  5495. +/* MAILBOX 0 access in Owner 0 area */
  5496. +/* Some addresses should ONLY be used by owner 0 */
  5497. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  5498. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  5499. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  5500. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  5501. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  5502. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  5503. +/* MAILBOX 1 access in Owner 0 area */
  5504. +/* Owner 0 should only WRITE to this mailbox */
  5505. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  5506. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  5507. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  5508. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  5509. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  5510. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  5511. +/* General SEM, BELL, MAIL config/status */
  5512. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  5513. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  5514. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  5515. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  5516. +
  5517. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  5518. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5519. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  5520. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  5521. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  5522. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  5523. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  5524. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  5525. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  5526. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  5527. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  5528. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  5529. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  5530. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  5531. +/* MAILBOX 0 access in Owner 0 area */
  5532. +/* Owner 1 should only WRITE to this mailbox */
  5533. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  5534. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  5535. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  5536. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  5537. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  5538. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  5539. +/* MAILBOX 1 access in Owner 0 area */
  5540. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  5541. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  5542. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  5543. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  5544. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  5545. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  5546. +/* General SEM, BELL, MAIL config/status */
  5547. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  5548. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  5549. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  5550. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  5551. +
  5552. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  5553. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5554. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  5555. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  5556. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  5557. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  5558. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  5559. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  5560. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  5561. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  5562. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  5563. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  5564. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  5565. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  5566. +/* MAILBOX 0 access in Owner 2 area */
  5567. +/* Owner 2 should only WRITE to this mailbox */
  5568. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  5569. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  5570. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  5571. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  5572. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  5573. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  5574. +/* MAILBOX 1 access in Owner 2 area */
  5575. +/* Owner 2 should only WRITE to this mailbox */
  5576. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  5577. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  5578. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  5579. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  5580. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  5581. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  5582. +/* General SEM, BELL, MAIL config/status */
  5583. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  5584. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  5585. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  5586. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  5587. +
  5588. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  5589. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5590. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  5591. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  5592. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  5593. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  5594. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  5595. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  5596. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  5597. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  5598. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  5599. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  5600. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  5601. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  5602. +/* MAILBOX 0 access in Owner 3 area */
  5603. +/* Owner 3 should only WRITE to this mailbox */
  5604. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  5605. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  5606. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  5607. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  5608. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  5609. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  5610. +/* MAILBOX 1 access in Owner 3 area */
  5611. +/* Owner 3 should only WRITE to this mailbox */
  5612. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  5613. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  5614. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  5615. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  5616. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  5617. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  5618. +/* General SEM, BELL, MAIL config/status */
  5619. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  5620. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  5621. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  5622. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  5623. +
  5624. +
  5625. +
  5626. +/* Mailbox flags. Valid for all owners */
  5627. +
  5628. +/* Mailbox status register (...0x98) */
  5629. +#define ARM_MS_FULL 0x80000000
  5630. +#define ARM_MS_EMPTY 0x40000000
  5631. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  5632. +
  5633. +/* MAILBOX config/status register (...0x9C) */
  5634. +/* ANY write to this register clears the error bits! */
  5635. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  5636. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  5637. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  5638. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  5639. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  5640. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  5641. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5642. +/* Bit 7 is unused */
  5643. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5644. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5645. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5646. +
  5647. +/* Semaphore clear/debug register (...0xE0) */
  5648. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5649. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5650. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5651. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5652. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5653. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5654. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5655. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5656. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5657. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5658. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5659. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5660. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5661. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5662. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5663. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5664. +
  5665. +/* Doorbells clear/debug register (...0xE4) */
  5666. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5667. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5668. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5669. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5670. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5671. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5672. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5673. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5674. +
  5675. +/* MY IRQS register (...0xF8) */
  5676. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5677. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5678. +
  5679. +/* ALL IRQS register (...0xF8) */
  5680. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5681. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5682. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5683. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5684. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5685. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5686. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5687. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5688. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5689. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5690. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5691. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5692. +/* */
  5693. +/* ARM JTAG BASH */
  5694. +/* */
  5695. +#define AJB_BASE 0x7e2000c0
  5696. +
  5697. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5698. +#define AJB_BITS0 0x000000
  5699. +#define AJB_BITS4 0x000004
  5700. +#define AJB_BITS8 0x000008
  5701. +#define AJB_BITS12 0x00000C
  5702. +#define AJB_BITS16 0x000010
  5703. +#define AJB_BITS20 0x000014
  5704. +#define AJB_BITS24 0x000018
  5705. +#define AJB_BITS28 0x00001C
  5706. +#define AJB_BITS32 0x000020
  5707. +#define AJB_BITS34 0x000022
  5708. +#define AJB_OUT_MS 0x000040
  5709. +#define AJB_OUT_LS 0x000000
  5710. +#define AJB_INV_CLK 0x000080
  5711. +#define AJB_D0_RISE 0x000100
  5712. +#define AJB_D0_FALL 0x000000
  5713. +#define AJB_D1_RISE 0x000200
  5714. +#define AJB_D1_FALL 0x000000
  5715. +#define AJB_IN_RISE 0x000400
  5716. +#define AJB_IN_FALL 0x000000
  5717. +#define AJB_ENABLE 0x000800
  5718. +#define AJB_HOLD0 0x000000
  5719. +#define AJB_HOLD1 0x001000
  5720. +#define AJB_HOLD2 0x002000
  5721. +#define AJB_HOLD3 0x003000
  5722. +#define AJB_RESETN 0x004000
  5723. +#define AJB_CLKSHFT 16
  5724. +#define AJB_BUSY 0x80000000
  5725. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5726. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5727. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5728. +
  5729. +#endif
  5730. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5731. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5732. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-02-07 19:57:28.000000000 +0100
  5733. @@ -0,0 +1,60 @@
  5734. +/*
  5735. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5736. + *
  5737. + * Copyright (C) 2010 Broadcom
  5738. + *
  5739. + * This program is free software; you can redistribute it and/or modify
  5740. + * it under the terms of the GNU General Public License as published by
  5741. + * the Free Software Foundation; either version 2 of the License, or
  5742. + * (at your option) any later version.
  5743. + *
  5744. + * This program is distributed in the hope that it will be useful,
  5745. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5746. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5747. + * GNU General Public License for more details.
  5748. + *
  5749. + * You should have received a copy of the GNU General Public License
  5750. + * along with this program; if not, write to the Free Software
  5751. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5752. + */
  5753. +
  5754. +#ifndef _ARM_POWER_H
  5755. +#define _ARM_POWER_H
  5756. +
  5757. +/* Use meaningful names on each side */
  5758. +#ifdef __VIDEOCORE__
  5759. +#define PREFIX(x) ARM_##x
  5760. +#else
  5761. +#define PREFIX(x) BCM_##x
  5762. +#endif
  5763. +
  5764. +enum {
  5765. + PREFIX(POWER_SDCARD_BIT),
  5766. + PREFIX(POWER_UART_BIT),
  5767. + PREFIX(POWER_MINIUART_BIT),
  5768. + PREFIX(POWER_USB_BIT),
  5769. + PREFIX(POWER_I2C0_BIT),
  5770. + PREFIX(POWER_I2C1_BIT),
  5771. + PREFIX(POWER_I2C2_BIT),
  5772. + PREFIX(POWER_SPI_BIT),
  5773. + PREFIX(POWER_CCP2TX_BIT),
  5774. +
  5775. + PREFIX(POWER_MAX)
  5776. +};
  5777. +
  5778. +enum {
  5779. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5780. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5781. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5782. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5783. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5784. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5785. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5786. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5787. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5788. +
  5789. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5790. + PREFIX(POWER_NONE) = 0
  5791. +};
  5792. +
  5793. +#endif
  5794. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5795. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5796. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-02-07 19:57:28.000000000 +0100
  5797. @@ -0,0 +1,7 @@
  5798. +#ifndef __ASM_MACH_CLKDEV_H
  5799. +#define __ASM_MACH_CLKDEV_H
  5800. +
  5801. +#define __clk_get(clk) ({ 1; })
  5802. +#define __clk_put(clk) do { } while (0)
  5803. +
  5804. +#endif
  5805. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-3.11.10/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5806. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5807. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-02-07 19:57:28.000000000 +0100
  5808. @@ -0,0 +1,22 @@
  5809. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5810. + *
  5811. + * Debugging macro include header
  5812. + *
  5813. + * Copyright (C) 2010 Broadcom
  5814. + * Copyright (C) 1994-1999 Russell King
  5815. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5816. + *
  5817. + * This program is free software; you can redistribute it and/or modify
  5818. + * it under the terms of the GNU General Public License version 2 as
  5819. + * published by the Free Software Foundation.
  5820. + *
  5821. +*/
  5822. +
  5823. +#include <mach/platform.h>
  5824. +
  5825. + .macro addruart, rp, rv, tmp
  5826. + ldr \rp, =UART0_BASE
  5827. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5828. + .endm
  5829. +
  5830. +#include <asm/hardware/debug-pl01x.S>
  5831. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/dma.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/dma.h
  5832. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5833. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/dma.h 2014-02-07 19:57:28.000000000 +0100
  5834. @@ -0,0 +1,86 @@
  5835. +/*
  5836. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5837. + *
  5838. + * Copyright (C) 2010 Broadcom
  5839. + *
  5840. + * This program is free software; you can redistribute it and/or modify
  5841. + * it under the terms of the GNU General Public License version 2 as
  5842. + * published by the Free Software Foundation.
  5843. + */
  5844. +
  5845. +
  5846. +#ifndef _MACH_BCM2708_DMA_H
  5847. +#define _MACH_BCM2708_DMA_H
  5848. +
  5849. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5850. +
  5851. +/* DMA CS Control and Status bits */
  5852. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5853. +#define BCM2708_DMA_INT (1 << 2)
  5854. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5855. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5856. +#define BCM2708_DMA_ERR (1 << 8)
  5857. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5858. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5859. +
  5860. +/* DMA control block "info" field bits */
  5861. +#define BCM2708_DMA_INT_EN (1 << 0)
  5862. +#define BCM2708_DMA_TDMODE (1 << 1)
  5863. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5864. +#define BCM2708_DMA_D_INC (1 << 4)
  5865. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5866. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5867. +#define BCM2708_DMA_S_INC (1 << 8)
  5868. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5869. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5870. +
  5871. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5872. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5873. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5874. +
  5875. +#define BCM2708_DMA_DREQ_EMMC 11
  5876. +#define BCM2708_DMA_DREQ_SDHOST 13
  5877. +
  5878. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5879. +#define BCM2708_DMA_ADDR 0x04
  5880. +/* the current control block appears in the following registers - read only */
  5881. +#define BCM2708_DMA_INFO 0x08
  5882. +#define BCM2708_DMA_NEXTCB 0x1C
  5883. +#define BCM2708_DMA_DEBUG 0x20
  5884. +
  5885. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5886. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5887. +
  5888. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5889. +
  5890. +struct bcm2708_dma_cb {
  5891. + unsigned long info;
  5892. + unsigned long src;
  5893. + unsigned long dst;
  5894. + unsigned long length;
  5895. + unsigned long stride;
  5896. + unsigned long next;
  5897. + unsigned long pad[2];
  5898. +};
  5899. +
  5900. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5901. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5902. + dma_addr_t control_block);
  5903. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5904. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5905. +
  5906. +/* When listing features we can ask for when allocating DMA channels give
  5907. + those with higher priority smaller ordinal numbers */
  5908. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5909. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5910. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5911. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5912. +#define BCM_DMA_FEATURE_COUNT 2
  5913. +
  5914. +/* return channel no or -ve error */
  5915. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5916. + void __iomem **out_dma_base, int *out_dma_irq);
  5917. +extern int bcm_dma_chan_free(int channel);
  5918. +
  5919. +
  5920. +#endif /* _MACH_BCM2708_DMA_H */
  5921. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-3.11.10/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5922. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5923. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-02-07 19:57:28.000000000 +0100
  5924. @@ -0,0 +1,69 @@
  5925. +/*
  5926. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5927. + *
  5928. + * Low-level IRQ helper macros for BCM2708 platforms
  5929. + *
  5930. + * Copyright (C) 2010 Broadcom
  5931. + *
  5932. + * This program is free software; you can redistribute it and/or modify
  5933. + * it under the terms of the GNU General Public License as published by
  5934. + * the Free Software Foundation; either version 2 of the License, or
  5935. + * (at your option) any later version.
  5936. + *
  5937. + * This program is distributed in the hope that it will be useful,
  5938. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5939. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5940. + * GNU General Public License for more details.
  5941. + *
  5942. + * You should have received a copy of the GNU General Public License
  5943. + * along with this program; if not, write to the Free Software
  5944. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5945. + */
  5946. +#include <mach/hardware.h>
  5947. +
  5948. + .macro disable_fiq
  5949. + .endm
  5950. +
  5951. + .macro get_irqnr_preamble, base, tmp
  5952. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5953. + .endm
  5954. +
  5955. + .macro arch_ret_to_user, tmp1, tmp2
  5956. + .endm
  5957. +
  5958. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5959. + /* get masked status */
  5960. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5961. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5962. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5963. + /* clear bits 8 and 9, and test */
  5964. + bics \irqstat, \irqstat, #0x300
  5965. + bne 1010f
  5966. +
  5967. + tst \tmp, #0x100
  5968. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5969. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5970. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5971. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5972. + bicne \irqstat, #((1<<18) | (1<<19))
  5973. + bne 1010f
  5974. +
  5975. + tst \tmp, #0x200
  5976. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5977. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5978. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5979. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5980. + bicne \irqstat, #((1<<30))
  5981. + beq 1020f
  5982. +
  5983. +1010:
  5984. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5985. + @ N.B. CLZ is an ARM5 instruction.
  5986. + sub \tmp, \irqstat, #1
  5987. + eor \irqstat, \irqstat, \tmp
  5988. + clz \tmp, \irqstat
  5989. + sub \irqnr, \tmp
  5990. +
  5991. +1020: @ EQ will be set if no irqs pending
  5992. +
  5993. + .endm
  5994. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/frc.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/frc.h
  5995. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5996. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/frc.h 2014-02-07 19:57:28.000000000 +0100
  5997. @@ -0,0 +1,38 @@
  5998. +/*
  5999. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6000. + *
  6001. + * BCM2708 free running counter (timer)
  6002. + *
  6003. + * Copyright (C) 2010 Broadcom
  6004. + *
  6005. + * This program is free software; you can redistribute it and/or modify
  6006. + * it under the terms of the GNU General Public License as published by
  6007. + * the Free Software Foundation; either version 2 of the License, or
  6008. + * (at your option) any later version.
  6009. + *
  6010. + * This program is distributed in the hope that it will be useful,
  6011. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6012. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6013. + * GNU General Public License for more details.
  6014. + *
  6015. + * You should have received a copy of the GNU General Public License
  6016. + * along with this program; if not, write to the Free Software
  6017. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6018. + */
  6019. +
  6020. +#ifndef _MACH_FRC_H
  6021. +#define _MACH_FRC_H
  6022. +
  6023. +#define FRC_TICK_RATE (1000000)
  6024. +
  6025. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6026. + (slightly faster than frc_clock_ticks63()
  6027. + */
  6028. +extern unsigned long frc_clock_ticks32(void);
  6029. +
  6030. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  6031. + * Note - top bit should be ignored (see cnt32_to_63)
  6032. + */
  6033. +extern unsigned long long frc_clock_ticks63(void);
  6034. +
  6035. +#endif
  6036. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/gpio.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/gpio.h
  6037. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  6038. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-02-07 19:57:28.000000000 +0100
  6039. @@ -0,0 +1,17 @@
  6040. +/*
  6041. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  6042. + *
  6043. + * This file is licensed under the terms of the GNU General Public
  6044. + * License version 2. This program is licensed "as is" without any
  6045. + * warranty of any kind, whether express or implied.
  6046. + */
  6047. +
  6048. +#ifndef __ASM_ARCH_GPIO_H
  6049. +#define __ASM_ARCH_GPIO_H
  6050. +
  6051. +#define ARCH_NR_GPIOS 54 // number of gpio lines
  6052. +
  6053. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  6054. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  6055. +
  6056. +#endif
  6057. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/hardware.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/hardware.h
  6058. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  6059. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-02-07 19:57:28.000000000 +0100
  6060. @@ -0,0 +1,28 @@
  6061. +/*
  6062. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  6063. + *
  6064. + * This file contains the hardware definitions of the BCM2708 devices.
  6065. + *
  6066. + * Copyright (C) 2010 Broadcom
  6067. + *
  6068. + * This program is free software; you can redistribute it and/or modify
  6069. + * it under the terms of the GNU General Public License as published by
  6070. + * the Free Software Foundation; either version 2 of the License, or
  6071. + * (at your option) any later version.
  6072. + *
  6073. + * This program is distributed in the hope that it will be useful,
  6074. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6075. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6076. + * GNU General Public License for more details.
  6077. + *
  6078. + * You should have received a copy of the GNU General Public License
  6079. + * along with this program; if not, write to the Free Software
  6080. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6081. + */
  6082. +#ifndef __ASM_ARCH_HARDWARE_H
  6083. +#define __ASM_ARCH_HARDWARE_H
  6084. +
  6085. +#include <asm/sizes.h>
  6086. +#include <mach/platform.h>
  6087. +
  6088. +#endif
  6089. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/io.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/io.h
  6090. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  6091. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/io.h 2014-02-07 19:57:28.000000000 +0100
  6092. @@ -0,0 +1,27 @@
  6093. +/*
  6094. + * arch/arm/mach-bcm2708/include/mach/io.h
  6095. + *
  6096. + * Copyright (C) 2003 ARM Limited
  6097. + *
  6098. + * This program is free software; you can redistribute it and/or modify
  6099. + * it under the terms of the GNU General Public License as published by
  6100. + * the Free Software Foundation; either version 2 of the License, or
  6101. + * (at your option) any later version.
  6102. + *
  6103. + * This program is distributed in the hope that it will be useful,
  6104. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6105. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6106. + * GNU General Public License for more details.
  6107. + *
  6108. + * You should have received a copy of the GNU General Public License
  6109. + * along with this program; if not, write to the Free Software
  6110. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6111. + */
  6112. +#ifndef __ASM_ARM_ARCH_IO_H
  6113. +#define __ASM_ARM_ARCH_IO_H
  6114. +
  6115. +#define IO_SPACE_LIMIT 0xffffffff
  6116. +
  6117. +#define __io(a) __typesafe_io(a)
  6118. +
  6119. +#endif
  6120. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/irqs.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/irqs.h
  6121. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  6122. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-02-07 19:57:28.000000000 +0100
  6123. @@ -0,0 +1,199 @@
  6124. +/*
  6125. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  6126. + *
  6127. + * Copyright (C) 2010 Broadcom
  6128. + * Copyright (C) 2003 ARM Limited
  6129. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  6130. + *
  6131. + * This program is free software; you can redistribute it and/or modify
  6132. + * it under the terms of the GNU General Public License as published by
  6133. + * the Free Software Foundation; either version 2 of the License, or
  6134. + * (at your option) any later version.
  6135. + *
  6136. + * This program is distributed in the hope that it will be useful,
  6137. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6138. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6139. + * GNU General Public License for more details.
  6140. + *
  6141. + * You should have received a copy of the GNU General Public License
  6142. + * along with this program; if not, write to the Free Software
  6143. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6144. + */
  6145. +
  6146. +#ifndef _BCM2708_IRQS_H_
  6147. +#define _BCM2708_IRQS_H_
  6148. +
  6149. +#include <mach/platform.h>
  6150. +
  6151. +/*
  6152. + * IRQ interrupts definitions are the same as the INT definitions
  6153. + * held within platform.h
  6154. + */
  6155. +#define IRQ_ARMCTRL_START 0
  6156. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  6157. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  6158. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  6159. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  6160. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  6161. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  6162. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  6163. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  6164. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  6165. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  6166. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  6167. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  6168. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  6169. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  6170. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  6171. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  6172. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  6173. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  6174. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  6175. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  6176. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  6177. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  6178. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  6179. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  6180. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  6181. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  6182. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  6183. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  6184. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  6185. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  6186. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  6187. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  6188. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  6189. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  6190. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  6191. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  6192. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  6193. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  6194. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  6195. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  6196. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  6197. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  6198. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  6199. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  6200. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  6201. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  6202. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  6203. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  6204. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  6205. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  6206. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  6207. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  6208. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  6209. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  6210. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  6211. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  6212. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  6213. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  6214. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  6215. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  6216. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  6217. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  6218. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  6219. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  6220. +
  6221. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  6222. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  6223. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  6224. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  6225. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  6226. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  6227. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  6228. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  6229. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  6230. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  6231. +
  6232. +#define FIQ_START HARD_IRQS
  6233. +
  6234. +/*
  6235. + * FIQ interrupts definitions are the same as the INT definitions.
  6236. + */
  6237. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  6238. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  6239. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  6240. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  6241. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  6242. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  6243. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  6244. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  6245. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  6246. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  6247. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  6248. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  6249. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  6250. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  6251. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  6252. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  6253. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  6254. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  6255. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  6256. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  6257. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  6258. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  6259. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  6260. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  6261. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  6262. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  6263. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  6264. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  6265. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  6266. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  6267. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  6268. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  6269. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  6270. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  6271. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  6272. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  6273. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  6274. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  6275. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  6276. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  6277. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  6278. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  6279. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  6280. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  6281. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  6282. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  6283. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  6284. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  6285. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  6286. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  6287. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  6288. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  6289. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  6290. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  6291. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  6292. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  6293. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  6294. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  6295. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  6296. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  6297. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  6298. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  6299. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  6300. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  6301. +
  6302. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  6303. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  6304. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  6305. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  6306. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  6307. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  6308. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  6309. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  6310. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  6311. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  6312. +
  6313. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  6314. +
  6315. +#define HARD_IRQS (64 + 21)
  6316. +#define FIQ_IRQS (64 + 21)
  6317. +#define GPIO_IRQS (32*5)
  6318. +
  6319. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS
  6320. +
  6321. +
  6322. +#endif /* _BCM2708_IRQS_H_ */
  6323. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/memory.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/memory.h
  6324. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  6325. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/memory.h 2014-02-07 19:57:28.000000000 +0100
  6326. @@ -0,0 +1,57 @@
  6327. +/*
  6328. + * arch/arm/mach-bcm2708/include/mach/memory.h
  6329. + *
  6330. + * Copyright (C) 2010 Broadcom
  6331. + *
  6332. + * This program is free software; you can redistribute it and/or modify
  6333. + * it under the terms of the GNU General Public License as published by
  6334. + * the Free Software Foundation; either version 2 of the License, or
  6335. + * (at your option) any later version.
  6336. + *
  6337. + * This program is distributed in the hope that it will be useful,
  6338. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6339. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6340. + * GNU General Public License for more details.
  6341. + *
  6342. + * You should have received a copy of the GNU General Public License
  6343. + * along with this program; if not, write to the Free Software
  6344. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6345. + */
  6346. +#ifndef __ASM_ARCH_MEMORY_H
  6347. +#define __ASM_ARCH_MEMORY_H
  6348. +
  6349. +/* Memory overview:
  6350. +
  6351. + [ARMcore] <--virtual addr-->
  6352. + [ARMmmu] <--physical addr-->
  6353. + [GERTmap] <--bus add-->
  6354. + [VCperiph]
  6355. +
  6356. +*/
  6357. +
  6358. +/*
  6359. + * Physical DRAM offset.
  6360. + */
  6361. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  6362. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  6363. +
  6364. +#ifdef CONFIG_BCM2708_NOL2CACHE
  6365. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  6366. +#else
  6367. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  6368. +#endif
  6369. +
  6370. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  6371. + * will provide the offset into this area as well as setting the bits that
  6372. + * stop the L1 and L2 cache from being used
  6373. + *
  6374. + * WARNING: this only works because the ARM is given memory at a fixed location
  6375. + * (ARMMEM_OFFSET)
  6376. + */
  6377. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  6378. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  6379. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  6380. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6381. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  6382. +
  6383. +#endif
  6384. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/platform.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/platform.h
  6385. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  6386. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/platform.h 2014-02-07 19:57:28.000000000 +0100
  6387. @@ -0,0 +1,226 @@
  6388. +/*
  6389. + * arch/arm/mach-bcm2708/include/mach/platform.h
  6390. + *
  6391. + * Copyright (C) 2010 Broadcom
  6392. + *
  6393. + * This program is free software; you can redistribute it and/or modify
  6394. + * it under the terms of the GNU General Public License as published by
  6395. + * the Free Software Foundation; either version 2 of the License, or
  6396. + * (at your option) any later version.
  6397. + *
  6398. + * This program is distributed in the hope that it will be useful,
  6399. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6400. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6401. + * GNU General Public License for more details.
  6402. + *
  6403. + * You should have received a copy of the GNU General Public License
  6404. + * along with this program; if not, write to the Free Software
  6405. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6406. + */
  6407. +
  6408. +#ifndef _BCM2708_PLATFORM_H
  6409. +#define _BCM2708_PLATFORM_H
  6410. +
  6411. +
  6412. +/* macros to get at IO space when running virtually */
  6413. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  6414. +
  6415. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  6416. +
  6417. +
  6418. +/*
  6419. + * SDRAM
  6420. + */
  6421. +#define BCM2708_SDRAM_BASE 0x00000000
  6422. +
  6423. +/*
  6424. + * Logic expansion modules
  6425. + *
  6426. + */
  6427. +
  6428. +
  6429. +/* ------------------------------------------------------------------------
  6430. + * BCM2708 ARMCTRL Registers
  6431. + * ------------------------------------------------------------------------
  6432. + */
  6433. +
  6434. +#define HW_REGISTER_RW(addr) (addr)
  6435. +#define HW_REGISTER_RO(addr) (addr)
  6436. +
  6437. +#include "arm_control.h"
  6438. +#undef ARM_BASE
  6439. +
  6440. +/*
  6441. + * Definitions and addresses for the ARM CONTROL logic
  6442. + * This file is manually generated.
  6443. + */
  6444. +
  6445. +#define BCM2708_PERI_BASE 0x20000000
  6446. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  6447. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  6448. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  6449. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  6450. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  6451. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  6452. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  6453. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  6454. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  6455. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  6456. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  6457. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  6458. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  6459. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  6460. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  6461. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  6462. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  6463. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  6464. +
  6465. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  6466. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  6467. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  6468. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  6469. +
  6470. +
  6471. +/*
  6472. + * Interrupt assignments
  6473. + */
  6474. +
  6475. +#define ARM_IRQ1_BASE 0
  6476. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  6477. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  6478. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  6479. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  6480. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  6481. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  6482. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  6483. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  6484. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  6485. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  6486. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  6487. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  6488. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  6489. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  6490. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  6491. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  6492. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  6493. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  6494. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  6495. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  6496. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  6497. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  6498. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  6499. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  6500. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  6501. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  6502. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  6503. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  6504. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  6505. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  6506. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  6507. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  6508. +
  6509. +#define ARM_IRQ2_BASE 32
  6510. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  6511. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  6512. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  6513. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  6514. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  6515. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  6516. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  6517. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  6518. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  6519. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  6520. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  6521. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  6522. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  6523. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  6524. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  6525. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  6526. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  6527. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  6528. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  6529. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  6530. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  6531. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  6532. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  6533. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  6534. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  6535. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  6536. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  6537. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  6538. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  6539. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  6540. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  6541. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  6542. +
  6543. +#define ARM_IRQ0_BASE 64
  6544. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  6545. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  6546. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  6547. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  6548. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  6549. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  6550. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  6551. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  6552. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  6553. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  6554. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  6555. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  6556. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  6557. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  6558. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  6559. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  6560. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  6561. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  6562. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  6563. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  6564. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  6565. +
  6566. +#define MAXIRQNUM (32 + 32 + 20)
  6567. +#define MAXFIQNUM (32 + 32 + 20)
  6568. +
  6569. +#define MAX_TIMER 2
  6570. +#define MAX_PERIOD 699050
  6571. +#define TICKS_PER_uSEC 1
  6572. +
  6573. +/*
  6574. + * These are useconds NOT ticks.
  6575. + *
  6576. + */
  6577. +#define mSEC_1 1000
  6578. +#define mSEC_5 (mSEC_1 * 5)
  6579. +#define mSEC_10 (mSEC_1 * 10)
  6580. +#define mSEC_25 (mSEC_1 * 25)
  6581. +#define SEC_1 (mSEC_1 * 1000)
  6582. +
  6583. +/*
  6584. + * Watchdog
  6585. + */
  6586. +#define PM_RSTC (PM_BASE+0x1c)
  6587. +#define PM_RSTS (PM_BASE+0x20)
  6588. +#define PM_WDOG (PM_BASE+0x24)
  6589. +
  6590. +#define PM_WDOG_RESET 0000000000
  6591. +#define PM_PASSWORD 0x5a000000
  6592. +#define PM_WDOG_TIME_SET 0x000fffff
  6593. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  6594. +#define PM_RSTC_WRCFG_SET 0x00000030
  6595. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  6596. +#define PM_RSTC_RESET 0x00000102
  6597. +
  6598. +#define PM_RSTS_HADPOR_SET 0x00001000
  6599. +#define PM_RSTS_HADSRH_SET 0x00000400
  6600. +#define PM_RSTS_HADSRF_SET 0x00000200
  6601. +#define PM_RSTS_HADSRQ_SET 0x00000100
  6602. +#define PM_RSTS_HADWRH_SET 0x00000040
  6603. +#define PM_RSTS_HADWRF_SET 0x00000020
  6604. +#define PM_RSTS_HADWRQ_SET 0x00000010
  6605. +#define PM_RSTS_HADDRH_SET 0x00000004
  6606. +#define PM_RSTS_HADDRF_SET 0x00000002
  6607. +#define PM_RSTS_HADDRQ_SET 0x00000001
  6608. +
  6609. +#define UART0_CLOCK 3000000
  6610. +
  6611. +#endif
  6612. +
  6613. +/* END */
  6614. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/power.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/power.h
  6615. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  6616. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/power.h 2014-02-07 19:57:28.000000000 +0100
  6617. @@ -0,0 +1,26 @@
  6618. +/*
  6619. + * linux/arch/arm/mach-bcm2708/power.h
  6620. + *
  6621. + * Copyright (C) 2010 Broadcom
  6622. + *
  6623. + * This program is free software; you can redistribute it and/or modify
  6624. + * it under the terms of the GNU General Public License version 2 as
  6625. + * published by the Free Software Foundation.
  6626. + *
  6627. + * This device provides a shared mechanism for controlling the power to
  6628. + * VideoCore subsystems.
  6629. + */
  6630. +
  6631. +#ifndef _MACH_BCM2708_POWER_H
  6632. +#define _MACH_BCM2708_POWER_H
  6633. +
  6634. +#include <linux/types.h>
  6635. +#include <mach/arm_power.h>
  6636. +
  6637. +typedef unsigned int BCM_POWER_HANDLE_T;
  6638. +
  6639. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6640. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6641. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6642. +
  6643. +#endif
  6644. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/system.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/system.h
  6645. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6646. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/system.h 2014-02-07 19:57:28.000000000 +0100
  6647. @@ -0,0 +1,38 @@
  6648. +/*
  6649. + * arch/arm/mach-bcm2708/include/mach/system.h
  6650. + *
  6651. + * Copyright (C) 2010 Broadcom
  6652. + * Copyright (C) 2003 ARM Limited
  6653. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6654. + *
  6655. + * This program is free software; you can redistribute it and/or modify
  6656. + * it under the terms of the GNU General Public License as published by
  6657. + * the Free Software Foundation; either version 2 of the License, or
  6658. + * (at your option) any later version.
  6659. + *
  6660. + * This program is distributed in the hope that it will be useful,
  6661. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6662. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6663. + * GNU General Public License for more details.
  6664. + *
  6665. + * You should have received a copy of the GNU General Public License
  6666. + * along with this program; if not, write to the Free Software
  6667. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6668. + */
  6669. +#ifndef __ASM_ARCH_SYSTEM_H
  6670. +#define __ASM_ARCH_SYSTEM_H
  6671. +
  6672. +#include <linux/io.h>
  6673. +#include <mach/hardware.h>
  6674. +#include <mach/platform.h>
  6675. +
  6676. +static inline void arch_idle(void)
  6677. +{
  6678. + /*
  6679. + * This should do all the clock switching
  6680. + * and wait for interrupt tricks
  6681. + */
  6682. + cpu_do_idle();
  6683. +}
  6684. +
  6685. +#endif
  6686. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/timex.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/timex.h
  6687. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6688. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/timex.h 2014-02-07 19:57:28.000000000 +0100
  6689. @@ -0,0 +1,23 @@
  6690. +/*
  6691. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6692. + *
  6693. + * BCM2708 sysem clock frequency
  6694. + *
  6695. + * Copyright (C) 2010 Broadcom
  6696. + *
  6697. + * This program is free software; you can redistribute it and/or modify
  6698. + * it under the terms of the GNU General Public License as published by
  6699. + * the Free Software Foundation; either version 2 of the License, or
  6700. + * (at your option) any later version.
  6701. + *
  6702. + * This program is distributed in the hope that it will be useful,
  6703. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6704. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6705. + * GNU General Public License for more details.
  6706. + *
  6707. + * You should have received a copy of the GNU General Public License
  6708. + * along with this program; if not, write to the Free Software
  6709. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6710. + */
  6711. +
  6712. +#define CLOCK_TICK_RATE (1000000)
  6713. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6714. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6715. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-02-07 19:57:28.000000000 +0100
  6716. @@ -0,0 +1,84 @@
  6717. +/*
  6718. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6719. + *
  6720. + * Copyright (C) 2010 Broadcom
  6721. + * Copyright (C) 2003 ARM Limited
  6722. + *
  6723. + * This program is free software; you can redistribute it and/or modify
  6724. + * it under the terms of the GNU General Public License as published by
  6725. + * the Free Software Foundation; either version 2 of the License, or
  6726. + * (at your option) any later version.
  6727. + *
  6728. + * This program is distributed in the hope that it will be useful,
  6729. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6730. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6731. + * GNU General Public License for more details.
  6732. + *
  6733. + * You should have received a copy of the GNU General Public License
  6734. + * along with this program; if not, write to the Free Software
  6735. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6736. + */
  6737. +
  6738. +#include <linux/io.h>
  6739. +#include <linux/amba/serial.h>
  6740. +#include <mach/hardware.h>
  6741. +
  6742. +#define UART_BAUD 115200
  6743. +
  6744. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6745. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6746. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6747. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6748. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6749. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6750. +
  6751. +/*
  6752. + * This does not append a newline
  6753. + */
  6754. +static inline void putc(int c)
  6755. +{
  6756. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6757. + barrier();
  6758. +
  6759. + __raw_writel(c, BCM2708_UART_DR);
  6760. +}
  6761. +
  6762. +static inline void flush(void)
  6763. +{
  6764. + int fr;
  6765. +
  6766. + do {
  6767. + fr = __raw_readl(BCM2708_UART_FR);
  6768. + barrier();
  6769. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6770. +}
  6771. +
  6772. +static inline void arch_decomp_setup(void)
  6773. +{
  6774. + int temp, div, rem, frac;
  6775. +
  6776. + temp = 16 * UART_BAUD;
  6777. + div = UART0_CLOCK / temp;
  6778. + rem = UART0_CLOCK % temp;
  6779. + temp = (8 * rem) / UART_BAUD;
  6780. + frac = (temp >> 1) + (temp & 1);
  6781. +
  6782. + /* Make sure the UART is disabled before we start */
  6783. + __raw_writel(0, BCM2708_UART_CR);
  6784. +
  6785. + /* Set the baud rate */
  6786. + __raw_writel(div, BCM2708_UART_IBRD);
  6787. + __raw_writel(frac, BCM2708_UART_FBRD);
  6788. +
  6789. + /* Set the UART to 8n1, FIFO enabled */
  6790. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6791. +
  6792. + /* Enable the UART */
  6793. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6794. + BCM2708_UART_CR);
  6795. +}
  6796. +
  6797. +/*
  6798. + * nothing to do
  6799. + */
  6800. +#define arch_decomp_wdog()
  6801. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vcio.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vcio.h
  6802. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6803. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-02-07 19:57:28.000000000 +0100
  6804. @@ -0,0 +1,141 @@
  6805. +/*
  6806. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6807. + *
  6808. + * Copyright (C) 2010 Broadcom
  6809. + *
  6810. + * This program is free software; you can redistribute it and/or modify
  6811. + * it under the terms of the GNU General Public License as published by
  6812. + * the Free Software Foundation; either version 2 of the License, or
  6813. + * (at your option) any later version.
  6814. + *
  6815. + * This program is distributed in the hope that it will be useful,
  6816. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6817. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6818. + * GNU General Public License for more details.
  6819. + *
  6820. + * You should have received a copy of the GNU General Public License
  6821. + * along with this program; if not, write to the Free Software
  6822. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6823. + */
  6824. +#ifndef _MACH_BCM2708_VCIO_H
  6825. +#define _MACH_BCM2708_VCIO_H
  6826. +
  6827. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6828. + * (semaphores, doorbells, mailboxes)
  6829. + */
  6830. +
  6831. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6832. +
  6833. +/* Constants shared with the ARM identifying separate mailbox channels */
  6834. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6835. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6836. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6837. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6838. +#define MBOX_CHAN_COUNT 9
  6839. +
  6840. +/* Mailbox property tags */
  6841. +enum {
  6842. + VCMSG_PROPERTY_END = 0x00000000,
  6843. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6844. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6845. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6846. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6847. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6848. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6849. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6850. + VCMSG_GET_CLOCKS = 0x00020007,
  6851. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6852. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6853. + VCMSG_GET_POWER_STATE = 0x00020001,
  6854. + VCMSG_GET_TIMING = 0x00020002,
  6855. + VCMSG_SET_POWER_STATE = 0x00028001,
  6856. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6857. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6858. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6859. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6860. + VCMSG_GET_VOLTAGE = 0x00030003,
  6861. + VCMSG_SET_VOLTAGE = 0x00038003,
  6862. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6863. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6864. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6865. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6866. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6867. + VCMSG_GET_TURBO = 0x00030009,
  6868. + VCMSG_SET_TURBO = 0x00038009,
  6869. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6870. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6871. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6872. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6873. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6874. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6875. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6876. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6877. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6878. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6879. + VCMSG_GET_DEPTH = 0x00040005,
  6880. + VCMSG_TST_DEPTH = 0x00044005,
  6881. + VCMSG_SET_DEPTH = 0x00048005,
  6882. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6883. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6884. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6885. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6886. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6887. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6888. + VCMSG_GET_PITCH = 0x00040008,
  6889. + VCMSG_TST_PITCH = 0x00044008,
  6890. + VCMSG_SET_PITCH = 0x00048008,
  6891. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6892. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6893. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6894. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6895. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6896. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6897. + VCMSG_GET_PALETTE = 0x0004000b,
  6898. + VCMSG_TST_PALETTE = 0x0004400b,
  6899. + VCMSG_SET_PALETTE = 0x0004800b,
  6900. + VCMSG_GET_LAYER = 0x0004000c,
  6901. + VCMSG_TST_LAYER = 0x0004400c,
  6902. + VCMSG_SET_LAYER = 0x0004800c,
  6903. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6904. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6905. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6906. +};
  6907. +
  6908. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6909. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6910. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6911. +
  6912. +#include <linux/ioctl.h>
  6913. +
  6914. +/*
  6915. + * The major device number. We can't rely on dynamic
  6916. + * registration any more, because ioctls need to know
  6917. + * it.
  6918. + */
  6919. +#define MAJOR_NUM 100
  6920. +
  6921. +/*
  6922. + * Set the message of the device driver
  6923. + */
  6924. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6925. +/*
  6926. + * _IOWR means that we're creating an ioctl command
  6927. + * number for passing information from a user process
  6928. + * to the kernel module and from the kernel module to user process
  6929. + *
  6930. + * The first arguments, MAJOR_NUM, is the major device
  6931. + * number we're using.
  6932. + *
  6933. + * The second argument is the number of the command
  6934. + * (there could be several with different meanings).
  6935. + *
  6936. + * The third argument is the type we want to get from
  6937. + * the process to the kernel.
  6938. + */
  6939. +
  6940. +/*
  6941. + * The name of the device file
  6942. + */
  6943. +#define DEVICE_FILE_NAME "char_dev"
  6944. +
  6945. +#endif
  6946. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6947. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6948. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-02-07 19:57:28.000000000 +0100
  6949. @@ -0,0 +1,35 @@
  6950. +/*****************************************************************************
  6951. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6952. +*
  6953. +* Unless you and Broadcom execute a separate written software license
  6954. +* agreement governing use of this software, this software is licensed to you
  6955. +* under the terms of the GNU General Public License version 2, available at
  6956. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6957. +*
  6958. +* Notwithstanding the above, under no circumstances may you combine this
  6959. +* software in any way with any other Broadcom software provided under a
  6960. +* license other than the GPL, without Broadcom's express prior written
  6961. +* consent.
  6962. +*****************************************************************************/
  6963. +
  6964. +#if !defined( VC_MEM_H )
  6965. +#define VC_MEM_H
  6966. +
  6967. +#include <linux/ioctl.h>
  6968. +
  6969. +#define VC_MEM_IOC_MAGIC 'v'
  6970. +
  6971. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6972. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6973. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6974. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6975. +
  6976. +#if defined( __KERNEL__ )
  6977. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6978. +
  6979. +extern unsigned long mm_vc_mem_phys_addr;
  6980. +extern unsigned int mm_vc_mem_size;
  6981. +extern int vc_mem_get_current_size( void );
  6982. +#endif
  6983. +
  6984. +#endif /* VC_MEM_H */
  6985. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vc_support.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vc_support.h
  6986. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vc_support.h 1970-01-01 01:00:00.000000000 +0100
  6987. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vc_support.h 2014-02-07 19:57:28.000000000 +0100
  6988. @@ -0,0 +1,69 @@
  6989. +#ifndef _VC_SUPPORT_H_
  6990. +#define _VC_SUPPORT_H_
  6991. +
  6992. +/*
  6993. + * vc_support.h
  6994. + *
  6995. + * Created on: 25 Nov 2012
  6996. + * Author: Simon
  6997. + */
  6998. +
  6999. +enum {
  7000. +/*
  7001. + If a MEM_HANDLE_T is discardable, the memory manager may resize it to size
  7002. + 0 at any time when it is not locked or retained.
  7003. + */
  7004. + MEM_FLAG_DISCARDABLE = 1 << 0,
  7005. +
  7006. + /*
  7007. + If a MEM_HANDLE_T is allocating (or normal), its block of memory will be
  7008. + accessed in an allocating fashion through the cache.
  7009. + */
  7010. + MEM_FLAG_NORMAL = 0 << 2,
  7011. + MEM_FLAG_ALLOCATING = MEM_FLAG_NORMAL,
  7012. +
  7013. + /*
  7014. + If a MEM_HANDLE_T is direct, its block of memory will be accessed
  7015. + directly, bypassing the cache.
  7016. + */
  7017. + MEM_FLAG_DIRECT = 1 << 2,
  7018. +
  7019. + /*
  7020. + If a MEM_HANDLE_T is coherent, its block of memory will be accessed in a
  7021. + non-allocating fashion through the cache.
  7022. + */
  7023. + MEM_FLAG_COHERENT = 2 << 2,
  7024. +
  7025. + /*
  7026. + If a MEM_HANDLE_T is L1-nonallocating, its block of memory will be accessed by
  7027. + the VPU in a fashion which is allocating in L2, but only coherent in L1.
  7028. + */
  7029. + MEM_FLAG_L1_NONALLOCATING = (MEM_FLAG_DIRECT | MEM_FLAG_COHERENT),
  7030. +
  7031. + /*
  7032. + If a MEM_HANDLE_T is zero'd, its contents are set to 0 rather than
  7033. + MEM_HANDLE_INVALID on allocation and resize up.
  7034. + */
  7035. + MEM_FLAG_ZERO = 1 << 4,
  7036. +
  7037. + /*
  7038. + If a MEM_HANDLE_T is uninitialised, it will not be reset to a defined value
  7039. + (either zero, or all 1's) on allocation.
  7040. + */
  7041. + MEM_FLAG_NO_INIT = 1 << 5,
  7042. +
  7043. + /*
  7044. + Hints.
  7045. + */
  7046. + MEM_FLAG_HINT_PERMALOCK = 1 << 6, /* Likely to be locked for long periods of time. */
  7047. +};
  7048. +
  7049. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags);
  7050. +unsigned int ReleaseVcMemory(unsigned int handle);
  7051. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle);
  7052. +unsigned int UnlockVcMemory(unsigned int handle);
  7053. +
  7054. +unsigned int ExecuteVcCode(unsigned int code,
  7055. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5);
  7056. +
  7057. +#endif
  7058. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7059. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  7060. +++ linux-3.11.10/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-02-07 19:57:28.000000000 +0100
  7061. @@ -0,0 +1,20 @@
  7062. +/*
  7063. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  7064. + *
  7065. + * Copyright (C) 2010 Broadcom
  7066. + *
  7067. + * This program is free software; you can redistribute it and/or modify
  7068. + * it under the terms of the GNU General Public License as published by
  7069. + * the Free Software Foundation; either version 2 of the License, or
  7070. + * (at your option) any later version.
  7071. + *
  7072. + * This program is distributed in the hope that it will be useful,
  7073. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7074. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7075. + * GNU General Public License for more details.
  7076. + *
  7077. + * You should have received a copy of the GNU General Public License
  7078. + * along with this program; if not, write to the Free Software
  7079. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  7080. + */
  7081. +#define VMALLOC_END (0xe8000000)
  7082. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/Kconfig linux-3.11.10/arch/arm/mach-bcm2708/Kconfig
  7083. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7084. +++ linux-3.11.10/arch/arm/mach-bcm2708/Kconfig 2014-02-07 19:57:28.000000000 +0100
  7085. @@ -0,0 +1,48 @@
  7086. +menu "Broadcom BCM2708 Implementations"
  7087. + depends on ARCH_BCM2708
  7088. +
  7089. +config MACH_BCM2708
  7090. + bool "Broadcom BCM2708 Development Platform"
  7091. + select NEED_MACH_MEMORY_H
  7092. + select NEED_MACH_IO_H
  7093. + select CPU_V6
  7094. + help
  7095. + Include support for the Broadcom(R) BCM2708 platform.
  7096. +
  7097. +config BCM2708_GPIO
  7098. + bool "BCM2708 gpio support"
  7099. + depends on MACH_BCM2708
  7100. + select ARCH_REQUIRE_GPIOLIB
  7101. + default y
  7102. + help
  7103. + Include support for the Broadcom(R) BCM2708 gpio.
  7104. +
  7105. +config BCM2708_VCMEM
  7106. + bool "Videocore Memory"
  7107. + depends on MACH_BCM2708
  7108. + default y
  7109. + help
  7110. + Helper for videocore memory access and total size allocation.
  7111. +
  7112. +config BCM2708_NOL2CACHE
  7113. + bool "Videocore L2 cache disable"
  7114. + depends on MACH_BCM2708
  7115. + default n
  7116. + help
  7117. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  7118. +
  7119. +config BCM2708_DMAER
  7120. + tristate "BCM2708 DMA helper"
  7121. + depends on MACH_BCM2708
  7122. + default n
  7123. + help
  7124. + Enable DMA helper for accelerating X composition
  7125. +
  7126. +config BCM2708_SPIDEV
  7127. + bool "Bind spidev to SPI0 master"
  7128. + depends on MACH_BCM2708
  7129. + depends on SPI
  7130. + default y
  7131. + help
  7132. + Binds spidev driver to the SPI0 master
  7133. +endmenu
  7134. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/Makefile linux-3.11.10/arch/arm/mach-bcm2708/Makefile
  7135. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  7136. +++ linux-3.11.10/arch/arm/mach-bcm2708/Makefile 2014-02-07 19:57:28.000000000 +0100
  7137. @@ -0,0 +1,10 @@
  7138. +#
  7139. +# Makefile for the linux kernel.
  7140. +#
  7141. +
  7142. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  7143. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  7144. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  7145. +
  7146. +obj-$(CONFIG_BCM2708_DMAER) += dmaer_master.o
  7147. +dmaer_master-objs := dmaer.o vc_support.o
  7148. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/Makefile.boot linux-3.11.10/arch/arm/mach-bcm2708/Makefile.boot
  7149. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  7150. +++ linux-3.11.10/arch/arm/mach-bcm2708/Makefile.boot 2014-02-07 19:57:28.000000000 +0100
  7151. @@ -0,0 +1,3 @@
  7152. + zreladdr-y := 0x00008000
  7153. +params_phys-y := 0x00000100
  7154. +initrd_phys-y := 0x00800000
  7155. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/power.c linux-3.11.10/arch/arm/mach-bcm2708/power.c
  7156. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  7157. +++ linux-3.11.10/arch/arm/mach-bcm2708/power.c 2014-02-07 19:57:28.000000000 +0100
  7158. @@ -0,0 +1,194 @@
  7159. +/*
  7160. + * linux/arch/arm/mach-bcm2708/power.c
  7161. + *
  7162. + * Copyright (C) 2010 Broadcom
  7163. + *
  7164. + * This program is free software; you can redistribute it and/or modify
  7165. + * it under the terms of the GNU General Public License version 2 as
  7166. + * published by the Free Software Foundation.
  7167. + *
  7168. + * This device provides a shared mechanism for controlling the power to
  7169. + * VideoCore subsystems.
  7170. + */
  7171. +
  7172. +#include <linux/module.h>
  7173. +#include <linux/semaphore.h>
  7174. +#include <linux/bug.h>
  7175. +#include <mach/power.h>
  7176. +#include <mach/vcio.h>
  7177. +#include <mach/arm_power.h>
  7178. +
  7179. +#define DRIVER_NAME "bcm2708_power"
  7180. +
  7181. +#define BCM_POWER_MAXCLIENTS 4
  7182. +#define BCM_POWER_NOCLIENT (1<<31)
  7183. +
  7184. +/* Some drivers expect there devices to be permanently powered */
  7185. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  7186. +
  7187. +#if 1
  7188. +#define DPRINTK printk
  7189. +#else
  7190. +#define DPRINTK if (0) printk
  7191. +#endif
  7192. +
  7193. +struct state_struct {
  7194. + uint32_t global_request;
  7195. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  7196. + struct semaphore client_mutex;
  7197. + struct semaphore mutex;
  7198. +} g_state;
  7199. +
  7200. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  7201. +{
  7202. + BCM_POWER_HANDLE_T i;
  7203. + int ret = -EBUSY;
  7204. +
  7205. + down(&g_state.client_mutex);
  7206. +
  7207. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7208. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  7209. + g_state.client_request[i] = BCM_POWER_NONE;
  7210. + *handle = i;
  7211. + ret = 0;
  7212. + break;
  7213. + }
  7214. + }
  7215. +
  7216. + up(&g_state.client_mutex);
  7217. +
  7218. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  7219. +
  7220. + return ret;
  7221. +}
  7222. +EXPORT_SYMBOL_GPL(bcm_power_open);
  7223. +
  7224. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  7225. +{
  7226. + int rc = 0;
  7227. +
  7228. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  7229. +
  7230. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  7231. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  7232. + if (down_interruptible(&g_state.mutex) != 0) {
  7233. + DPRINTK("bcm_power_request -> interrupted\n");
  7234. + return -EINTR;
  7235. + }
  7236. +
  7237. + if (request != g_state.client_request[handle]) {
  7238. + uint32_t others_request = 0;
  7239. + uint32_t global_request;
  7240. + BCM_POWER_HANDLE_T i;
  7241. +
  7242. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  7243. + if (i != handle)
  7244. + others_request |=
  7245. + g_state.client_request[i];
  7246. + }
  7247. + others_request &= ~BCM_POWER_NOCLIENT;
  7248. +
  7249. + global_request = request | others_request;
  7250. + if (global_request != g_state.global_request) {
  7251. + uint32_t actual;
  7252. +
  7253. + /* Send a request to VideoCore */
  7254. + bcm_mailbox_write(MBOX_CHAN_POWER,
  7255. + global_request << 4);
  7256. +
  7257. + /* Wait for a response during power-up */
  7258. + if (global_request & ~g_state.global_request) {
  7259. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  7260. + &actual);
  7261. + DPRINTK
  7262. + ("bcm_mailbox_read -> %08x, %d\n",
  7263. + actual, rc);
  7264. + actual >>= 4;
  7265. + } else {
  7266. + rc = 0;
  7267. + actual = global_request;
  7268. + }
  7269. +
  7270. + if (rc == 0) {
  7271. + if (actual != global_request) {
  7272. + printk(KERN_ERR
  7273. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  7274. + __func__,
  7275. + g_state.global_request,
  7276. + global_request, actual, request, others_request);
  7277. + /* A failure */
  7278. + BUG_ON((others_request & actual)
  7279. + != others_request);
  7280. + request &= actual;
  7281. + rc = -EIO;
  7282. + }
  7283. +
  7284. + g_state.global_request = actual;
  7285. + g_state.client_request[handle] =
  7286. + request;
  7287. + }
  7288. + }
  7289. + }
  7290. + up(&g_state.mutex);
  7291. + } else {
  7292. + rc = -EINVAL;
  7293. + }
  7294. + DPRINTK("bcm_power_request -> %d\n", rc);
  7295. + return rc;
  7296. +}
  7297. +EXPORT_SYMBOL_GPL(bcm_power_request);
  7298. +
  7299. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  7300. +{
  7301. + int rc;
  7302. +
  7303. + DPRINTK("bcm_power_close(%d)\n", handle);
  7304. +
  7305. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  7306. + if (rc == 0)
  7307. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  7308. +
  7309. + return rc;
  7310. +}
  7311. +EXPORT_SYMBOL_GPL(bcm_power_close);
  7312. +
  7313. +static int __init bcm_power_init(void)
  7314. +{
  7315. +#if defined(BCM_POWER_ALWAYS_ON)
  7316. + BCM_POWER_HANDLE_T always_on_handle;
  7317. +#endif
  7318. + int rc = 0;
  7319. + int i;
  7320. +
  7321. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  7322. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7323. +
  7324. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  7325. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  7326. +
  7327. + sema_init(&g_state.client_mutex, 1);
  7328. + sema_init(&g_state.mutex, 1);
  7329. +
  7330. + g_state.global_request = 0;
  7331. +
  7332. +#if defined(BCM_POWER_ALWAYS_ON)
  7333. + if (BCM_POWER_ALWAYS_ON) {
  7334. + bcm_power_open(&always_on_handle);
  7335. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  7336. + }
  7337. +#endif
  7338. +
  7339. + return rc;
  7340. +}
  7341. +
  7342. +static void __exit bcm_power_exit(void)
  7343. +{
  7344. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  7345. +}
  7346. +
  7347. +arch_initcall(bcm_power_init); /* Initialize early */
  7348. +module_exit(bcm_power_exit);
  7349. +
  7350. +MODULE_AUTHOR("Phil Elwell");
  7351. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  7352. +MODULE_LICENSE("GPL");
  7353. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/vcio.c linux-3.11.10/arch/arm/mach-bcm2708/vcio.c
  7354. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  7355. +++ linux-3.11.10/arch/arm/mach-bcm2708/vcio.c 2014-02-07 19:57:28.000000000 +0100
  7356. @@ -0,0 +1,474 @@
  7357. +/*
  7358. + * linux/arch/arm/mach-bcm2708/vcio.c
  7359. + *
  7360. + * Copyright (C) 2010 Broadcom
  7361. + *
  7362. + * This program is free software; you can redistribute it and/or modify
  7363. + * it under the terms of the GNU General Public License version 2 as
  7364. + * published by the Free Software Foundation.
  7365. + *
  7366. + * This device provides a shared mechanism for writing to the mailboxes,
  7367. + * semaphores, doorbells etc. that are shared between the ARM and the
  7368. + * VideoCore processor
  7369. + */
  7370. +
  7371. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  7372. +#define SUPPORT_SYSRQ
  7373. +#endif
  7374. +
  7375. +#include <linux/module.h>
  7376. +#include <linux/console.h>
  7377. +#include <linux/serial_core.h>
  7378. +#include <linux/serial.h>
  7379. +#include <linux/errno.h>
  7380. +#include <linux/device.h>
  7381. +#include <linux/init.h>
  7382. +#include <linux/mm.h>
  7383. +#include <linux/dma-mapping.h>
  7384. +#include <linux/platform_device.h>
  7385. +#include <linux/sysrq.h>
  7386. +#include <linux/delay.h>
  7387. +#include <linux/slab.h>
  7388. +#include <linux/interrupt.h>
  7389. +#include <linux/irq.h>
  7390. +
  7391. +#include <linux/io.h>
  7392. +
  7393. +#include <mach/vcio.h>
  7394. +#include <mach/platform.h>
  7395. +
  7396. +#include <asm/uaccess.h>
  7397. +
  7398. +
  7399. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  7400. +
  7401. +/* ----------------------------------------------------------------------
  7402. + * Mailbox
  7403. + * -------------------------------------------------------------------- */
  7404. +
  7405. +/* offsets from a mail box base address */
  7406. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  7407. +#define MAIL_RD 0x00 /* read - and next 4 words */
  7408. +#define MAIL_POL 0x10 /* read without popping the fifo */
  7409. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  7410. +#define MAIL_STA 0x18 /* status */
  7411. +#define MAIL_CNF 0x1C /* configuration */
  7412. +
  7413. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  7414. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  7415. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  7416. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  7417. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  7418. +
  7419. +#define MBOX_MAGIC 0xd0d0c0de
  7420. +
  7421. +struct vc_mailbox {
  7422. + struct device *dev; /* parent device */
  7423. + void __iomem *status;
  7424. + void __iomem *config;
  7425. + void __iomem *read;
  7426. + void __iomem *write;
  7427. + uint32_t msg[MBOX_CHAN_COUNT];
  7428. + struct semaphore sema[MBOX_CHAN_COUNT];
  7429. + uint32_t magic;
  7430. +};
  7431. +
  7432. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  7433. + uint32_t addr_mbox)
  7434. +{
  7435. + int i;
  7436. +
  7437. + mbox_out->dev = dev;
  7438. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  7439. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  7440. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  7441. + /* Write to the other mailbox */
  7442. + mbox_out->write =
  7443. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  7444. + MAIL_WRT);
  7445. +
  7446. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  7447. + mbox_out->msg[i] = 0;
  7448. + sema_init(&mbox_out->sema[i], 0);
  7449. + }
  7450. +
  7451. + /* Enable the interrupt on data reception */
  7452. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  7453. +
  7454. + mbox_out->magic = MBOX_MAGIC;
  7455. +}
  7456. +
  7457. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  7458. +{
  7459. + int rc;
  7460. +
  7461. + if (mbox->magic != MBOX_MAGIC)
  7462. + rc = -EINVAL;
  7463. + else {
  7464. + /* wait for the mailbox FIFO to have some space in it */
  7465. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  7466. + cpu_relax();
  7467. +
  7468. + writel(MBOX_MSG(chan, data28), mbox->write);
  7469. + rc = 0;
  7470. + }
  7471. + return rc;
  7472. +}
  7473. +
  7474. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  7475. +{
  7476. + int rc;
  7477. +
  7478. + if (mbox->magic != MBOX_MAGIC)
  7479. + rc = -EINVAL;
  7480. + else {
  7481. + down(&mbox->sema[chan]);
  7482. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  7483. + mbox->msg[chan] = 0;
  7484. + rc = 0;
  7485. + }
  7486. + return rc;
  7487. +}
  7488. +
  7489. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  7490. +{
  7491. + /* wait for the mailbox FIFO to have some data in it */
  7492. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  7493. + int status = readl(mbox->status);
  7494. + int ret = IRQ_NONE;
  7495. +
  7496. + while (!(status & ARM_MS_EMPTY)) {
  7497. + uint32_t msg = readl(mbox->read);
  7498. + int chan = MBOX_CHAN(msg);
  7499. + if (chan < MBOX_CHAN_COUNT) {
  7500. + if (mbox->msg[chan]) {
  7501. + /* Overflow */
  7502. + printk(KERN_ERR DRIVER_NAME
  7503. + ": mbox chan %d overflow - drop %08x\n",
  7504. + chan, msg);
  7505. + } else {
  7506. + mbox->msg[chan] = (msg | 0xf);
  7507. + up(&mbox->sema[chan]);
  7508. + }
  7509. + } else {
  7510. + printk(KERN_ERR DRIVER_NAME
  7511. + ": invalid channel selector (msg %08x)\n", msg);
  7512. + }
  7513. + ret = IRQ_HANDLED;
  7514. + status = readl(mbox->status);
  7515. + }
  7516. + return ret;
  7517. +}
  7518. +
  7519. +static struct irqaction mbox_irqaction = {
  7520. + .name = "ARM Mailbox IRQ",
  7521. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  7522. + .handler = mbox_irq,
  7523. +};
  7524. +
  7525. +/* ----------------------------------------------------------------------
  7526. + * Mailbox Methods
  7527. + * -------------------------------------------------------------------- */
  7528. +
  7529. +static struct device *mbox_dev; /* we assume there's only one! */
  7530. +
  7531. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  7532. +{
  7533. + int rc;
  7534. +
  7535. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7536. + device_lock(dev);
  7537. + rc = mbox_write(mailbox, chan, data28);
  7538. + device_unlock(dev);
  7539. +
  7540. + return rc;
  7541. +}
  7542. +
  7543. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  7544. +{
  7545. + int rc;
  7546. +
  7547. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  7548. + device_lock(dev);
  7549. + rc = mbox_read(mailbox, chan, data28);
  7550. + device_unlock(dev);
  7551. +
  7552. + return rc;
  7553. +}
  7554. +
  7555. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  7556. +{
  7557. + if (mbox_dev)
  7558. + return dev_mbox_write(mbox_dev, chan, data28);
  7559. + else
  7560. + return -ENODEV;
  7561. +}
  7562. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  7563. +
  7564. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  7565. +{
  7566. + if (mbox_dev)
  7567. + return dev_mbox_read(mbox_dev, chan, data28);
  7568. + else
  7569. + return -ENODEV;
  7570. +}
  7571. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  7572. +
  7573. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  7574. +{
  7575. + mbox_dev = dev;
  7576. +}
  7577. +
  7578. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  7579. +{
  7580. + if ( (uint32_t)src < TASK_SIZE)
  7581. + {
  7582. + return copy_from_user(dst, src, size);
  7583. + }
  7584. + else
  7585. + {
  7586. + memcpy( dst, src, size );
  7587. + return 0;
  7588. + }
  7589. +}
  7590. +
  7591. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  7592. +{
  7593. + if ( (uint32_t)dst < TASK_SIZE)
  7594. + {
  7595. + return copy_to_user(dst, src, size);
  7596. + }
  7597. + else
  7598. + {
  7599. + memcpy( dst, src, size );
  7600. + return 0;
  7601. + }
  7602. +}
  7603. +
  7604. +static DEFINE_MUTEX(mailbox_lock);
  7605. +extern int bcm_mailbox_property(void *data, int size)
  7606. +{
  7607. + uint32_t success;
  7608. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  7609. + void *mem_kern; /* the memory address accessed from driver */
  7610. + int s = 0;
  7611. +
  7612. + mutex_lock(&mailbox_lock);
  7613. + /* allocate some memory for the messages communicating with GPU */
  7614. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  7615. + if (mem_kern) {
  7616. + /* create the message */
  7617. + mbox_copy_from_user(mem_kern, data, size);
  7618. +
  7619. + /* send the message */
  7620. + wmb();
  7621. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  7622. + if (s == 0) {
  7623. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  7624. + }
  7625. + if (s == 0) {
  7626. + /* copy the response */
  7627. + rmb();
  7628. + mbox_copy_to_user(data, mem_kern, size);
  7629. + }
  7630. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  7631. + } else {
  7632. + s = -ENOMEM;
  7633. + }
  7634. + if (s != 0)
  7635. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  7636. +
  7637. + mutex_unlock(&mailbox_lock);
  7638. + return s;
  7639. +}
  7640. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  7641. +
  7642. +/* ----------------------------------------------------------------------
  7643. + * Platform Device for Mailbox
  7644. + * -------------------------------------------------------------------- */
  7645. +
  7646. +/*
  7647. + * Is the device open right now? Used to prevent
  7648. + * concurent access into the same device
  7649. + */
  7650. +static int Device_Open = 0;
  7651. +
  7652. +/*
  7653. + * This is called whenever a process attempts to open the device file
  7654. + */
  7655. +static int device_open(struct inode *inode, struct file *file)
  7656. +{
  7657. + /*
  7658. + * We don't want to talk to two processes at the same time
  7659. + */
  7660. + if (Device_Open)
  7661. + return -EBUSY;
  7662. +
  7663. + Device_Open++;
  7664. + /*
  7665. + * Initialize the message
  7666. + */
  7667. + try_module_get(THIS_MODULE);
  7668. + return 0;
  7669. +}
  7670. +
  7671. +static int device_release(struct inode *inode, struct file *file)
  7672. +{
  7673. + /*
  7674. + * We're now ready for our next caller
  7675. + */
  7676. + Device_Open--;
  7677. +
  7678. + module_put(THIS_MODULE);
  7679. + return 0;
  7680. +}
  7681. +
  7682. +/*
  7683. + * This function is called whenever a process tries to do an ioctl on our
  7684. + * device file. We get two extra parameters (additional to the inode and file
  7685. + * structures, which all device functions get): the number of the ioctl called
  7686. + * and the parameter given to the ioctl function.
  7687. + *
  7688. + * If the ioctl is write or read/write (meaning output is returned to the
  7689. + * calling process), the ioctl call returns the output of this function.
  7690. + *
  7691. + */
  7692. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  7693. + unsigned int ioctl_num, /* number and param for ioctl */
  7694. + unsigned long ioctl_param)
  7695. +{
  7696. + unsigned size;
  7697. + /*
  7698. + * Switch according to the ioctl called
  7699. + */
  7700. + switch (ioctl_num) {
  7701. + case IOCTL_MBOX_PROPERTY:
  7702. + /*
  7703. + * Receive a pointer to a message (in user space) and set that
  7704. + * to be the device's message. Get the parameter given to
  7705. + * ioctl by the process.
  7706. + */
  7707. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  7708. + return bcm_mailbox_property((void *)ioctl_param, size);
  7709. + break;
  7710. + default:
  7711. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  7712. + return -EINVAL;
  7713. + }
  7714. +
  7715. + return 0;
  7716. +}
  7717. +
  7718. +/* Module Declarations */
  7719. +
  7720. +/*
  7721. + * This structure will hold the functions to be called
  7722. + * when a process does something to the device we
  7723. + * created. Since a pointer to this structure is kept in
  7724. + * the devices table, it can't be local to
  7725. + * init_module. NULL is for unimplemented functios.
  7726. + */
  7727. +struct file_operations fops = {
  7728. + .unlocked_ioctl = device_ioctl,
  7729. + .open = device_open,
  7730. + .release = device_release, /* a.k.a. close */
  7731. +};
  7732. +
  7733. +static int bcm_vcio_probe(struct platform_device *pdev)
  7734. +{
  7735. + int ret = 0;
  7736. + struct vc_mailbox *mailbox;
  7737. +
  7738. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7739. + if (NULL == mailbox) {
  7740. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7741. + "mailbox memory\n");
  7742. + ret = -ENOMEM;
  7743. + } else {
  7744. + struct resource *res;
  7745. +
  7746. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7747. + if (res == NULL) {
  7748. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7749. + "resource\n");
  7750. + ret = -ENODEV;
  7751. + kfree(mailbox);
  7752. + } else {
  7753. + /* should be based on the registers from res really */
  7754. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7755. +
  7756. + platform_set_drvdata(pdev, mailbox);
  7757. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7758. +
  7759. + mbox_irqaction.dev_id = mailbox;
  7760. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7761. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7762. + __io_address(ARM_0_MAIL0_RD));
  7763. + }
  7764. + }
  7765. +
  7766. + if (ret == 0) {
  7767. + /*
  7768. + * Register the character device
  7769. + */
  7770. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7771. +
  7772. + /*
  7773. + * Negative values signify an error
  7774. + */
  7775. + if (ret < 0) {
  7776. + printk(KERN_ERR DRIVER_NAME
  7777. + "Failed registering the character device %d\n", ret);
  7778. + return ret;
  7779. + }
  7780. + }
  7781. + return ret;
  7782. +}
  7783. +
  7784. +static int bcm_vcio_remove(struct platform_device *pdev)
  7785. +{
  7786. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7787. +
  7788. + platform_set_drvdata(pdev, NULL);
  7789. + kfree(mailbox);
  7790. +
  7791. + return 0;
  7792. +}
  7793. +
  7794. +static struct platform_driver bcm_mbox_driver = {
  7795. + .probe = bcm_vcio_probe,
  7796. + .remove = bcm_vcio_remove,
  7797. +
  7798. + .driver = {
  7799. + .name = DRIVER_NAME,
  7800. + .owner = THIS_MODULE,
  7801. + },
  7802. +};
  7803. +
  7804. +static int __init bcm_mbox_init(void)
  7805. +{
  7806. + int ret;
  7807. +
  7808. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7809. +
  7810. + ret = platform_driver_register(&bcm_mbox_driver);
  7811. + if (ret != 0) {
  7812. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7813. + "on platform\n");
  7814. + }
  7815. +
  7816. + return ret;
  7817. +}
  7818. +
  7819. +static void __exit bcm_mbox_exit(void)
  7820. +{
  7821. + platform_driver_unregister(&bcm_mbox_driver);
  7822. +}
  7823. +
  7824. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7825. +module_exit(bcm_mbox_exit);
  7826. +
  7827. +MODULE_AUTHOR("Gray Girling");
  7828. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7829. +MODULE_LICENSE("GPL");
  7830. +MODULE_ALIAS("platform:bcm-mbox");
  7831. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/vc_mem.c linux-3.11.10/arch/arm/mach-bcm2708/vc_mem.c
  7832. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7833. +++ linux-3.11.10/arch/arm/mach-bcm2708/vc_mem.c 2014-02-07 19:57:28.000000000 +0100
  7834. @@ -0,0 +1,462 @@
  7835. +/*****************************************************************************
  7836. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7837. +*
  7838. +* Unless you and Broadcom execute a separate written software license
  7839. +* agreement governing use of this software, this software is licensed to you
  7840. +* under the terms of the GNU General Public License version 2, available at
  7841. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7842. +*
  7843. +* Notwithstanding the above, under no circumstances may you combine this
  7844. +* software in any way with any other Broadcom software provided under a
  7845. +* license other than the GPL, without Broadcom's express prior written
  7846. +* consent.
  7847. +*****************************************************************************/
  7848. +
  7849. +#include <linux/kernel.h>
  7850. +#include <linux/module.h>
  7851. +#include <linux/fs.h>
  7852. +#include <linux/device.h>
  7853. +#include <linux/cdev.h>
  7854. +#include <linux/mm.h>
  7855. +#include <linux/slab.h>
  7856. +#include <linux/proc_fs.h>
  7857. +#include <asm/uaccess.h>
  7858. +#include <linux/dma-mapping.h>
  7859. +
  7860. +#ifdef CONFIG_ARCH_KONA
  7861. +#include <chal/chal_ipc.h>
  7862. +#elif CONFIG_ARCH_BCM2708
  7863. +#else
  7864. +#include <csp/chal_ipc.h>
  7865. +#endif
  7866. +
  7867. +#include "mach/vc_mem.h"
  7868. +#include <mach/vcio.h>
  7869. +
  7870. +#define DRIVER_NAME "vc-mem"
  7871. +
  7872. +// Uncomment to enable debug logging
  7873. +// #define ENABLE_DBG
  7874. +
  7875. +#if defined(ENABLE_DBG)
  7876. +#define LOG_DBG( fmt, ... ) printk( KERN_INFO fmt "\n", ##__VA_ARGS__ )
  7877. +#else
  7878. +#define LOG_DBG( fmt, ... )
  7879. +#endif
  7880. +#define LOG_ERR( fmt, ... ) printk( KERN_ERR fmt "\n", ##__VA_ARGS__ )
  7881. +
  7882. +// Device (/dev) related variables
  7883. +static dev_t vc_mem_devnum = 0;
  7884. +static struct class *vc_mem_class = NULL;
  7885. +static struct cdev vc_mem_cdev;
  7886. +static int vc_mem_inited = 0;
  7887. +
  7888. +// Proc entry
  7889. +static struct proc_dir_entry *vc_mem_proc_entry;
  7890. +
  7891. +/*
  7892. + * Videocore memory addresses and size
  7893. + *
  7894. + * Drivers that wish to know the videocore memory addresses and sizes should
  7895. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7896. + * headers. This allows the other drivers to not be tied down to a a certain
  7897. + * address/size at compile time.
  7898. + *
  7899. + * In the future, the goal is to have the videocore memory virtual address and
  7900. + * size be calculated at boot time rather than at compile time. The decision of
  7901. + * where the videocore memory resides and its size would be in the hands of the
  7902. + * bootloader (and/or kernel). When that happens, the values of these variables
  7903. + * would be calculated and assigned in the init function.
  7904. + */
  7905. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7906. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7907. +unsigned int mm_vc_mem_size = 0;
  7908. +unsigned int mm_vc_mem_base = 0;
  7909. +
  7910. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7911. +EXPORT_SYMBOL(mm_vc_mem_size);
  7912. +EXPORT_SYMBOL(mm_vc_mem_base);
  7913. +
  7914. +static uint phys_addr = 0;
  7915. +static uint mem_size = 0;
  7916. +static uint mem_base = 0;
  7917. +
  7918. +
  7919. +/****************************************************************************
  7920. +*
  7921. +* vc_mem_open
  7922. +*
  7923. +***************************************************************************/
  7924. +
  7925. +static int
  7926. +vc_mem_open(struct inode *inode, struct file *file)
  7927. +{
  7928. + (void) inode;
  7929. + (void) file;
  7930. +
  7931. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  7932. +
  7933. + return 0;
  7934. +}
  7935. +
  7936. +/****************************************************************************
  7937. +*
  7938. +* vc_mem_release
  7939. +*
  7940. +***************************************************************************/
  7941. +
  7942. +static int
  7943. +vc_mem_release(struct inode *inode, struct file *file)
  7944. +{
  7945. + (void) inode;
  7946. + (void) file;
  7947. +
  7948. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  7949. +
  7950. + return 0;
  7951. +}
  7952. +
  7953. +/****************************************************************************
  7954. +*
  7955. +* vc_mem_get_size
  7956. +*
  7957. +***************************************************************************/
  7958. +
  7959. +static void
  7960. +vc_mem_get_size(void)
  7961. +{
  7962. +}
  7963. +
  7964. +/****************************************************************************
  7965. +*
  7966. +* vc_mem_get_base
  7967. +*
  7968. +***************************************************************************/
  7969. +
  7970. +static void
  7971. +vc_mem_get_base(void)
  7972. +{
  7973. +}
  7974. +
  7975. +/****************************************************************************
  7976. +*
  7977. +* vc_mem_get_current_size
  7978. +*
  7979. +***************************************************************************/
  7980. +
  7981. +int
  7982. +vc_mem_get_current_size(void)
  7983. +{
  7984. + return mm_vc_mem_size;
  7985. +}
  7986. +
  7987. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7988. +
  7989. +/****************************************************************************
  7990. +*
  7991. +* vc_mem_ioctl
  7992. +*
  7993. +***************************************************************************/
  7994. +
  7995. +static long
  7996. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7997. +{
  7998. + int rc = 0;
  7999. +
  8000. + (void) cmd;
  8001. + (void) arg;
  8002. +
  8003. + LOG_DBG("%s: called file = 0x%p", __func__, file);
  8004. +
  8005. + switch (cmd) {
  8006. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  8007. + {
  8008. + LOG_DBG("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p",
  8009. + __func__, (void *) mm_vc_mem_phys_addr);
  8010. +
  8011. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  8012. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  8013. + rc = -EFAULT;
  8014. + }
  8015. + break;
  8016. + }
  8017. + case VC_MEM_IOC_MEM_SIZE:
  8018. + {
  8019. + // Get the videocore memory size first
  8020. + vc_mem_get_size();
  8021. +
  8022. + LOG_DBG("%s: VC_MEM_IOC_MEM_SIZE=%u", __func__,
  8023. + mm_vc_mem_size);
  8024. +
  8025. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  8026. + sizeof (mm_vc_mem_size)) != 0) {
  8027. + rc = -EFAULT;
  8028. + }
  8029. + break;
  8030. + }
  8031. + case VC_MEM_IOC_MEM_BASE:
  8032. + {
  8033. + // Get the videocore memory base
  8034. + vc_mem_get_base();
  8035. +
  8036. + LOG_DBG("%s: VC_MEM_IOC_MEM_BASE=%u", __func__,
  8037. + mm_vc_mem_base);
  8038. +
  8039. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8040. + sizeof (mm_vc_mem_base)) != 0) {
  8041. + rc = -EFAULT;
  8042. + }
  8043. + break;
  8044. + }
  8045. + case VC_MEM_IOC_MEM_LOAD:
  8046. + {
  8047. + // Get the videocore memory base
  8048. + vc_mem_get_base();
  8049. +
  8050. + LOG_DBG("%s: VC_MEM_IOC_MEM_LOAD=%u", __func__,
  8051. + mm_vc_mem_base);
  8052. +
  8053. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  8054. + sizeof (mm_vc_mem_base)) != 0) {
  8055. + rc = -EFAULT;
  8056. + }
  8057. + break;
  8058. + }
  8059. + default:
  8060. + {
  8061. + return -ENOTTY;
  8062. + }
  8063. + }
  8064. + LOG_DBG("%s: file = 0x%p returning %d", __func__, file, rc);
  8065. +
  8066. + return rc;
  8067. +}
  8068. +
  8069. +/****************************************************************************
  8070. +*
  8071. +* vc_mem_mmap
  8072. +*
  8073. +***************************************************************************/
  8074. +
  8075. +static int
  8076. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  8077. +{
  8078. + int rc = 0;
  8079. + unsigned long length = vma->vm_end - vma->vm_start;
  8080. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  8081. +
  8082. + LOG_DBG("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx",
  8083. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  8084. + (long) vma->vm_pgoff);
  8085. +
  8086. + if (offset + length > mm_vc_mem_size) {
  8087. + LOG_ERR("%s: length %ld is too big", __func__, length);
  8088. + return -EINVAL;
  8089. + }
  8090. + // Do not cache the memory map
  8091. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  8092. +
  8093. + rc = remap_pfn_range(vma, vma->vm_start,
  8094. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  8095. + vma->vm_pgoff, length, vma->vm_page_prot);
  8096. + if (rc != 0) {
  8097. + LOG_ERR("%s: remap_pfn_range failed (rc=%d)", __func__, rc);
  8098. + }
  8099. +
  8100. + return rc;
  8101. +}
  8102. +
  8103. +/****************************************************************************
  8104. +*
  8105. +* File Operations for the driver.
  8106. +*
  8107. +***************************************************************************/
  8108. +
  8109. +static const struct file_operations vc_mem_fops = {
  8110. + .owner = THIS_MODULE,
  8111. + .open = vc_mem_open,
  8112. + .release = vc_mem_release,
  8113. + .unlocked_ioctl = vc_mem_ioctl,
  8114. + .mmap = vc_mem_mmap,
  8115. +};
  8116. +
  8117. +/****************************************************************************
  8118. +*
  8119. +* vc_mem_proc_read
  8120. +*
  8121. +***************************************************************************/
  8122. +
  8123. +static int
  8124. +vc_mem_proc_read(char *buf, char **start, off_t offset, int count, int *eof,
  8125. + void *data)
  8126. +{
  8127. + char *p = buf;
  8128. +
  8129. + (void) start;
  8130. + (void) count;
  8131. + (void) data;
  8132. +
  8133. + if (offset > 0) {
  8134. + *eof = 1;
  8135. + return 0;
  8136. + }
  8137. + // Get the videocore memory size first
  8138. + vc_mem_get_size();
  8139. +
  8140. + p += sprintf(p, "Videocore memory:\n");
  8141. + if (mm_vc_mem_phys_addr != 0)
  8142. + p += sprintf(p, " Physical address: 0x%p\n",
  8143. + (void *) mm_vc_mem_phys_addr);
  8144. + else
  8145. + p += sprintf(p, " Physical address: 0x00000000\n");
  8146. + p += sprintf(p, " Length (bytes): %u\n", mm_vc_mem_size);
  8147. +
  8148. + *eof = 1;
  8149. + return p - buf;
  8150. +}
  8151. +
  8152. +/****************************************************************************
  8153. +*
  8154. +* vc_mem_proc_write
  8155. +*
  8156. +***************************************************************************/
  8157. +
  8158. +static int
  8159. +vc_mem_proc_write(struct file *file, const char __user * buffer,
  8160. + unsigned long count, void *data)
  8161. +{
  8162. + int rc = -EFAULT;
  8163. + char input_str[10];
  8164. +
  8165. + memset(input_str, 0, sizeof (input_str));
  8166. +
  8167. + if (count > sizeof (input_str)) {
  8168. + LOG_ERR("%s: input string length too long", __func__);
  8169. + goto out;
  8170. + }
  8171. +
  8172. + if (copy_from_user(input_str, buffer, count - 1)) {
  8173. + LOG_ERR("%s: failed to get input string", __func__);
  8174. + goto out;
  8175. + }
  8176. +
  8177. + if (strncmp(input_str, "connect", strlen("connect")) == 0) {
  8178. + // Get the videocore memory size from the videocore
  8179. + vc_mem_get_size();
  8180. + }
  8181. +
  8182. + out:
  8183. + return rc;
  8184. +}
  8185. +
  8186. +/****************************************************************************
  8187. +*
  8188. +* vc_mem_init
  8189. +*
  8190. +***************************************************************************/
  8191. +
  8192. +static int __init
  8193. +vc_mem_init(void)
  8194. +{
  8195. + int rc = -EFAULT;
  8196. + struct device *dev;
  8197. +
  8198. + LOG_DBG("%s: called", __func__);
  8199. +
  8200. + mm_vc_mem_phys_addr = phys_addr;
  8201. + mm_vc_mem_size = mem_size;
  8202. + mm_vc_mem_base = mem_base;
  8203. +
  8204. + vc_mem_get_size();
  8205. +
  8206. + printk("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  8207. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  8208. +
  8209. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  8210. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8211. + goto out_err;
  8212. + }
  8213. +
  8214. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  8215. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  8216. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8217. + goto out_unregister;
  8218. + }
  8219. +
  8220. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  8221. + if (IS_ERR(vc_mem_class)) {
  8222. + rc = PTR_ERR(vc_mem_class);
  8223. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8224. + goto out_cdev_del;
  8225. + }
  8226. +
  8227. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  8228. + DRIVER_NAME);
  8229. + if (IS_ERR(dev)) {
  8230. + rc = PTR_ERR(dev);
  8231. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8232. + goto out_class_destroy;
  8233. + }
  8234. +
  8235. +#if 0
  8236. + vc_mem_proc_entry = create_proc_entry(DRIVER_NAME, 0444, NULL);
  8237. + if (vc_mem_proc_entry == NULL) {
  8238. + rc = -EFAULT;
  8239. + LOG_ERR("%s: create_proc_entry failed", __func__);
  8240. + goto out_device_destroy;
  8241. + }
  8242. + vc_mem_proc_entry->read_proc = vc_mem_proc_read;
  8243. + vc_mem_proc_entry->write_proc = vc_mem_proc_write;
  8244. +#endif
  8245. +
  8246. + vc_mem_inited = 1;
  8247. + return 0;
  8248. +
  8249. + out_device_destroy:
  8250. + device_destroy(vc_mem_class, vc_mem_devnum);
  8251. +
  8252. + out_class_destroy:
  8253. + class_destroy(vc_mem_class);
  8254. + vc_mem_class = NULL;
  8255. +
  8256. + out_cdev_del:
  8257. + cdev_del(&vc_mem_cdev);
  8258. +
  8259. + out_unregister:
  8260. + unregister_chrdev_region(vc_mem_devnum, 1);
  8261. +
  8262. + out_err:
  8263. + return -1;
  8264. +}
  8265. +
  8266. +/****************************************************************************
  8267. +*
  8268. +* vc_mem_exit
  8269. +*
  8270. +***************************************************************************/
  8271. +
  8272. +static void __exit
  8273. +vc_mem_exit(void)
  8274. +{
  8275. + LOG_DBG("%s: called", __func__);
  8276. +
  8277. + if (vc_mem_inited) {
  8278. +#if 0
  8279. + remove_proc_entry(vc_mem_proc_entry->name, NULL);
  8280. +#endif
  8281. + device_destroy(vc_mem_class, vc_mem_devnum);
  8282. + class_destroy(vc_mem_class);
  8283. + cdev_del(&vc_mem_cdev);
  8284. + unregister_chrdev_region(vc_mem_devnum, 1);
  8285. + }
  8286. +}
  8287. +
  8288. +module_init(vc_mem_init);
  8289. +module_exit(vc_mem_exit);
  8290. +MODULE_LICENSE("GPL");
  8291. +MODULE_AUTHOR("Broadcom Corporation");
  8292. +
  8293. +module_param(phys_addr, uint, 0644);
  8294. +module_param(mem_size, uint, 0644);
  8295. +module_param(mem_base, uint, 0644);
  8296. +
  8297. diff -Nur linux-3.11.10.orig/arch/arm/mach-bcm2708/vc_support.c linux-3.11.10/arch/arm/mach-bcm2708/vc_support.c
  8298. --- linux-3.11.10.orig/arch/arm/mach-bcm2708/vc_support.c 1970-01-01 01:00:00.000000000 +0100
  8299. +++ linux-3.11.10/arch/arm/mach-bcm2708/vc_support.c 2014-02-07 19:57:28.000000000 +0100
  8300. @@ -0,0 +1,318 @@
  8301. +/*
  8302. + * vc_support.c
  8303. + *
  8304. + * Created on: 25 Nov 2012
  8305. + * Author: Simon
  8306. + */
  8307. +
  8308. +#include <linux/module.h>
  8309. +#include <mach/vcio.h>
  8310. +
  8311. +#ifdef ECLIPSE_IGNORE
  8312. +
  8313. +#define __user
  8314. +#define __init
  8315. +#define __exit
  8316. +#define __iomem
  8317. +#define KERN_DEBUG
  8318. +#define KERN_ERR
  8319. +#define KERN_WARNING
  8320. +#define KERN_INFO
  8321. +#define _IOWR(a, b, c) b
  8322. +#define _IOW(a, b, c) b
  8323. +#define _IO(a, b) b
  8324. +
  8325. +#endif
  8326. +
  8327. +/****** VC MAILBOX FUNCTIONALITY ******/
  8328. +unsigned int AllocateVcMemory(unsigned int *pHandle, unsigned int size, unsigned int alignment, unsigned int flags)
  8329. +{
  8330. + struct vc_msg
  8331. + {
  8332. + unsigned int m_msgSize;
  8333. + unsigned int m_response;
  8334. +
  8335. + struct vc_tag
  8336. + {
  8337. + unsigned int m_tagId;
  8338. + unsigned int m_sendBufferSize;
  8339. + union {
  8340. + unsigned int m_sendDataSize;
  8341. + unsigned int m_recvDataSize;
  8342. + };
  8343. +
  8344. + struct args
  8345. + {
  8346. + union {
  8347. + unsigned int m_size;
  8348. + unsigned int m_handle;
  8349. + };
  8350. + unsigned int m_alignment;
  8351. + unsigned int m_flags;
  8352. + } m_args;
  8353. + } m_tag;
  8354. +
  8355. + unsigned int m_endTag;
  8356. + } msg;
  8357. + int s;
  8358. +
  8359. + msg.m_msgSize = sizeof(msg);
  8360. + msg.m_response = 0;
  8361. + msg.m_endTag = 0;
  8362. +
  8363. + //fill in the tag for the allocation command
  8364. + msg.m_tag.m_tagId = 0x3000c;
  8365. + msg.m_tag.m_sendBufferSize = 12;
  8366. + msg.m_tag.m_sendDataSize = 12;
  8367. +
  8368. + //fill in our args
  8369. + msg.m_tag.m_args.m_size = size;
  8370. + msg.m_tag.m_args.m_alignment = alignment;
  8371. + msg.m_tag.m_args.m_flags = flags;
  8372. +
  8373. + //run the command
  8374. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8375. +
  8376. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8377. + {
  8378. + *pHandle = msg.m_tag.m_args.m_handle;
  8379. + return 0;
  8380. + }
  8381. + else
  8382. + {
  8383. + printk(KERN_ERR "failed to allocate vc memory: s=%d response=%08x recv data size=%08x\n",
  8384. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8385. + return 1;
  8386. + }
  8387. +}
  8388. +
  8389. +unsigned int ReleaseVcMemory(unsigned int handle)
  8390. +{
  8391. + struct vc_msg
  8392. + {
  8393. + unsigned int m_msgSize;
  8394. + unsigned int m_response;
  8395. +
  8396. + struct vc_tag
  8397. + {
  8398. + unsigned int m_tagId;
  8399. + unsigned int m_sendBufferSize;
  8400. + union {
  8401. + unsigned int m_sendDataSize;
  8402. + unsigned int m_recvDataSize;
  8403. + };
  8404. +
  8405. + struct args
  8406. + {
  8407. + union {
  8408. + unsigned int m_handle;
  8409. + unsigned int m_error;
  8410. + };
  8411. + } m_args;
  8412. + } m_tag;
  8413. +
  8414. + unsigned int m_endTag;
  8415. + } msg;
  8416. + int s;
  8417. +
  8418. + msg.m_msgSize = sizeof(msg);
  8419. + msg.m_response = 0;
  8420. + msg.m_endTag = 0;
  8421. +
  8422. + //fill in the tag for the release command
  8423. + msg.m_tag.m_tagId = 0x3000f;
  8424. + msg.m_tag.m_sendBufferSize = 4;
  8425. + msg.m_tag.m_sendDataSize = 4;
  8426. +
  8427. + //pass across the handle
  8428. + msg.m_tag.m_args.m_handle = handle;
  8429. +
  8430. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8431. +
  8432. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8433. + return 0;
  8434. + else
  8435. + {
  8436. + printk(KERN_ERR "failed to release vc memory: s=%d response=%08x recv data size=%08x error=%08x\n",
  8437. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8438. + return 1;
  8439. + }
  8440. +}
  8441. +
  8442. +unsigned int LockVcMemory(unsigned int *pBusAddress, unsigned int handle)
  8443. +{
  8444. + struct vc_msg
  8445. + {
  8446. + unsigned int m_msgSize;
  8447. + unsigned int m_response;
  8448. +
  8449. + struct vc_tag
  8450. + {
  8451. + unsigned int m_tagId;
  8452. + unsigned int m_sendBufferSize;
  8453. + union {
  8454. + unsigned int m_sendDataSize;
  8455. + unsigned int m_recvDataSize;
  8456. + };
  8457. +
  8458. + struct args
  8459. + {
  8460. + union {
  8461. + unsigned int m_handle;
  8462. + unsigned int m_busAddress;
  8463. + };
  8464. + } m_args;
  8465. + } m_tag;
  8466. +
  8467. + unsigned int m_endTag;
  8468. + } msg;
  8469. + int s;
  8470. +
  8471. + msg.m_msgSize = sizeof(msg);
  8472. + msg.m_response = 0;
  8473. + msg.m_endTag = 0;
  8474. +
  8475. + //fill in the tag for the lock command
  8476. + msg.m_tag.m_tagId = 0x3000d;
  8477. + msg.m_tag.m_sendBufferSize = 4;
  8478. + msg.m_tag.m_sendDataSize = 4;
  8479. +
  8480. + //pass across the handle
  8481. + msg.m_tag.m_args.m_handle = handle;
  8482. +
  8483. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8484. +
  8485. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8486. + {
  8487. + //pick out the bus address
  8488. + *pBusAddress = msg.m_tag.m_args.m_busAddress;
  8489. + return 0;
  8490. + }
  8491. + else
  8492. + {
  8493. + printk(KERN_ERR "failed to lock vc memory: s=%d response=%08x recv data size=%08x\n",
  8494. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8495. + return 1;
  8496. + }
  8497. +}
  8498. +
  8499. +unsigned int UnlockVcMemory(unsigned int handle)
  8500. +{
  8501. + struct vc_msg
  8502. + {
  8503. + unsigned int m_msgSize;
  8504. + unsigned int m_response;
  8505. +
  8506. + struct vc_tag
  8507. + {
  8508. + unsigned int m_tagId;
  8509. + unsigned int m_sendBufferSize;
  8510. + union {
  8511. + unsigned int m_sendDataSize;
  8512. + unsigned int m_recvDataSize;
  8513. + };
  8514. +
  8515. + struct args
  8516. + {
  8517. + union {
  8518. + unsigned int m_handle;
  8519. + unsigned int m_error;
  8520. + };
  8521. + } m_args;
  8522. + } m_tag;
  8523. +
  8524. + unsigned int m_endTag;
  8525. + } msg;
  8526. + int s;
  8527. +
  8528. + msg.m_msgSize = sizeof(msg);
  8529. + msg.m_response = 0;
  8530. + msg.m_endTag = 0;
  8531. +
  8532. + //fill in the tag for the unlock command
  8533. + msg.m_tag.m_tagId = 0x3000e;
  8534. + msg.m_tag.m_sendBufferSize = 4;
  8535. + msg.m_tag.m_sendDataSize = 4;
  8536. +
  8537. + //pass across the handle
  8538. + msg.m_tag.m_args.m_handle = handle;
  8539. +
  8540. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8541. +
  8542. + //check the error code too
  8543. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004 && msg.m_tag.m_args.m_error == 0)
  8544. + return 0;
  8545. + else
  8546. + {
  8547. + printk(KERN_ERR "failed to unlock vc memory: s=%d response=%08x recv data size=%08x error%08x\n",
  8548. + s, msg.m_response, msg.m_tag.m_recvDataSize, msg.m_tag.m_args.m_error);
  8549. + return 1;
  8550. + }
  8551. +}
  8552. +
  8553. +unsigned int ExecuteVcCode(unsigned int code,
  8554. + unsigned int r0, unsigned int r1, unsigned int r2, unsigned int r3, unsigned int r4, unsigned int r5)
  8555. +{
  8556. + struct vc_msg
  8557. + {
  8558. + unsigned int m_msgSize;
  8559. + unsigned int m_response;
  8560. +
  8561. + struct vc_tag
  8562. + {
  8563. + unsigned int m_tagId;
  8564. + unsigned int m_sendBufferSize;
  8565. + union {
  8566. + unsigned int m_sendDataSize;
  8567. + unsigned int m_recvDataSize;
  8568. + };
  8569. +
  8570. + struct args
  8571. + {
  8572. + union {
  8573. + unsigned int m_pCode;
  8574. + unsigned int m_return;
  8575. + };
  8576. + unsigned int m_r0;
  8577. + unsigned int m_r1;
  8578. + unsigned int m_r2;
  8579. + unsigned int m_r3;
  8580. + unsigned int m_r4;
  8581. + unsigned int m_r5;
  8582. + } m_args;
  8583. + } m_tag;
  8584. +
  8585. + unsigned int m_endTag;
  8586. + } msg;
  8587. + int s;
  8588. +
  8589. + msg.m_msgSize = sizeof(msg);
  8590. + msg.m_response = 0;
  8591. + msg.m_endTag = 0;
  8592. +
  8593. + //fill in the tag for the unlock command
  8594. + msg.m_tag.m_tagId = 0x30010;
  8595. + msg.m_tag.m_sendBufferSize = 28;
  8596. + msg.m_tag.m_sendDataSize = 28;
  8597. +
  8598. + //pass across the handle
  8599. + msg.m_tag.m_args.m_pCode = code;
  8600. + msg.m_tag.m_args.m_r0 = r0;
  8601. + msg.m_tag.m_args.m_r1 = r1;
  8602. + msg.m_tag.m_args.m_r2 = r2;
  8603. + msg.m_tag.m_args.m_r3 = r3;
  8604. + msg.m_tag.m_args.m_r4 = r4;
  8605. + msg.m_tag.m_args.m_r5 = r5;
  8606. +
  8607. + s = bcm_mailbox_property(&msg, sizeof(msg));
  8608. +
  8609. + //check the error code too
  8610. + if (s == 0 && msg.m_response == 0x80000000 && msg.m_tag.m_recvDataSize == 0x80000004)
  8611. + return msg.m_tag.m_args.m_return;
  8612. + else
  8613. + {
  8614. + printk(KERN_ERR "failed to execute: s=%d response=%08x recv data size=%08x\n",
  8615. + s, msg.m_response, msg.m_tag.m_recvDataSize);
  8616. + return 1;
  8617. + }
  8618. +}
  8619. diff -Nur linux-3.11.10.orig/arch/arm/Makefile linux-3.11.10/arch/arm/Makefile
  8620. --- linux-3.11.10.orig/arch/arm/Makefile 2013-11-29 19:42:37.000000000 +0100
  8621. +++ linux-3.11.10/arch/arm/Makefile 2014-02-07 19:57:28.000000000 +0100
  8622. @@ -146,6 +146,7 @@
  8623. # by CONFIG_* macro name.
  8624. machine-$(CONFIG_ARCH_AT91) += at91
  8625. machine-$(CONFIG_ARCH_BCM) += bcm
  8626. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  8627. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  8628. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  8629. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  8630. diff -Nur linux-3.11.10.orig/arch/arm/mm/Kconfig linux-3.11.10/arch/arm/mm/Kconfig
  8631. --- linux-3.11.10.orig/arch/arm/mm/Kconfig 2013-11-29 19:42:37.000000000 +0100
  8632. +++ linux-3.11.10/arch/arm/mm/Kconfig 2014-02-07 19:57:28.000000000 +0100
  8633. @@ -358,7 +358,7 @@
  8634. # ARMv6
  8635. config CPU_V6
  8636. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  8637. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  8638. select CPU_32v6
  8639. select CPU_ABRT_EV6
  8640. select CPU_CACHE_V6
  8641. diff -Nur linux-3.11.10.orig/arch/arm/mm/proc-v6.S linux-3.11.10/arch/arm/mm/proc-v6.S
  8642. --- linux-3.11.10.orig/arch/arm/mm/proc-v6.S 2013-11-29 19:42:37.000000000 +0100
  8643. +++ linux-3.11.10/arch/arm/mm/proc-v6.S 2014-02-07 19:57:28.000000000 +0100
  8644. @@ -73,10 +73,19 @@
  8645. *
  8646. * IRQs are already disabled.
  8647. */
  8648. +
  8649. +/* See jira SW-5991 for details of this workaround */
  8650. ENTRY(cpu_v6_do_idle)
  8651. - mov r1, #0
  8652. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8653. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8654. + .align 5
  8655. + mov r1, #2
  8656. +1: subs r1, #1
  8657. + nop
  8658. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  8659. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  8660. + nop
  8661. + nop
  8662. + nop
  8663. + bne 1b
  8664. mov pc, lr
  8665. ENTRY(cpu_v6_dcache_clean_area)
  8666. diff -Nur linux-3.11.10.orig/arch/arm/tools/mach-types linux-3.11.10/arch/arm/tools/mach-types
  8667. --- linux-3.11.10.orig/arch/arm/tools/mach-types 2013-11-29 19:42:37.000000000 +0100
  8668. +++ linux-3.11.10/arch/arm/tools/mach-types 2014-02-07 19:57:28.000000000 +0100
  8669. @@ -522,6 +522,7 @@
  8670. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  8671. paz00 MACH_PAZ00 PAZ00 3128
  8672. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  8673. +bcm2708 MACH_BCM2708 BCM2708 3138
  8674. ag5evm MACH_AG5EVM AG5EVM 3189
  8675. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  8676. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  8677. diff -Nur linux-3.11.10.orig/drivers/char/broadcom/Kconfig linux-3.11.10/drivers/char/broadcom/Kconfig
  8678. --- linux-3.11.10.orig/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  8679. +++ linux-3.11.10/drivers/char/broadcom/Kconfig 2014-02-07 19:57:28.000000000 +0100
  8680. @@ -0,0 +1,16 @@
  8681. +#
  8682. +# Broadcom char driver config
  8683. +#
  8684. +
  8685. +menuconfig BRCM_CHAR_DRIVERS
  8686. + bool "Broadcom Char Drivers"
  8687. + help
  8688. + Broadcom's char drivers
  8689. +
  8690. +config BCM_VC_CMA
  8691. + bool "Videocore CMA"
  8692. + depends on CMA && BRCM_CHAR_DRIVERS
  8693. + default n
  8694. + help
  8695. + Helper for videocore CMA access.
  8696. +
  8697. diff -Nur linux-3.11.10.orig/drivers/char/broadcom/Makefile linux-3.11.10/drivers/char/broadcom/Makefile
  8698. --- linux-3.11.10.orig/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  8699. +++ linux-3.11.10/drivers/char/broadcom/Makefile 2014-02-07 19:57:28.000000000 +0100
  8700. @@ -0,0 +1 @@
  8701. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  8702. diff -Nur linux-3.11.10.orig/drivers/char/broadcom/vc_cma/Makefile linux-3.11.10/drivers/char/broadcom/vc_cma/Makefile
  8703. --- linux-3.11.10.orig/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  8704. +++ linux-3.11.10/drivers/char/broadcom/vc_cma/Makefile 2014-02-07 19:57:28.000000000 +0100
  8705. @@ -0,0 +1,14 @@
  8706. +EXTRA_CFLAGS += -Wall -Wstrict-prototypes -Wno-trigraphs
  8707. +EXTRA_CFLAGS += -Werror
  8708. +EXTRA_CFLAGS += -I"include/linux/broadcom"
  8709. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services"
  8710. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchi"
  8711. +EXTRA_CFLAGS += -I"drivers/misc/vc04_services/interface/vchiq_arm"
  8712. +
  8713. +EXTRA_CFLAGS += -D__KERNEL__
  8714. +EXTRA_CFLAGS += -D__linux__
  8715. +EXTRA_CFLAGS += -Werror
  8716. +
  8717. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  8718. +
  8719. +vc-cma-objs := vc_cma.o
  8720. diff -Nur linux-3.11.10.orig/drivers/char/broadcom/vc_cma/vc_cma.c linux-3.11.10/drivers/char/broadcom/vc_cma/vc_cma.c
  8721. --- linux-3.11.10.orig/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  8722. +++ linux-3.11.10/drivers/char/broadcom/vc_cma/vc_cma.c 2014-02-07 19:57:28.000000000 +0100
  8723. @@ -0,0 +1,1143 @@
  8724. +/**
  8725. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8726. + *
  8727. + * Redistribution and use in source and binary forms, with or without
  8728. + * modification, are permitted provided that the following conditions
  8729. + * are met:
  8730. + * 1. Redistributions of source code must retain the above copyright
  8731. + * notice, this list of conditions, and the following disclaimer,
  8732. + * without modification.
  8733. + * 2. Redistributions in binary form must reproduce the above copyright
  8734. + * notice, this list of conditions and the following disclaimer in the
  8735. + * documentation and/or other materials provided with the distribution.
  8736. + * 3. The names of the above-listed copyright holders may not be used
  8737. + * to endorse or promote products derived from this software without
  8738. + * specific prior written permission.
  8739. + *
  8740. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8741. + * GNU General Public License ("GPL") version 2, as published by the Free
  8742. + * Software Foundation.
  8743. + *
  8744. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8745. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8746. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8747. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8748. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8749. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8750. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8751. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8752. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8753. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8754. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8755. + */
  8756. +
  8757. +#include <linux/kernel.h>
  8758. +#include <linux/module.h>
  8759. +#include <linux/kthread.h>
  8760. +#include <linux/fs.h>
  8761. +#include <linux/device.h>
  8762. +#include <linux/cdev.h>
  8763. +#include <linux/mm.h>
  8764. +#include <linux/proc_fs.h>
  8765. +#include <linux/seq_file.h>
  8766. +#include <linux/dma-mapping.h>
  8767. +#include <linux/dma-contiguous.h>
  8768. +#include <linux/platform_device.h>
  8769. +#include <linux/uaccess.h>
  8770. +#include <asm/cacheflush.h>
  8771. +
  8772. +#include "vc_cma.h"
  8773. +
  8774. +#include "vchiq_util.h"
  8775. +#include "vchiq_connected.h"
  8776. +//#include "debug_sym.h"
  8777. +//#include "vc_mem.h"
  8778. +
  8779. +#define DRIVER_NAME "vc-cma"
  8780. +
  8781. +#define LOG_DBG(fmt, ...) \
  8782. + if (vc_cma_debug) \
  8783. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  8784. +#define LOG_ERR(fmt, ...) \
  8785. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  8786. +
  8787. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  8788. +#define VC_CMA_VERSION 2
  8789. +
  8790. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  8791. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  8792. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  8793. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  8794. +#define VC_CMA_RESERVE_COUNT_MAX 16
  8795. +
  8796. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  8797. +
  8798. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  8799. +
  8800. +#define loud_error(...) \
  8801. + LOG_ERR("===== " __VA_ARGS__)
  8802. +
  8803. +enum {
  8804. + VC_CMA_MSG_QUIT,
  8805. + VC_CMA_MSG_OPEN,
  8806. + VC_CMA_MSG_TICK,
  8807. + VC_CMA_MSG_ALLOC, /* chunk count */
  8808. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  8809. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  8810. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  8811. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  8812. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  8813. + VC_CMA_MSG_UPDATE_RESERVE,
  8814. + VC_CMA_MSG_MAX
  8815. +};
  8816. +
  8817. +struct cma_msg {
  8818. + unsigned short type;
  8819. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  8820. +};
  8821. +
  8822. +struct vc_cma_reserve_user {
  8823. + unsigned int pid;
  8824. + unsigned int reserve;
  8825. +};
  8826. +
  8827. +/* Device (/dev) related variables */
  8828. +static dev_t vc_cma_devnum;
  8829. +static struct class *vc_cma_class;
  8830. +static struct cdev vc_cma_cdev;
  8831. +static int vc_cma_inited;
  8832. +static int vc_cma_debug;
  8833. +
  8834. +/* Proc entry */
  8835. +static struct proc_dir_entry *vc_cma_proc_entry;
  8836. +
  8837. +phys_addr_t vc_cma_base;
  8838. +struct page *vc_cma_base_page;
  8839. +unsigned int vc_cma_size;
  8840. +EXPORT_SYMBOL(vc_cma_size);
  8841. +unsigned int vc_cma_initial;
  8842. +unsigned int vc_cma_chunks;
  8843. +unsigned int vc_cma_chunks_used;
  8844. +unsigned int vc_cma_chunks_reserved;
  8845. +
  8846. +static int in_loud_error;
  8847. +
  8848. +unsigned int vc_cma_reserve_total;
  8849. +unsigned int vc_cma_reserve_count;
  8850. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  8851. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  8852. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  8853. +
  8854. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  8855. +static struct platform_device vc_cma_device = {
  8856. + .name = "vc-cma",
  8857. + .id = 0,
  8858. + .dev = {
  8859. + .dma_mask = &vc_cma_dma_mask,
  8860. + .coherent_dma_mask = DMA_BIT_MASK(32),
  8861. + },
  8862. +};
  8863. +
  8864. +static VCHIQ_INSTANCE_T cma_instance;
  8865. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  8866. +static VCHIU_QUEUE_T cma_msg_queue;
  8867. +static struct task_struct *cma_worker;
  8868. +
  8869. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  8870. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  8871. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8872. + VCHIQ_HEADER_T * header,
  8873. + VCHIQ_SERVICE_HANDLE_T service,
  8874. + void *bulk_userdata);
  8875. +static void send_vc_msg(unsigned short type,
  8876. + unsigned short param1, unsigned short param2);
  8877. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  8878. +
  8879. +static int early_vc_cma_mem(char *p)
  8880. +{
  8881. + unsigned int new_size;
  8882. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  8883. + vc_cma_size = memparse(p, &p);
  8884. + vc_cma_initial = vc_cma_size;
  8885. + if (*p == '/')
  8886. + vc_cma_size = memparse(p + 1, &p);
  8887. + if (*p == '@')
  8888. + vc_cma_base = memparse(p + 1, &p);
  8889. +
  8890. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  8891. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8892. + if (new_size > vc_cma_size)
  8893. + vc_cma_size = 0;
  8894. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  8895. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8896. + if (vc_cma_initial > vc_cma_size)
  8897. + vc_cma_initial = vc_cma_size;
  8898. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  8899. + & ~(VC_CMA_CHUNK_SIZE - 1);
  8900. +
  8901. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  8902. + vc_cma_size, (unsigned int)vc_cma_base);
  8903. +
  8904. + return 0;
  8905. +}
  8906. +
  8907. +early_param("vc-cma-mem", early_vc_cma_mem);
  8908. +
  8909. +void vc_cma_early_init(void)
  8910. +{
  8911. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  8912. + if (vc_cma_size) {
  8913. + int rc = platform_device_register(&vc_cma_device);
  8914. + LOG_DBG("platform_device_register -> %d", rc);
  8915. + }
  8916. +}
  8917. +
  8918. +void vc_cma_reserve(void)
  8919. +{
  8920. + /* if vc_cma_size is set, then declare vc CMA area of the same
  8921. + * size from the end of memory
  8922. + */
  8923. + if (vc_cma_size) {
  8924. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  8925. + vc_cma_base, 0) == 0) {
  8926. + } else {
  8927. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  8928. + vc_cma_size, (unsigned int)vc_cma_base);
  8929. + vc_cma_size = 0;
  8930. + }
  8931. + }
  8932. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  8933. +}
  8934. +
  8935. +/****************************************************************************
  8936. +*
  8937. +* vc_cma_open
  8938. +*
  8939. +***************************************************************************/
  8940. +
  8941. +static int vc_cma_open(struct inode *inode, struct file *file)
  8942. +{
  8943. + (void)inode;
  8944. + (void)file;
  8945. +
  8946. + return 0;
  8947. +}
  8948. +
  8949. +/****************************************************************************
  8950. +*
  8951. +* vc_cma_release
  8952. +*
  8953. +***************************************************************************/
  8954. +
  8955. +static int vc_cma_release(struct inode *inode, struct file *file)
  8956. +{
  8957. + (void)inode;
  8958. + (void)file;
  8959. +
  8960. + vc_cma_set_reserve(0, current->tgid);
  8961. +
  8962. + return 0;
  8963. +}
  8964. +
  8965. +/****************************************************************************
  8966. +*
  8967. +* vc_cma_ioctl
  8968. +*
  8969. +***************************************************************************/
  8970. +
  8971. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8972. +{
  8973. + int rc = 0;
  8974. +
  8975. + (void)cmd;
  8976. + (void)arg;
  8977. +
  8978. + switch (cmd) {
  8979. + case VC_CMA_IOC_RESERVE:
  8980. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  8981. + if (rc >= 0)
  8982. + rc = 0;
  8983. + break;
  8984. + default:
  8985. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  8986. + return -ENOTTY;
  8987. + }
  8988. +
  8989. + return rc;
  8990. +}
  8991. +
  8992. +/****************************************************************************
  8993. +*
  8994. +* File Operations for the driver.
  8995. +*
  8996. +***************************************************************************/
  8997. +
  8998. +static const struct file_operations vc_cma_fops = {
  8999. + .owner = THIS_MODULE,
  9000. + .open = vc_cma_open,
  9001. + .release = vc_cma_release,
  9002. + .unlocked_ioctl = vc_cma_ioctl,
  9003. +};
  9004. +
  9005. +/****************************************************************************
  9006. +*
  9007. +* vc_cma_proc_open
  9008. +*
  9009. +***************************************************************************/
  9010. +
  9011. +static int vc_cma_show_info(struct seq_file *m, void *v)
  9012. +{
  9013. + int i;
  9014. +
  9015. + seq_printf(m, "Videocore CMA:\n");
  9016. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  9017. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  9018. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  9019. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  9020. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  9021. + (int)vc_cma_chunks,
  9022. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  9023. + seq_printf(m, " Used : %4d (%d bytes)\n",
  9024. + (int)vc_cma_chunks_used,
  9025. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  9026. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  9027. + (unsigned int)vc_cma_chunks_reserved,
  9028. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  9029. +
  9030. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9031. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  9032. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  9033. + user->reserve);
  9034. + }
  9035. +
  9036. + seq_printf(m, "\n");
  9037. +
  9038. + return 0;
  9039. +}
  9040. +
  9041. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  9042. +{
  9043. + return single_open(file, vc_cma_show_info, NULL);
  9044. +}
  9045. +
  9046. +/****************************************************************************
  9047. +*
  9048. +* vc_cma_proc_write
  9049. +*
  9050. +***************************************************************************/
  9051. +
  9052. +static int vc_cma_proc_write(struct file *file,
  9053. + const char __user *buffer,
  9054. + size_t size, loff_t *ppos)
  9055. +{
  9056. + int rc = -EFAULT;
  9057. + char input_str[20];
  9058. +
  9059. + memset(input_str, 0, sizeof(input_str));
  9060. +
  9061. + if (size > sizeof(input_str)) {
  9062. + LOG_ERR("%s: input string length too long", __func__);
  9063. + goto out;
  9064. + }
  9065. +
  9066. + if (copy_from_user(input_str, buffer, size - 1)) {
  9067. + LOG_ERR("%s: failed to get input string", __func__);
  9068. + goto out;
  9069. + }
  9070. +#define ALLOC_STR "alloc"
  9071. +#define FREE_STR "free"
  9072. +#define DEBUG_STR "debug"
  9073. +#define RESERVE_STR "reserve"
  9074. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  9075. + int size;
  9076. + char *p = input_str + strlen(ALLOC_STR);
  9077. +
  9078. + while (*p == ' ')
  9079. + p++;
  9080. + size = memparse(p, NULL);
  9081. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  9082. + if (size)
  9083. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  9084. + size / VC_CMA_CHUNK_SIZE, 0);
  9085. + else
  9086. + LOG_ERR("invalid size '%s'", p);
  9087. + rc = size;
  9088. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  9089. + int size;
  9090. + char *p = input_str + strlen(FREE_STR);
  9091. +
  9092. + while (*p == ' ')
  9093. + p++;
  9094. + size = memparse(p, NULL);
  9095. + LOG_ERR("/proc/vc-cma: free %d", size);
  9096. + if (size)
  9097. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  9098. + size / VC_CMA_CHUNK_SIZE, 0);
  9099. + else
  9100. + LOG_ERR("invalid size '%s'", p);
  9101. + rc = size;
  9102. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  9103. + char *p = input_str + strlen(DEBUG_STR);
  9104. + while (*p == ' ')
  9105. + p++;
  9106. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  9107. + vc_cma_debug = 1;
  9108. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  9109. + vc_cma_debug = 0;
  9110. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  9111. + rc = size;
  9112. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  9113. + int size;
  9114. + int reserved;
  9115. + char *p = input_str + strlen(RESERVE_STR);
  9116. + while (*p == ' ')
  9117. + p++;
  9118. + size = memparse(p, NULL);
  9119. +
  9120. + reserved = vc_cma_set_reserve(size, current->tgid);
  9121. + rc = (reserved >= 0) ? size : reserved;
  9122. + }
  9123. +
  9124. +out:
  9125. + return rc;
  9126. +}
  9127. +
  9128. +/****************************************************************************
  9129. +*
  9130. +* File Operations for /proc interface.
  9131. +*
  9132. +***************************************************************************/
  9133. +
  9134. +static const struct file_operations vc_cma_proc_fops = {
  9135. + .open = vc_cma_proc_open,
  9136. + .read = seq_read,
  9137. + .write = vc_cma_proc_write,
  9138. + .llseek = seq_lseek,
  9139. + .release = single_release
  9140. +};
  9141. +
  9142. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  9143. +{
  9144. + struct vc_cma_reserve_user *user = NULL;
  9145. + int delta = 0;
  9146. + int i;
  9147. +
  9148. + if (down_interruptible(&vc_cma_reserve_mutex))
  9149. + return -ERESTARTSYS;
  9150. +
  9151. + for (i = 0; i < vc_cma_reserve_count; i++) {
  9152. + if (pid == vc_cma_reserve_users[i].pid) {
  9153. + user = &vc_cma_reserve_users[i];
  9154. + delta = reserve - user->reserve;
  9155. + if (reserve)
  9156. + user->reserve = reserve;
  9157. + else {
  9158. + /* Remove this entry by copying downwards */
  9159. + while ((i + 1) < vc_cma_reserve_count) {
  9160. + user[0].pid = user[1].pid;
  9161. + user[0].reserve = user[1].reserve;
  9162. + user++;
  9163. + i++;
  9164. + }
  9165. + vc_cma_reserve_count--;
  9166. + user = NULL;
  9167. + }
  9168. + break;
  9169. + }
  9170. + }
  9171. +
  9172. + if (reserve && !user) {
  9173. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  9174. + LOG_ERR("vc-cma: Too many reservations - "
  9175. + "increase CMA_RESERVE_COUNT_MAX");
  9176. + up(&vc_cma_reserve_mutex);
  9177. + return -EBUSY;
  9178. + }
  9179. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  9180. + user->pid = pid;
  9181. + user->reserve = reserve;
  9182. + delta = reserve;
  9183. + vc_cma_reserve_count++;
  9184. + }
  9185. +
  9186. + vc_cma_reserve_total += delta;
  9187. +
  9188. + send_vc_msg(VC_CMA_MSG_RESERVE,
  9189. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  9190. +
  9191. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  9192. +
  9193. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  9194. + reserve, pid, vc_cma_reserve_total);
  9195. +
  9196. + up(&vc_cma_reserve_mutex);
  9197. +
  9198. + return vc_cma_reserve_total;
  9199. +}
  9200. +
  9201. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  9202. + VCHIQ_HEADER_T * header,
  9203. + VCHIQ_SERVICE_HANDLE_T service,
  9204. + void *bulk_userdata)
  9205. +{
  9206. + switch (reason) {
  9207. + case VCHIQ_MESSAGE_AVAILABLE:
  9208. + if (!send_worker_msg(header))
  9209. + return VCHIQ_RETRY;
  9210. + break;
  9211. + case VCHIQ_SERVICE_CLOSED:
  9212. + LOG_DBG("CMA service closed");
  9213. + break;
  9214. + default:
  9215. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  9216. + break;
  9217. + }
  9218. + return VCHIQ_SUCCESS;
  9219. +}
  9220. +
  9221. +static void send_vc_msg(unsigned short type,
  9222. + unsigned short param1, unsigned short param2)
  9223. +{
  9224. + unsigned short msg[] = { type, param1, param2 };
  9225. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  9226. + VCHIQ_STATUS_T ret;
  9227. + vchiq_use_service(cma_service);
  9228. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9229. + vchiq_release_service(cma_service);
  9230. + if (ret != VCHIQ_SUCCESS)
  9231. + LOG_ERR("vchiq_queue_message returned %x", ret);
  9232. +}
  9233. +
  9234. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  9235. +{
  9236. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  9237. + return false;
  9238. + vchiu_queue_push(&cma_msg_queue, msg);
  9239. + up(&vc_cma_worker_queue_push_mutex);
  9240. + return true;
  9241. +}
  9242. +
  9243. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  9244. +{
  9245. + int i;
  9246. + for (i = 0; i < num_chunks; i++) {
  9247. + struct page *chunk;
  9248. + unsigned int chunk_num;
  9249. + uint8_t *chunk_addr;
  9250. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  9251. +
  9252. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9253. + PAGES_PER_CHUNK,
  9254. + VC_CMA_CHUNK_ORDER);
  9255. + if (!chunk)
  9256. + break;
  9257. +
  9258. + chunk_addr = page_address(chunk);
  9259. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  9260. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  9261. + chunk_size);
  9262. +
  9263. + chunk_num =
  9264. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  9265. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9266. + VC_CMA_CHUNK_SIZE) != 0);
  9267. + if (chunk_num >= vc_cma_chunks) {
  9268. + LOG_ERR("%s: ===============================",
  9269. + __func__);
  9270. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  9271. + "bad SPARSEMEM configuration?",
  9272. + __func__, (unsigned int)page_to_phys(chunk),
  9273. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  9274. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  9275. + vc_cma_device.dev.cma_area);
  9276. + LOG_ERR("%s: ===============================",
  9277. + __func__);
  9278. + break;
  9279. + }
  9280. + reply->params[i] = chunk_num;
  9281. + vc_cma_chunks_used++;
  9282. + }
  9283. +
  9284. + if (i < num_chunks) {
  9285. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  9286. + "for %x bytes (alloc %d of %d, %d free)",
  9287. + __func__, VC_CMA_CHUNK_SIZE, i,
  9288. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  9289. + num_chunks = i;
  9290. + }
  9291. +
  9292. + LOG_DBG("CMA allocated %d chunks -> %d used",
  9293. + num_chunks, vc_cma_chunks_used);
  9294. + reply->type = VC_CMA_MSG_ALLOCATED;
  9295. +
  9296. + {
  9297. + VCHIQ_ELEMENT_T elem = {
  9298. + reply,
  9299. + offsetof(struct cma_msg, params[0]) +
  9300. + num_chunks * sizeof(reply->params[0])
  9301. + };
  9302. + VCHIQ_STATUS_T ret;
  9303. + vchiq_use_service(cma_service);
  9304. + ret = vchiq_queue_message(cma_service, &elem, 1);
  9305. + vchiq_release_service(cma_service);
  9306. + if (ret != VCHIQ_SUCCESS)
  9307. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  9308. + }
  9309. +
  9310. + return num_chunks;
  9311. +}
  9312. +
  9313. +static int cma_worker_proc(void *param)
  9314. +{
  9315. + static struct cma_msg reply;
  9316. + (void)param;
  9317. +
  9318. + while (1) {
  9319. + VCHIQ_HEADER_T *msg;
  9320. + static struct cma_msg msg_copy;
  9321. + struct cma_msg *cma_msg = &msg_copy;
  9322. + int type, msg_size;
  9323. +
  9324. + msg = vchiu_queue_pop(&cma_msg_queue);
  9325. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  9326. + msg_size = msg->size;
  9327. + memcpy(&msg_copy, msg->data, msg_size);
  9328. + type = cma_msg->type;
  9329. + vchiq_release_message(cma_service, msg);
  9330. + } else {
  9331. + msg_size = 0;
  9332. + type = (int)msg;
  9333. + if (type == VC_CMA_MSG_QUIT)
  9334. + break;
  9335. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  9336. + msg = NULL;
  9337. + cma_msg = NULL;
  9338. + } else {
  9339. + BUG();
  9340. + continue;
  9341. + }
  9342. + }
  9343. +
  9344. + switch (type) {
  9345. + case VC_CMA_MSG_ALLOC:{
  9346. + int num_chunks, free_chunks;
  9347. + num_chunks = cma_msg->params[0];
  9348. + free_chunks =
  9349. + vc_cma_chunks - vc_cma_chunks_used;
  9350. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  9351. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  9352. + LOG_ERR
  9353. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9354. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  9355. + num_chunks,
  9356. + VC_CMA_MAX_PARAMS_PER_MSG);
  9357. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  9358. + }
  9359. +
  9360. + if (num_chunks > free_chunks) {
  9361. + LOG_ERR
  9362. + ("CMA_MSG_ALLOC - chunk count (%d) "
  9363. + "exceeds free chunks (%d)",
  9364. + num_chunks, free_chunks);
  9365. + num_chunks = free_chunks;
  9366. + }
  9367. +
  9368. + vc_cma_alloc_chunks(num_chunks, &reply);
  9369. + }
  9370. + break;
  9371. +
  9372. + case VC_CMA_MSG_FREE:{
  9373. + int chunk_count =
  9374. + (msg_size -
  9375. + offsetof(struct cma_msg,
  9376. + params)) /
  9377. + sizeof(cma_msg->params[0]);
  9378. + int i;
  9379. + BUG_ON(chunk_count <= 0);
  9380. +
  9381. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  9382. + chunk_count, cma_msg->params[0]);
  9383. + for (i = 0; i < chunk_count; i++) {
  9384. + int chunk_num = cma_msg->params[i];
  9385. + struct page *page = vc_cma_base_page +
  9386. + chunk_num * PAGES_PER_CHUNK;
  9387. + if (chunk_num >= vc_cma_chunks) {
  9388. + LOG_ERR
  9389. + ("CMA_MSG_FREE - chunk %d of %d"
  9390. + " (value %x) exceeds maximum "
  9391. + "(%x)", i, chunk_count,
  9392. + chunk_num,
  9393. + vc_cma_chunks - 1);
  9394. + break;
  9395. + }
  9396. +
  9397. + if (!dma_release_from_contiguous
  9398. + (NULL /*&vc_cma_device.dev*/, page,
  9399. + PAGES_PER_CHUNK)) {
  9400. + LOG_ERR
  9401. + ("CMA_MSG_FREE - failed to "
  9402. + "release chunk %d (phys %x, "
  9403. + "page %x)", chunk_num,
  9404. + page_to_phys(page),
  9405. + (unsigned int)page);
  9406. + }
  9407. + vc_cma_chunks_used--;
  9408. + }
  9409. + LOG_DBG("CMA released %d chunks -> %d used",
  9410. + i, vc_cma_chunks_used);
  9411. + }
  9412. + break;
  9413. +
  9414. + case VC_CMA_MSG_UPDATE_RESERVE:{
  9415. + int chunks_needed =
  9416. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  9417. + 1)
  9418. + / VC_CMA_CHUNK_SIZE) -
  9419. + vc_cma_chunks_reserved;
  9420. +
  9421. + LOG_DBG
  9422. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  9423. + chunks_needed);
  9424. +
  9425. + /* Cap the reservations to what is available */
  9426. + if (chunks_needed > 0) {
  9427. + if (chunks_needed >
  9428. + (vc_cma_chunks -
  9429. + vc_cma_chunks_used))
  9430. + chunks_needed =
  9431. + (vc_cma_chunks -
  9432. + vc_cma_chunks_used);
  9433. +
  9434. + chunks_needed =
  9435. + vc_cma_alloc_chunks(chunks_needed,
  9436. + &reply);
  9437. + }
  9438. +
  9439. + LOG_DBG
  9440. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  9441. + chunks_needed);
  9442. + vc_cma_chunks_reserved += chunks_needed;
  9443. + }
  9444. + break;
  9445. +
  9446. + default:
  9447. + LOG_ERR("unexpected msg type %d", type);
  9448. + break;
  9449. + }
  9450. + }
  9451. +
  9452. + LOG_DBG("quitting...");
  9453. + return 0;
  9454. +}
  9455. +
  9456. +/****************************************************************************
  9457. +*
  9458. +* vc_cma_connected_init
  9459. +*
  9460. +* This function is called once the videocore has been connected.
  9461. +*
  9462. +***************************************************************************/
  9463. +
  9464. +static void vc_cma_connected_init(void)
  9465. +{
  9466. + VCHIQ_SERVICE_PARAMS_T service_params;
  9467. +
  9468. + LOG_DBG("vc_cma_connected_init");
  9469. +
  9470. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  9471. + LOG_ERR("could not create CMA msg queue");
  9472. + goto fail_queue;
  9473. + }
  9474. +
  9475. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  9476. + goto fail_vchiq_init;
  9477. +
  9478. + vchiq_connect(cma_instance);
  9479. +
  9480. + service_params.fourcc = VC_CMA_FOURCC;
  9481. + service_params.callback = cma_service_callback;
  9482. + service_params.userdata = NULL;
  9483. + service_params.version = VC_CMA_VERSION;
  9484. + service_params.version_min = VC_CMA_VERSION;
  9485. +
  9486. + if (vchiq_open_service(cma_instance, &service_params,
  9487. + &cma_service) != VCHIQ_SUCCESS) {
  9488. + LOG_ERR("failed to open service - already in use?");
  9489. + goto fail_vchiq_open;
  9490. + }
  9491. +
  9492. + vchiq_release_service(cma_service);
  9493. +
  9494. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  9495. + if (!cma_worker) {
  9496. + LOG_ERR("could not create CMA worker thread");
  9497. + goto fail_worker;
  9498. + }
  9499. + set_user_nice(cma_worker, -20);
  9500. + wake_up_process(cma_worker);
  9501. +
  9502. + return;
  9503. +
  9504. +fail_worker:
  9505. + vchiq_close_service(cma_service);
  9506. +fail_vchiq_open:
  9507. + vchiq_shutdown(cma_instance);
  9508. +fail_vchiq_init:
  9509. + vchiu_queue_delete(&cma_msg_queue);
  9510. +fail_queue:
  9511. + return;
  9512. +}
  9513. +
  9514. +void
  9515. +loud_error_header(void)
  9516. +{
  9517. + if (in_loud_error)
  9518. + return;
  9519. +
  9520. + LOG_ERR("============================================================"
  9521. + "================");
  9522. + LOG_ERR("============================================================"
  9523. + "================");
  9524. + LOG_ERR("=====");
  9525. +
  9526. + in_loud_error = 1;
  9527. +}
  9528. +
  9529. +void
  9530. +loud_error_footer(void)
  9531. +{
  9532. + if (!in_loud_error)
  9533. + return;
  9534. +
  9535. + LOG_ERR("=====");
  9536. + LOG_ERR("============================================================"
  9537. + "================");
  9538. + LOG_ERR("============================================================"
  9539. + "================");
  9540. +
  9541. + in_loud_error = 0;
  9542. +}
  9543. +
  9544. +#if 1
  9545. +static int check_cma_config(void) { return 1; }
  9546. +#else
  9547. +static int
  9548. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  9549. + const char *symbol,
  9550. + void *buf, size_t bufsize)
  9551. +{
  9552. + VC_MEM_ADDR_T vcMemAddr;
  9553. + size_t vcMemSize;
  9554. + uint8_t *mapAddr;
  9555. + off_t vcMapAddr;
  9556. +
  9557. + if (!LookupVideoCoreSymbol(handle, symbol,
  9558. + &vcMemAddr,
  9559. + &vcMemSize)) {
  9560. + loud_error_header();
  9561. + loud_error(
  9562. + "failed to find VC symbol \"%s\".",
  9563. + symbol);
  9564. + loud_error_footer();
  9565. + return 0;
  9566. + }
  9567. +
  9568. + if (vcMemSize != bufsize) {
  9569. + loud_error_header();
  9570. + loud_error(
  9571. + "VC symbol \"%s\" is the wrong size.",
  9572. + symbol);
  9573. + loud_error_footer();
  9574. + return 0;
  9575. + }
  9576. +
  9577. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  9578. + vcMapAddr += mm_vc_mem_phys_addr;
  9579. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  9580. + if (mapAddr == 0) {
  9581. + loud_error_header();
  9582. + loud_error(
  9583. + "failed to ioremap \"%s\" @ 0x%x "
  9584. + "(phys: 0x%x, size: %u).",
  9585. + symbol,
  9586. + (unsigned int)vcMapAddr,
  9587. + (unsigned int)vcMemAddr,
  9588. + (unsigned int)vcMemSize);
  9589. + loud_error_footer();
  9590. + return 0;
  9591. + }
  9592. +
  9593. + memcpy(buf, mapAddr, bufsize);
  9594. + iounmap(mapAddr);
  9595. +
  9596. + return 1;
  9597. +}
  9598. +
  9599. +
  9600. +static int
  9601. +check_cma_config(void)
  9602. +{
  9603. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  9604. + VC_MEM_ADDR_T mempool_start;
  9605. + VC_MEM_ADDR_T mempool_end;
  9606. + VC_MEM_ADDR_T mempool_offline_start;
  9607. + VC_MEM_ADDR_T mempool_offline_end;
  9608. + VC_MEM_ADDR_T cam_alloc_base;
  9609. + VC_MEM_ADDR_T cam_alloc_size;
  9610. + VC_MEM_ADDR_T cam_alloc_end;
  9611. + int success = 0;
  9612. +
  9613. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  9614. + goto out;
  9615. +
  9616. + /* Read the relevant VideoCore variables */
  9617. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  9618. + &mempool_start,
  9619. + sizeof(mempool_start)))
  9620. + goto close;
  9621. +
  9622. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  9623. + &mempool_end,
  9624. + sizeof(mempool_end)))
  9625. + goto close;
  9626. +
  9627. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  9628. + &mempool_offline_start,
  9629. + sizeof(mempool_offline_start)))
  9630. + goto close;
  9631. +
  9632. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  9633. + &mempool_offline_end,
  9634. + sizeof(mempool_offline_end)))
  9635. + goto close;
  9636. +
  9637. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  9638. + &cam_alloc_base,
  9639. + sizeof(cam_alloc_base)))
  9640. + goto close;
  9641. +
  9642. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  9643. + &cam_alloc_size,
  9644. + sizeof(cam_alloc_size)))
  9645. + goto close;
  9646. +
  9647. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  9648. +
  9649. + success = 1;
  9650. +
  9651. + /* Now the sanity checks */
  9652. + if (!mempool_offline_start)
  9653. + mempool_offline_start = mempool_start;
  9654. + if (!mempool_offline_end)
  9655. + mempool_offline_end = mempool_end;
  9656. +
  9657. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  9658. + loud_error_header();
  9659. + loud_error(
  9660. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  9661. + "vc_cma_base(%x)",
  9662. + mempool_offline_start,
  9663. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  9664. + vc_cma_base);
  9665. + success = 0;
  9666. + }
  9667. +
  9668. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  9669. + (vc_cma_base + vc_cma_size)) {
  9670. + loud_error_header();
  9671. + loud_error(
  9672. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  9673. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  9674. + mempool_offline_start,
  9675. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  9676. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  9677. + success = 0;
  9678. + }
  9679. +
  9680. + if (mempool_end < mempool_start) {
  9681. + loud_error_header();
  9682. + loud_error(
  9683. + "__MEMPOOL_END(%x) must not be before "
  9684. + "__MEMPOOL_START(%x)",
  9685. + mempool_end,
  9686. + mempool_start);
  9687. + success = 0;
  9688. + }
  9689. +
  9690. + if (mempool_offline_end < mempool_offline_start) {
  9691. + loud_error_header();
  9692. + loud_error(
  9693. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  9694. + "__MEMPOOL_OFFLINE_START(%x)",
  9695. + mempool_offline_end,
  9696. + mempool_offline_start);
  9697. + success = 0;
  9698. + }
  9699. +
  9700. + if (mempool_offline_start < mempool_start) {
  9701. + loud_error_header();
  9702. + loud_error(
  9703. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  9704. + "__MEMPOOL_START(%x)",
  9705. + mempool_offline_start,
  9706. + mempool_start);
  9707. + success = 0;
  9708. + }
  9709. +
  9710. + if (mempool_offline_end > mempool_end) {
  9711. + loud_error_header();
  9712. + loud_error(
  9713. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  9714. + "__MEMPOOL_END(%x)",
  9715. + mempool_offline_end,
  9716. + mempool_end);
  9717. + success = 0;
  9718. + }
  9719. +
  9720. + if ((cam_alloc_base < mempool_end) &&
  9721. + (cam_alloc_end > mempool_start)) {
  9722. + loud_error_header();
  9723. + loud_error(
  9724. + "cam_alloc pool(%x-%x) overlaps "
  9725. + "mempool(%x-%x)",
  9726. + cam_alloc_base, cam_alloc_end,
  9727. + mempool_start, mempool_end);
  9728. + success = 0;
  9729. + }
  9730. +
  9731. + loud_error_footer();
  9732. +
  9733. +close:
  9734. + CloseVideoCoreMemory(mem_hndl);
  9735. +
  9736. +out:
  9737. + return success;
  9738. +}
  9739. +#endif
  9740. +
  9741. +static int vc_cma_init(void)
  9742. +{
  9743. + int rc = -EFAULT;
  9744. + struct device *dev;
  9745. +
  9746. + if (!check_cma_config())
  9747. + goto out_release;
  9748. +
  9749. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  9750. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  9751. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  9752. + vc_cma_size, vc_cma_size / (1024 * 1024));
  9753. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  9754. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  9755. +
  9756. + vc_cma_base_page = phys_to_page(vc_cma_base);
  9757. +
  9758. + if (vc_cma_chunks) {
  9759. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  9760. +
  9761. + for (vc_cma_chunks_used = 0;
  9762. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  9763. + struct page *chunk;
  9764. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  9765. + PAGES_PER_CHUNK,
  9766. + VC_CMA_CHUNK_ORDER);
  9767. + if (!chunk)
  9768. + break;
  9769. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  9770. + VC_CMA_CHUNK_SIZE) != 0);
  9771. + }
  9772. + if (vc_cma_chunks_used != chunks_needed) {
  9773. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  9774. + "bytes, allocation %d of %d)",
  9775. + __func__, VC_CMA_CHUNK_SIZE,
  9776. + vc_cma_chunks_used, chunks_needed);
  9777. + goto out_release;
  9778. + }
  9779. +
  9780. + vchiq_add_connected_callback(vc_cma_connected_init);
  9781. + }
  9782. +
  9783. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  9784. + if (rc < 0) {
  9785. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  9786. + goto out_release;
  9787. + }
  9788. +
  9789. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  9790. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  9791. + if (rc != 0) {
  9792. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  9793. + goto out_unregister;
  9794. + }
  9795. +
  9796. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  9797. + if (IS_ERR(vc_cma_class)) {
  9798. + rc = PTR_ERR(vc_cma_class);
  9799. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  9800. + goto out_cdev_del;
  9801. + }
  9802. +
  9803. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  9804. + DRIVER_NAME);
  9805. + if (IS_ERR(dev)) {
  9806. + rc = PTR_ERR(dev);
  9807. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  9808. + goto out_class_destroy;
  9809. + }
  9810. +
  9811. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  9812. + if (vc_cma_proc_entry == NULL) {
  9813. + rc = -EFAULT;
  9814. + LOG_ERR("%s: proc_create failed", __func__);
  9815. + goto out_device_destroy;
  9816. + }
  9817. +
  9818. + vc_cma_inited = 1;
  9819. + return 0;
  9820. +
  9821. +out_device_destroy:
  9822. + device_destroy(vc_cma_class, vc_cma_devnum);
  9823. +
  9824. +out_class_destroy:
  9825. + class_destroy(vc_cma_class);
  9826. + vc_cma_class = NULL;
  9827. +
  9828. +out_cdev_del:
  9829. + cdev_del(&vc_cma_cdev);
  9830. +
  9831. +out_unregister:
  9832. + unregister_chrdev_region(vc_cma_devnum, 1);
  9833. +
  9834. +out_release:
  9835. + /* It is tempting to try to clean up by calling
  9836. + dma_release_from_contiguous for all allocated chunks, but it isn't
  9837. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  9838. + VideoCore is already using that memory, so giving it back to Linux
  9839. + is likely to be fatal.
  9840. + */
  9841. + return -1;
  9842. +}
  9843. +
  9844. +/****************************************************************************
  9845. +*
  9846. +* vc_cma_exit
  9847. +*
  9848. +***************************************************************************/
  9849. +
  9850. +static void __exit vc_cma_exit(void)
  9851. +{
  9852. + LOG_DBG("%s: called", __func__);
  9853. +
  9854. + if (vc_cma_inited) {
  9855. + remove_proc_entry(DRIVER_NAME, NULL);
  9856. + device_destroy(vc_cma_class, vc_cma_devnum);
  9857. + class_destroy(vc_cma_class);
  9858. + cdev_del(&vc_cma_cdev);
  9859. + unregister_chrdev_region(vc_cma_devnum, 1);
  9860. + }
  9861. +}
  9862. +
  9863. +module_init(vc_cma_init);
  9864. +module_exit(vc_cma_exit);
  9865. +MODULE_LICENSE("GPL");
  9866. +MODULE_AUTHOR("Broadcom Corporation");
  9867. diff -Nur linux-3.11.10.orig/drivers/char/hw_random/bcm2708-rng.c linux-3.11.10/drivers/char/hw_random/bcm2708-rng.c
  9868. --- linux-3.11.10.orig/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  9869. +++ linux-3.11.10/drivers/char/hw_random/bcm2708-rng.c 2014-02-07 19:57:28.000000000 +0100
  9870. @@ -0,0 +1,117 @@
  9871. +/**
  9872. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  9873. + *
  9874. + * Redistribution and use in source and binary forms, with or without
  9875. + * modification, are permitted provided that the following conditions
  9876. + * are met:
  9877. + * 1. Redistributions of source code must retain the above copyright
  9878. + * notice, this list of conditions, and the following disclaimer,
  9879. + * without modification.
  9880. + * 2. Redistributions in binary form must reproduce the above copyright
  9881. + * notice, this list of conditions and the following disclaimer in the
  9882. + * documentation and/or other materials provided with the distribution.
  9883. + * 3. The names of the above-listed copyright holders may not be used
  9884. + * to endorse or promote products derived from this software without
  9885. + * specific prior written permission.
  9886. + *
  9887. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9888. + * GNU General Public License ("GPL") version 2, as published by the Free
  9889. + * Software Foundation.
  9890. + *
  9891. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  9892. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  9893. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  9894. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  9895. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  9896. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  9897. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  9898. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  9899. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  9900. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9901. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9902. + */
  9903. +
  9904. +#include <linux/kernel.h>
  9905. +#include <linux/module.h>
  9906. +#include <linux/init.h>
  9907. +#include <linux/hw_random.h>
  9908. +#include <linux/printk.h>
  9909. +
  9910. +#include <asm/io.h>
  9911. +#include <mach/hardware.h>
  9912. +#include <mach/platform.h>
  9913. +
  9914. +#define RNG_CTRL (0x0)
  9915. +#define RNG_STATUS (0x4)
  9916. +#define RNG_DATA (0x8)
  9917. +#define RNG_FF_THRESHOLD (0xc)
  9918. +
  9919. +/* enable rng */
  9920. +#define RNG_RBGEN 0x1
  9921. +/* double speed, less random mode */
  9922. +#define RNG_RBG2X 0x2
  9923. +
  9924. +/* the initial numbers generated are "less random" so will be discarded */
  9925. +#define RNG_WARMUP_COUNT 0x40000
  9926. +
  9927. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  9928. +{
  9929. + void __iomem *rng_base = (void __iomem *)rng->priv;
  9930. + unsigned words;
  9931. + /* wait for a random number to be in fifo */
  9932. + do {
  9933. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  9934. + }
  9935. + while (words == 0);
  9936. + /* read the random number */
  9937. + *buffer = __raw_readl(rng_base + RNG_DATA);
  9938. + return 4;
  9939. +}
  9940. +
  9941. +static struct hwrng bcm2708_rng_ops = {
  9942. + .name = "bcm2708",
  9943. + .data_read = bcm2708_rng_data_read,
  9944. +};
  9945. +
  9946. +static int __init bcm2708_rng_init(void)
  9947. +{
  9948. + void __iomem *rng_base;
  9949. + int err;
  9950. +
  9951. + /* map peripheral */
  9952. + rng_base = ioremap(RNG_BASE, 0x10);
  9953. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  9954. + if (!rng_base) {
  9955. + pr_err("bcm2708_rng_init failed to ioremap\n");
  9956. + return -ENOMEM;
  9957. + }
  9958. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  9959. + /* register driver */
  9960. + err = hwrng_register(&bcm2708_rng_ops);
  9961. + if (err) {
  9962. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  9963. + iounmap(rng_base);
  9964. + } else {
  9965. + /* set warm-up count & enable */
  9966. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  9967. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  9968. + }
  9969. + return err;
  9970. +}
  9971. +
  9972. +static void __exit bcm2708_rng_exit(void)
  9973. +{
  9974. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  9975. + pr_info("bcm2708_rng_exit\n");
  9976. + /* disable rng hardware */
  9977. + __raw_writel(0, rng_base + RNG_CTRL);
  9978. + /* unregister driver */
  9979. + hwrng_unregister(&bcm2708_rng_ops);
  9980. + iounmap(rng_base);
  9981. +}
  9982. +
  9983. +module_init(bcm2708_rng_init);
  9984. +module_exit(bcm2708_rng_exit);
  9985. +
  9986. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  9987. +MODULE_LICENSE("GPL and additional rights");
  9988. diff -Nur linux-3.11.10.orig/drivers/char/hw_random/Kconfig linux-3.11.10/drivers/char/hw_random/Kconfig
  9989. --- linux-3.11.10.orig/drivers/char/hw_random/Kconfig 2013-11-29 19:42:37.000000000 +0100
  9990. +++ linux-3.11.10/drivers/char/hw_random/Kconfig 2014-02-07 19:57:28.000000000 +0100
  9991. @@ -314,3 +314,14 @@
  9992. module will be called tpm-rng.
  9993. If unsure, say Y.
  9994. +
  9995. +config HW_RANDOM_BCM2708
  9996. + tristate "BCM2708 generic true random number generator support"
  9997. + depends on HW_RANDOM && ARCH_BCM2708
  9998. + ---help---
  9999. + This driver provides the kernel-side support for the BCM2708 hardware.
  10000. +
  10001. + To compile this driver as a module, choose M here: the
  10002. + module will be called bcm2708-rng.
  10003. +
  10004. + If unsure, say N.
  10005. diff -Nur linux-3.11.10.orig/drivers/char/hw_random/Makefile linux-3.11.10/drivers/char/hw_random/Makefile
  10006. --- linux-3.11.10.orig/drivers/char/hw_random/Makefile 2013-11-29 19:42:37.000000000 +0100
  10007. +++ linux-3.11.10/drivers/char/hw_random/Makefile 2014-02-07 19:57:28.000000000 +0100
  10008. @@ -27,3 +27,4 @@
  10009. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  10010. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  10011. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  10012. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  10013. diff -Nur linux-3.11.10.orig/drivers/char/Kconfig linux-3.11.10/drivers/char/Kconfig
  10014. --- linux-3.11.10.orig/drivers/char/Kconfig 2013-11-29 19:42:37.000000000 +0100
  10015. +++ linux-3.11.10/drivers/char/Kconfig 2014-02-07 19:57:28.000000000 +0100
  10016. @@ -574,6 +574,8 @@
  10017. source "drivers/s390/char/Kconfig"
  10018. +source "drivers/char/broadcom/Kconfig"
  10019. +
  10020. config MSM_SMD_PKT
  10021. bool "Enable device interface for some SMD packet ports"
  10022. default n
  10023. diff -Nur linux-3.11.10.orig/drivers/char/Makefile linux-3.11.10/drivers/char/Makefile
  10024. --- linux-3.11.10.orig/drivers/char/Makefile 2013-11-29 19:42:37.000000000 +0100
  10025. +++ linux-3.11.10/drivers/char/Makefile 2014-02-07 19:57:28.000000000 +0100
  10026. @@ -62,3 +62,5 @@
  10027. js-rtc-y = rtc.o
  10028. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  10029. +
  10030. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  10031. diff -Nur linux-3.11.10.orig/drivers/cpufreq/bcm2835-cpufreq.c linux-3.11.10/drivers/cpufreq/bcm2835-cpufreq.c
  10032. --- linux-3.11.10.orig/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  10033. +++ linux-3.11.10/drivers/cpufreq/bcm2835-cpufreq.c 2014-02-07 19:57:28.000000000 +0100
  10034. @@ -0,0 +1,238 @@
  10035. +/*****************************************************************************
  10036. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10037. +*
  10038. +* Unless you and Broadcom execute a separate written software license
  10039. +* agreement governing use of this software, this software is licensed to you
  10040. +* under the terms of the GNU General Public License version 2, available at
  10041. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10042. +*
  10043. +* Notwithstanding the above, under no circumstances may you combine this
  10044. +* software in any way with any other Broadcom software provided under a
  10045. +* license other than the GPL, without Broadcom's express prior written
  10046. +* consent.
  10047. +*****************************************************************************/
  10048. +
  10049. +/*****************************************************************************
  10050. +* FILENAME: bcm2835-cpufreq.h
  10051. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  10052. +* processor. Messages are sent to Videocore either setting or requesting the
  10053. +* frequency of the ARM in order to match an appropiate frequency to the current
  10054. +* usage of the processor. The policy which selects the frequency to use is
  10055. +* defined in the kernel .config file, but can be changed during runtime.
  10056. +*****************************************************************************/
  10057. +
  10058. +/* ---------- INCLUDES ---------- */
  10059. +#include <linux/kernel.h>
  10060. +#include <linux/init.h>
  10061. +#include <linux/module.h>
  10062. +#include <linux/cpufreq.h>
  10063. +#include <mach/vcio.h>
  10064. +
  10065. +/* ---------- DEFINES ---------- */
  10066. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  10067. +#define MODULE_NAME "bcm2835-cpufreq"
  10068. +
  10069. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  10070. +
  10071. +/* debug printk macros */
  10072. +#ifdef CPUFREQ_DEBUG_ENABLE
  10073. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10074. +#else
  10075. +#define print_debug(fmt,...)
  10076. +#endif
  10077. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10078. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  10079. +
  10080. +/* tag part of the message */
  10081. +struct vc_msg_tag {
  10082. + uint32_t tag_id; /* the message id */
  10083. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  10084. + uint32_t data_size; /* amount of data being sent or received */
  10085. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  10086. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  10087. +};
  10088. +
  10089. +/* message structure to be sent to videocore */
  10090. +struct vc_msg {
  10091. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10092. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10093. + struct vc_msg_tag tag; /* the tag structure above to make */
  10094. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10095. +};
  10096. +
  10097. +/* ---------- GLOBALS ---------- */
  10098. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  10099. +
  10100. +/*
  10101. + ===============================================
  10102. + clk_rate either gets or sets the clock rates.
  10103. + ===============================================
  10104. +*/
  10105. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  10106. +{
  10107. + int s, actual_rate=0;
  10108. + struct vc_msg msg;
  10109. +
  10110. + /* wipe all previous message data */
  10111. + memset(&msg, 0, sizeof msg);
  10112. +
  10113. + msg.msg_size = sizeof msg;
  10114. +
  10115. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  10116. + msg.tag.buffer_size = 8;
  10117. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  10118. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10119. + msg.tag.val = arm_rate * 1000;
  10120. +
  10121. + /* send the message */
  10122. + s = bcm_mailbox_property(&msg, sizeof msg);
  10123. +
  10124. + /* check if it was all ok and return the rate in KHz */
  10125. + if (s == 0 && (msg.request_code & 0x80000000))
  10126. + actual_rate = msg.tag.val/1000;
  10127. +
  10128. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  10129. + return actual_rate;
  10130. +}
  10131. +
  10132. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  10133. +{
  10134. + int s;
  10135. + int arm_rate = 0;
  10136. + struct vc_msg msg;
  10137. +
  10138. + /* wipe all previous message data */
  10139. + memset(&msg, 0, sizeof msg);
  10140. +
  10141. + msg.msg_size = sizeof msg;
  10142. + msg.tag.tag_id = tag;
  10143. + msg.tag.buffer_size = 8;
  10144. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  10145. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  10146. +
  10147. + /* send the message */
  10148. + s = bcm_mailbox_property(&msg, sizeof msg);
  10149. +
  10150. + /* check if it was all ok and return the rate in KHz */
  10151. + if (s == 0 && (msg.request_code & 0x80000000))
  10152. + arm_rate = msg.tag.val/1000;
  10153. +
  10154. + print_debug("%s frequency = %d\n",
  10155. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  10156. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  10157. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  10158. + "Unexpected", arm_rate);
  10159. +
  10160. + return arm_rate;
  10161. +}
  10162. +
  10163. +/*
  10164. + ====================================================
  10165. + Module Initialisation registers the cpufreq driver
  10166. + ====================================================
  10167. +*/
  10168. +static int __init bcm2835_cpufreq_module_init(void)
  10169. +{
  10170. + print_debug("IN\n");
  10171. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  10172. +}
  10173. +
  10174. +/*
  10175. + =============
  10176. + Module exit
  10177. + =============
  10178. +*/
  10179. +static void __exit bcm2835_cpufreq_module_exit(void)
  10180. +{
  10181. + print_debug("IN\n");
  10182. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  10183. + return;
  10184. +}
  10185. +
  10186. +/*
  10187. + ==============================================================
  10188. + Initialisation function sets up the CPU policy for first use
  10189. + ==============================================================
  10190. +*/
  10191. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  10192. +{
  10193. + /* measured value of how long it takes to change frequency */
  10194. + policy->cpuinfo.transition_latency = 355000; /* ns */
  10195. +
  10196. + /* now find out what the maximum and minimum frequencies are */
  10197. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  10198. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  10199. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10200. +
  10201. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  10202. + return 0;
  10203. +}
  10204. +
  10205. +/*
  10206. + =================================================================================
  10207. + Target function chooses the most appropriate frequency from the table to enable
  10208. + =================================================================================
  10209. +*/
  10210. +
  10211. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  10212. +{
  10213. + unsigned int target = target_freq;
  10214. + unsigned int cur = policy->cur;
  10215. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  10216. +
  10217. + /* if we are above min and using ondemand, then just use max */
  10218. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  10219. + target = policy->max;
  10220. + /* if the frequency is the same, just quit */
  10221. + if (target == policy->cur)
  10222. + return 0;
  10223. +
  10224. + /* otherwise were good to set the clock frequency */
  10225. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  10226. +
  10227. + if (!policy->cur)
  10228. + {
  10229. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  10230. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10231. + return -EINVAL;
  10232. + }
  10233. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  10234. + return 0;
  10235. +}
  10236. +
  10237. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  10238. +{
  10239. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  10240. + print_debug("cpu=%d\n", actual_rate);
  10241. + return actual_rate;
  10242. +}
  10243. +
  10244. +/*
  10245. + =================================================================================
  10246. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  10247. + =================================================================================
  10248. +*/
  10249. +
  10250. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  10251. +{
  10252. + print_info("switching to governor %s\n", policy->governor->name);
  10253. + return 0;
  10254. +}
  10255. +
  10256. +
  10257. +/* the CPUFreq driver */
  10258. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  10259. + .name = "BCM2835 CPUFreq",
  10260. + .owner = THIS_MODULE,
  10261. + .init = bcm2835_cpufreq_driver_init,
  10262. + .verify = bcm2835_cpufreq_driver_verify,
  10263. + .target = bcm2835_cpufreq_driver_target,
  10264. + .get = bcm2835_cpufreq_driver_get
  10265. +};
  10266. +
  10267. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  10268. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  10269. +MODULE_LICENSE("GPL");
  10270. +
  10271. +module_init(bcm2835_cpufreq_module_init);
  10272. +module_exit(bcm2835_cpufreq_module_exit);
  10273. diff -Nur linux-3.11.10.orig/drivers/cpufreq/Kconfig.arm linux-3.11.10/drivers/cpufreq/Kconfig.arm
  10274. --- linux-3.11.10.orig/drivers/cpufreq/Kconfig.arm 2013-11-29 19:42:37.000000000 +0100
  10275. +++ linux-3.11.10/drivers/cpufreq/Kconfig.arm 2014-02-07 19:57:28.000000000 +0100
  10276. @@ -216,6 +216,14 @@
  10277. help
  10278. This adds the CPUFreq driver support for SPEAr SOCs.
  10279. +config ARM_BCM2835_CPUFREQ
  10280. + bool "BCM2835 Driver"
  10281. + default y
  10282. + help
  10283. + This adds the CPUFreq driver for BCM2835
  10284. +
  10285. + If in doubt, say N.
  10286. +
  10287. config ARM_TEGRA_CPUFREQ
  10288. bool "TEGRA CPUFreq support"
  10289. depends on ARCH_TEGRA
  10290. diff -Nur linux-3.11.10.orig/drivers/cpufreq/Makefile linux-3.11.10/drivers/cpufreq/Makefile
  10291. --- linux-3.11.10.orig/drivers/cpufreq/Makefile 2013-11-29 19:42:37.000000000 +0100
  10292. +++ linux-3.11.10/drivers/cpufreq/Makefile 2014-02-07 19:57:28.000000000 +0100
  10293. @@ -76,6 +76,7 @@
  10294. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  10295. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  10296. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  10297. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  10298. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  10299. ##################################################################################
  10300. diff -Nur linux-3.11.10.orig/drivers/hwmon/bcm2835-hwmon.c linux-3.11.10/drivers/hwmon/bcm2835-hwmon.c
  10301. --- linux-3.11.10.orig/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  10302. +++ linux-3.11.10/drivers/hwmon/bcm2835-hwmon.c 2014-02-07 19:57:28.000000000 +0100
  10303. @@ -0,0 +1,219 @@
  10304. +/*****************************************************************************
  10305. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10306. +*
  10307. +* Unless you and Broadcom execute a separate written software license
  10308. +* agreement governing use of this software, this software is licensed to you
  10309. +* under the terms of the GNU General Public License version 2, available at
  10310. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10311. +*
  10312. +* Notwithstanding the above, under no circumstances may you combine this
  10313. +* software in any way with any other Broadcom software provided under a
  10314. +* license other than the GPL, without Broadcom's express prior written
  10315. +* consent.
  10316. +*****************************************************************************/
  10317. +
  10318. +#include <linux/kernel.h>
  10319. +#include <linux/module.h>
  10320. +#include <linux/init.h>
  10321. +#include <linux/hwmon.h>
  10322. +#include <linux/hwmon-sysfs.h>
  10323. +#include <linux/platform_device.h>
  10324. +#include <linux/sysfs.h>
  10325. +#include <mach/vcio.h>
  10326. +#include <linux/slab.h>
  10327. +#include <linux/err.h>
  10328. +
  10329. +#define MODULE_NAME "bcm2835_hwmon"
  10330. +
  10331. +/*#define HWMON_DEBUG_ENABLE*/
  10332. +
  10333. +#ifdef HWMON_DEBUG_ENABLE
  10334. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10335. +#else
  10336. +#define print_debug(fmt,...)
  10337. +#endif
  10338. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10339. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  10340. +
  10341. +#define VC_TAG_GET_TEMP 0x00030006
  10342. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  10343. +
  10344. +/* --- STRUCTS --- */
  10345. +struct bcm2835_hwmon_data {
  10346. + struct device *hwmon_dev;
  10347. +};
  10348. +
  10349. +/* tag part of the message */
  10350. +struct vc_msg_tag {
  10351. + uint32_t tag_id; /* the tag ID for the temperature */
  10352. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  10353. + uint32_t request_code; /* identifies message as a request (should be 0) */
  10354. + uint32_t id; /* extra ID field (should be 0) */
  10355. + uint32_t val; /* returned value of the temperature */
  10356. +};
  10357. +
  10358. +/* message structure to be sent to videocore */
  10359. +struct vc_msg {
  10360. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10361. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10362. + struct vc_msg_tag tag; /* the tag structure above to make */
  10363. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10364. +};
  10365. +
  10366. +typedef enum {
  10367. + TEMP,
  10368. + MAX_TEMP,
  10369. +} temp_type;
  10370. +
  10371. +/* --- PROTOTYPES --- */
  10372. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  10373. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  10374. +
  10375. +/* --- GLOBALS --- */
  10376. +
  10377. +static struct bcm2835_hwmon_data *bcm2835_data;
  10378. +static struct platform_driver bcm2835_hwmon_driver;
  10379. +
  10380. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  10381. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  10382. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  10383. +
  10384. +static struct attribute* bcm2835_attributes[] = {
  10385. + &sensor_dev_attr_name.dev_attr.attr,
  10386. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10387. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10388. + NULL,
  10389. +};
  10390. +
  10391. +static struct attribute_group bcm2835_attr_group = {
  10392. + .attrs = bcm2835_attributes,
  10393. +};
  10394. +
  10395. +/* --- FUNCTIONS --- */
  10396. +
  10397. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10398. +{
  10399. + return sprintf(buf,"bcm2835_hwmon\n");
  10400. +}
  10401. +
  10402. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10403. +{
  10404. + struct vc_msg msg;
  10405. + int result;
  10406. + uint temp = 0;
  10407. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10408. +
  10409. + print_debug("IN");
  10410. +
  10411. + /* wipe all previous message data */
  10412. + memset(&msg, 0, sizeof msg);
  10413. +
  10414. + /* determine the message type */
  10415. + if(index == TEMP)
  10416. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10417. + else if (index == MAX_TEMP)
  10418. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10419. + else
  10420. + {
  10421. + print_debug("Unknown temperature message!");
  10422. + return -EINVAL;
  10423. + }
  10424. +
  10425. + msg.msg_size = sizeof msg;
  10426. + msg.tag.buffer_size = 8;
  10427. +
  10428. + /* send the message */
  10429. + result = bcm_mailbox_property(&msg, sizeof msg);
  10430. +
  10431. + /* check if it was all ok and return the rate in milli degrees C */
  10432. + if (result == 0 && (msg.request_code & 0x80000000))
  10433. + temp = (uint)msg.tag.val;
  10434. + #ifdef HWMON_DEBUG_ENABLE
  10435. + else
  10436. + print_debug("Failed to get temperature!");
  10437. + #endif
  10438. + print_debug("Got temperature as %u",temp);
  10439. + print_debug("OUT");
  10440. + return sprintf(buf, "%u\n", temp);
  10441. +}
  10442. +
  10443. +
  10444. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10445. +{
  10446. + int err;
  10447. +
  10448. + print_debug("IN");
  10449. + print_debug("HWMON Driver has been probed!");
  10450. +
  10451. + /* check that the device isn't null!*/
  10452. + if(pdev == NULL)
  10453. + {
  10454. + print_debug("Platform device is empty!");
  10455. + return -ENODEV;
  10456. + }
  10457. +
  10458. + /* allocate memory for neccessary data */
  10459. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10460. + if(!bcm2835_data)
  10461. + {
  10462. + print_debug("Unable to allocate memory for hwmon data!");
  10463. + err = -ENOMEM;
  10464. + goto kzalloc_error;
  10465. + }
  10466. +
  10467. + /* create the sysfs files */
  10468. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10469. + {
  10470. + print_debug("Unable to create sysfs files!");
  10471. + err = -EFAULT;
  10472. + goto sysfs_error;
  10473. + }
  10474. +
  10475. + /* register the hwmon device */
  10476. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10477. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10478. + {
  10479. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10480. + goto hwmon_error;
  10481. + }
  10482. + print_debug("OUT");
  10483. + return 0;
  10484. +
  10485. + /* error goto's */
  10486. + hwmon_error:
  10487. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10488. +
  10489. + sysfs_error:
  10490. + kfree(bcm2835_data);
  10491. +
  10492. + kzalloc_error:
  10493. +
  10494. + return err;
  10495. +
  10496. +}
  10497. +
  10498. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10499. +{
  10500. + print_debug("IN");
  10501. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10502. +
  10503. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10504. + print_debug("OUT");
  10505. + return 0;
  10506. +}
  10507. +
  10508. +/* Hwmon Driver */
  10509. +static struct platform_driver bcm2835_hwmon_driver = {
  10510. + .probe = bcm2835_hwmon_probe,
  10511. + .remove = bcm2835_hwmon_remove,
  10512. + .driver = {
  10513. + .name = "bcm2835_hwmon",
  10514. + .owner = THIS_MODULE,
  10515. + },
  10516. +};
  10517. +
  10518. +MODULE_LICENSE("GPL");
  10519. +MODULE_AUTHOR("Dorian Peake");
  10520. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10521. +
  10522. +module_platform_driver(bcm2835_hwmon_driver);
  10523. diff -Nur linux-3.11.10.orig/drivers/hwmon/Kconfig linux-3.11.10/drivers/hwmon/Kconfig
  10524. --- linux-3.11.10.orig/drivers/hwmon/Kconfig 2013-11-29 19:42:37.000000000 +0100
  10525. +++ linux-3.11.10/drivers/hwmon/Kconfig 2014-02-07 19:57:28.000000000 +0100
  10526. @@ -1543,6 +1543,16 @@
  10527. help
  10528. Support for the A/D converter on MC13783 and MC13892 PMIC.
  10529. +config SENSORS_BCM2835
  10530. + depends on THERMAL_BCM2835=n
  10531. + tristate "Broadcom BCM2835 HWMON Driver"
  10532. + help
  10533. + If you say yes here you get support for the hardware
  10534. + monitoring features of the BCM2835 Chip
  10535. +
  10536. + This driver can also be built as a module. If so, the module
  10537. + will be called bcm2835-hwmon.
  10538. +
  10539. if ACPI
  10540. comment "ACPI drivers"
  10541. diff -Nur linux-3.11.10.orig/drivers/hwmon/Makefile linux-3.11.10/drivers/hwmon/Makefile
  10542. --- linux-3.11.10.orig/drivers/hwmon/Makefile 2013-11-29 19:42:37.000000000 +0100
  10543. +++ linux-3.11.10/drivers/hwmon/Makefile 2014-02-07 19:57:28.000000000 +0100
  10544. @@ -141,6 +141,7 @@
  10545. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10546. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10547. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10548. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10549. obj-$(CONFIG_PMBUS) += pmbus/
  10550. diff -Nur linux-3.11.10.orig/drivers/i2c/busses/i2c-bcm2708.c linux-3.11.10/drivers/i2c/busses/i2c-bcm2708.c
  10551. --- linux-3.11.10.orig/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10552. +++ linux-3.11.10/drivers/i2c/busses/i2c-bcm2708.c 2014-02-07 19:57:28.000000000 +0100
  10553. @@ -0,0 +1,408 @@
  10554. +/*
  10555. + * Driver for Broadcom BCM2708 BSC Controllers
  10556. + *
  10557. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10558. + *
  10559. + * This driver is inspired by:
  10560. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10561. + *
  10562. + * This program is free software; you can redistribute it and/or modify
  10563. + * it under the terms of the GNU General Public License as published by
  10564. + * the Free Software Foundation; either version 2 of the License, or
  10565. + * (at your option) any later version.
  10566. + *
  10567. + * This program is distributed in the hope that it will be useful,
  10568. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10569. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10570. + * GNU General Public License for more details.
  10571. + *
  10572. + * You should have received a copy of the GNU General Public License
  10573. + * along with this program; if not, write to the Free Software
  10574. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10575. + */
  10576. +
  10577. +#include <linux/kernel.h>
  10578. +#include <linux/module.h>
  10579. +#include <linux/spinlock.h>
  10580. +#include <linux/clk.h>
  10581. +#include <linux/err.h>
  10582. +#include <linux/platform_device.h>
  10583. +#include <linux/io.h>
  10584. +#include <linux/slab.h>
  10585. +#include <linux/i2c.h>
  10586. +#include <linux/interrupt.h>
  10587. +#include <linux/sched.h>
  10588. +#include <linux/wait.h>
  10589. +
  10590. +/* BSC register offsets */
  10591. +#define BSC_C 0x00
  10592. +#define BSC_S 0x04
  10593. +#define BSC_DLEN 0x08
  10594. +#define BSC_A 0x0c
  10595. +#define BSC_FIFO 0x10
  10596. +#define BSC_DIV 0x14
  10597. +#define BSC_DEL 0x18
  10598. +#define BSC_CLKT 0x1c
  10599. +
  10600. +/* Bitfields in BSC_C */
  10601. +#define BSC_C_I2CEN 0x00008000
  10602. +#define BSC_C_INTR 0x00000400
  10603. +#define BSC_C_INTT 0x00000200
  10604. +#define BSC_C_INTD 0x00000100
  10605. +#define BSC_C_ST 0x00000080
  10606. +#define BSC_C_CLEAR_1 0x00000020
  10607. +#define BSC_C_CLEAR_2 0x00000010
  10608. +#define BSC_C_READ 0x00000001
  10609. +
  10610. +/* Bitfields in BSC_S */
  10611. +#define BSC_S_CLKT 0x00000200
  10612. +#define BSC_S_ERR 0x00000100
  10613. +#define BSC_S_RXF 0x00000080
  10614. +#define BSC_S_TXE 0x00000040
  10615. +#define BSC_S_RXD 0x00000020
  10616. +#define BSC_S_TXD 0x00000010
  10617. +#define BSC_S_RXR 0x00000008
  10618. +#define BSC_S_TXW 0x00000004
  10619. +#define BSC_S_DONE 0x00000002
  10620. +#define BSC_S_TA 0x00000001
  10621. +
  10622. +#define I2C_TIMEOUT_MS 150
  10623. +
  10624. +#define DRV_NAME "bcm2708_i2c"
  10625. +
  10626. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10627. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10628. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10629. +
  10630. +
  10631. +struct bcm2708_i2c {
  10632. + struct i2c_adapter adapter;
  10633. +
  10634. + spinlock_t lock;
  10635. + void __iomem *base;
  10636. + int irq;
  10637. + struct clk *clk;
  10638. +
  10639. + struct completion done;
  10640. +
  10641. + struct i2c_msg *msg;
  10642. + int pos;
  10643. + int nmsgs;
  10644. + bool error;
  10645. +};
  10646. +
  10647. +/*
  10648. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10649. + * the BSC hardware.
  10650. + *
  10651. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10652. + */
  10653. +static void bcm2708_i2c_init_pinmode(int id)
  10654. +{
  10655. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10656. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10657. +
  10658. + int pin;
  10659. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  10660. +
  10661. + BUG_ON(id != 0 && id != 1);
  10662. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10663. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10664. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10665. + INP_GPIO(pin); /* set mode to GPIO input first */
  10666. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10667. + }
  10668. +
  10669. + iounmap(gpio);
  10670. +
  10671. +#undef INP_GPIO
  10672. +#undef SET_GPIO_ALT
  10673. +}
  10674. +
  10675. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10676. +{
  10677. + return readl(bi->base + reg);
  10678. +}
  10679. +
  10680. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10681. +{
  10682. + writel(val, bi->base + reg);
  10683. +}
  10684. +
  10685. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10686. +{
  10687. + bcm2708_wr(bi, BSC_C, 0);
  10688. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10689. +}
  10690. +
  10691. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  10692. +{
  10693. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  10694. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  10695. +}
  10696. +
  10697. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  10698. +{
  10699. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  10700. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10701. +}
  10702. +
  10703. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  10704. +{
  10705. + unsigned long bus_hz;
  10706. + u32 cdiv;
  10707. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  10708. +
  10709. + bus_hz = clk_get_rate(bi->clk);
  10710. + cdiv = bus_hz / baudrate;
  10711. +
  10712. + if (bi->msg->flags & I2C_M_RD)
  10713. + c |= BSC_C_INTR | BSC_C_READ;
  10714. + else
  10715. + c |= BSC_C_INTT;
  10716. +
  10717. + bcm2708_wr(bi, BSC_DIV, cdiv);
  10718. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  10719. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10720. + bcm2708_wr(bi, BSC_C, c);
  10721. +}
  10722. +
  10723. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  10724. +{
  10725. + struct bcm2708_i2c *bi = dev_id;
  10726. + bool handled = true;
  10727. + u32 s;
  10728. +
  10729. + spin_lock(&bi->lock);
  10730. +
  10731. + /* we may see camera interrupts on the "other" I2C channel
  10732. + Just return if we've not sent anything */
  10733. + if (!bi->nmsgs || !bi->msg )
  10734. + goto early_exit;
  10735. +
  10736. + s = bcm2708_rd(bi, BSC_S);
  10737. +
  10738. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  10739. + bcm2708_bsc_reset(bi);
  10740. + bi->error = true;
  10741. +
  10742. + /* wake up our bh */
  10743. + complete(&bi->done);
  10744. + } else if (s & BSC_S_DONE) {
  10745. + bi->nmsgs--;
  10746. +
  10747. + if (bi->msg->flags & I2C_M_RD)
  10748. + bcm2708_bsc_fifo_drain(bi);
  10749. +
  10750. + bcm2708_bsc_reset(bi);
  10751. +
  10752. + if (bi->nmsgs) {
  10753. + /* advance to next message */
  10754. + bi->msg++;
  10755. + bi->pos = 0;
  10756. + bcm2708_bsc_setup(bi);
  10757. + } else {
  10758. + /* wake up our bh */
  10759. + complete(&bi->done);
  10760. + }
  10761. + } else if (s & BSC_S_TXW) {
  10762. + bcm2708_bsc_fifo_fill(bi);
  10763. + } else if (s & BSC_S_RXR) {
  10764. + bcm2708_bsc_fifo_drain(bi);
  10765. + } else {
  10766. + handled = false;
  10767. + }
  10768. +
  10769. +early_exit:
  10770. + spin_unlock(&bi->lock);
  10771. +
  10772. + return handled ? IRQ_HANDLED : IRQ_NONE;
  10773. +}
  10774. +
  10775. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  10776. + struct i2c_msg *msgs, int num)
  10777. +{
  10778. + struct bcm2708_i2c *bi = adap->algo_data;
  10779. + unsigned long flags;
  10780. + int ret;
  10781. +
  10782. + spin_lock_irqsave(&bi->lock, flags);
  10783. +
  10784. + INIT_COMPLETION(bi->done);
  10785. + bi->msg = msgs;
  10786. + bi->pos = 0;
  10787. + bi->nmsgs = num;
  10788. + bi->error = false;
  10789. +
  10790. + spin_unlock_irqrestore(&bi->lock, flags);
  10791. +
  10792. + bcm2708_bsc_setup(bi);
  10793. +
  10794. + ret = wait_for_completion_timeout(&bi->done,
  10795. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  10796. + if (ret == 0) {
  10797. + dev_err(&adap->dev, "transfer timed out\n");
  10798. + spin_lock_irqsave(&bi->lock, flags);
  10799. + bcm2708_bsc_reset(bi);
  10800. + spin_unlock_irqrestore(&bi->lock, flags);
  10801. + return -ETIMEDOUT;
  10802. + }
  10803. +
  10804. + return bi->error ? -EIO : num;
  10805. +}
  10806. +
  10807. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  10808. +{
  10809. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  10810. +}
  10811. +
  10812. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  10813. + .master_xfer = bcm2708_i2c_master_xfer,
  10814. + .functionality = bcm2708_i2c_functionality,
  10815. +};
  10816. +
  10817. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  10818. +{
  10819. + struct resource *regs;
  10820. + int irq, err = -ENOMEM;
  10821. + struct clk *clk;
  10822. + struct bcm2708_i2c *bi;
  10823. + struct i2c_adapter *adap;
  10824. +
  10825. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  10826. + if (!regs) {
  10827. + dev_err(&pdev->dev, "could not get IO memory\n");
  10828. + return -ENXIO;
  10829. + }
  10830. +
  10831. + irq = platform_get_irq(pdev, 0);
  10832. + if (irq < 0) {
  10833. + dev_err(&pdev->dev, "could not get IRQ\n");
  10834. + return irq;
  10835. + }
  10836. +
  10837. + clk = clk_get(&pdev->dev, NULL);
  10838. + if (IS_ERR(clk)) {
  10839. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  10840. + return PTR_ERR(clk);
  10841. + }
  10842. +
  10843. + bcm2708_i2c_init_pinmode(pdev->id);
  10844. +
  10845. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  10846. + if (!bi)
  10847. + goto out_clk_put;
  10848. +
  10849. + platform_set_drvdata(pdev, bi);
  10850. +
  10851. + adap = &bi->adapter;
  10852. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  10853. + adap->algo = &bcm2708_i2c_algorithm;
  10854. + adap->algo_data = bi;
  10855. + adap->dev.parent = &pdev->dev;
  10856. + adap->nr = pdev->id;
  10857. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  10858. +
  10859. + switch (pdev->id) {
  10860. + case 0:
  10861. + adap->class = I2C_CLASS_HWMON;
  10862. + break;
  10863. + case 1:
  10864. + adap->class = I2C_CLASS_DDC;
  10865. + break;
  10866. + default:
  10867. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  10868. + err = -ENXIO;
  10869. + goto out_free_bi;
  10870. + }
  10871. +
  10872. + spin_lock_init(&bi->lock);
  10873. + init_completion(&bi->done);
  10874. +
  10875. + bi->base = ioremap(regs->start, resource_size(regs));
  10876. + if (!bi->base) {
  10877. + dev_err(&pdev->dev, "could not remap memory\n");
  10878. + goto out_free_bi;
  10879. + }
  10880. +
  10881. + bi->irq = irq;
  10882. + bi->clk = clk;
  10883. +
  10884. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  10885. + dev_name(&pdev->dev), bi);
  10886. + if (err) {
  10887. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  10888. + goto out_iounmap;
  10889. + }
  10890. +
  10891. + bcm2708_bsc_reset(bi);
  10892. +
  10893. + err = i2c_add_numbered_adapter(adap);
  10894. + if (err < 0) {
  10895. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  10896. + goto out_free_irq;
  10897. + }
  10898. +
  10899. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  10900. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  10901. +
  10902. + return 0;
  10903. +
  10904. +out_free_irq:
  10905. + free_irq(bi->irq, bi);
  10906. +out_iounmap:
  10907. + iounmap(bi->base);
  10908. +out_free_bi:
  10909. + kfree(bi);
  10910. +out_clk_put:
  10911. + clk_put(clk);
  10912. + return err;
  10913. +}
  10914. +
  10915. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  10916. +{
  10917. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  10918. +
  10919. + platform_set_drvdata(pdev, NULL);
  10920. +
  10921. + i2c_del_adapter(&bi->adapter);
  10922. + free_irq(bi->irq, bi);
  10923. + iounmap(bi->base);
  10924. + clk_disable(bi->clk);
  10925. + clk_put(bi->clk);
  10926. + kfree(bi);
  10927. +
  10928. + return 0;
  10929. +}
  10930. +
  10931. +static struct platform_driver bcm2708_i2c_driver = {
  10932. + .driver = {
  10933. + .name = DRV_NAME,
  10934. + .owner = THIS_MODULE,
  10935. + },
  10936. + .probe = bcm2708_i2c_probe,
  10937. + .remove = bcm2708_i2c_remove,
  10938. +};
  10939. +
  10940. +// module_platform_driver(bcm2708_i2c_driver);
  10941. +
  10942. +
  10943. +static int __init bcm2708_i2c_init(void)
  10944. +{
  10945. + return platform_driver_register(&bcm2708_i2c_driver);
  10946. +}
  10947. +
  10948. +static void __exit bcm2708_i2c_exit(void)
  10949. +{
  10950. + platform_driver_unregister(&bcm2708_i2c_driver);
  10951. +}
  10952. +
  10953. +module_init(bcm2708_i2c_init);
  10954. +module_exit(bcm2708_i2c_exit);
  10955. +
  10956. +
  10957. +
  10958. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  10959. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  10960. +MODULE_LICENSE("GPL v2");
  10961. +MODULE_ALIAS("platform:" DRV_NAME);
  10962. diff -Nur linux-3.11.10.orig/drivers/i2c/busses/Kconfig linux-3.11.10/drivers/i2c/busses/Kconfig
  10963. --- linux-3.11.10.orig/drivers/i2c/busses/Kconfig 2013-11-29 19:42:37.000000000 +0100
  10964. +++ linux-3.11.10/drivers/i2c/busses/Kconfig 2014-02-07 19:57:28.000000000 +0100
  10965. @@ -345,6 +345,25 @@
  10966. This support is also available as a module. If so, the module
  10967. will be called i2c-bcm2835.
  10968. +config I2C_BCM2708
  10969. + tristate "BCM2708 BSC"
  10970. + depends on MACH_BCM2708
  10971. + help
  10972. + Enabling this option will add BSC (Broadcom Serial Controller)
  10973. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  10974. + with I2C/TWI/SMBus.
  10975. +
  10976. +config I2C_BCM2708_BAUDRATE
  10977. + prompt "BCM2708 I2C baudrate"
  10978. + depends on I2C_BCM2708
  10979. + int
  10980. + default 100000
  10981. + help
  10982. + Set the I2C baudrate. This will alter the default value. A
  10983. + different baudrate can be set by using a module parameter as well. If
  10984. + no parameter is provided when loading, this is the value that will be
  10985. + used.
  10986. +
  10987. config I2C_BLACKFIN_TWI
  10988. tristate "Blackfin TWI I2C support"
  10989. depends on BLACKFIN
  10990. diff -Nur linux-3.11.10.orig/drivers/i2c/busses/Makefile linux-3.11.10/drivers/i2c/busses/Makefile
  10991. --- linux-3.11.10.orig/drivers/i2c/busses/Makefile 2013-11-29 19:42:37.000000000 +0100
  10992. +++ linux-3.11.10/drivers/i2c/busses/Makefile 2014-02-07 19:57:28.000000000 +0100
  10993. @@ -32,6 +32,7 @@
  10994. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  10995. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  10996. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  10997. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  10998. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  10999. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  11000. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  11001. diff -Nur linux-3.11.10.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-3.11.10/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  11002. --- linux-3.11.10.orig/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2013-11-29 19:42:37.000000000 +0100
  11003. +++ linux-3.11.10/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-02-07 19:57:28.000000000 +0100
  11004. @@ -1384,6 +1384,10 @@
  11005. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  11006. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  11007. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  11008. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  11009. + &rtl2832u_props, "August DVB-T 205", NULL) },
  11010. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  11011. + &rtl2832u_props, "August DVB-T 205", NULL) },
  11012. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  11013. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  11014. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  11015. diff -Nur linux-3.11.10.orig/drivers/misc/Kconfig linux-3.11.10/drivers/misc/Kconfig
  11016. --- linux-3.11.10.orig/drivers/misc/Kconfig 2013-11-29 19:42:37.000000000 +0100
  11017. +++ linux-3.11.10/drivers/misc/Kconfig 2014-02-07 19:57:28.000000000 +0100
  11018. @@ -537,4 +537,5 @@
  11019. source "drivers/misc/altera-stapl/Kconfig"
  11020. source "drivers/misc/mei/Kconfig"
  11021. source "drivers/misc/vmw_vmci/Kconfig"
  11022. +source "drivers/misc/vc04_services/Kconfig"
  11023. endmenu
  11024. diff -Nur linux-3.11.10.orig/drivers/misc/Makefile linux-3.11.10/drivers/misc/Makefile
  11025. --- linux-3.11.10.orig/drivers/misc/Makefile 2013-11-29 19:42:37.000000000 +0100
  11026. +++ linux-3.11.10/drivers/misc/Makefile 2014-02-07 19:57:28.000000000 +0100
  11027. @@ -53,3 +53,4 @@
  11028. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  11029. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  11030. obj-$(CONFIG_SRAM) += sram.o
  11031. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  11032. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  11033. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  11034. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-02-07 19:57:28.000000000 +0100
  11035. @@ -0,0 +1,328 @@
  11036. +/**
  11037. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  11038. + *
  11039. + * Redistribution and use in source and binary forms, with or without
  11040. + * modification, are permitted provided that the following conditions
  11041. + * are met:
  11042. + * 1. Redistributions of source code must retain the above copyright
  11043. + * notice, this list of conditions, and the following disclaimer,
  11044. + * without modification.
  11045. + * 2. Redistributions in binary form must reproduce the above copyright
  11046. + * notice, this list of conditions and the following disclaimer in the
  11047. + * documentation and/or other materials provided with the distribution.
  11048. + * 3. The names of the above-listed copyright holders may not be used
  11049. + * to endorse or promote products derived from this software without
  11050. + * specific prior written permission.
  11051. + *
  11052. + * ALTERNATIVELY, this software may be distributed under the terms of the
  11053. + * GNU General Public License ("GPL") version 2, as published by the Free
  11054. + * Software Foundation.
  11055. + *
  11056. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  11057. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  11058. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11059. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  11060. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  11061. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  11062. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  11063. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11064. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  11065. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  11066. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11067. + */
  11068. +
  11069. +#ifndef CONNECTION_H_
  11070. +#define CONNECTION_H_
  11071. +
  11072. +#include <linux/kernel.h>
  11073. +#include <linux/types.h>
  11074. +#include <linux/semaphore.h>
  11075. +
  11076. +#include "interface/vchi/vchi_cfg_internal.h"
  11077. +#include "interface/vchi/vchi_common.h"
  11078. +#include "interface/vchi/message_drivers/message.h"
  11079. +
  11080. +/******************************************************************************
  11081. + Global defs
  11082. + *****************************************************************************/
  11083. +
  11084. +// Opaque handle for a connection / service pair
  11085. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  11086. +
  11087. +// opaque handle to the connection state information
  11088. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  11089. +
  11090. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  11091. +
  11092. +
  11093. +/******************************************************************************
  11094. + API
  11095. + *****************************************************************************/
  11096. +
  11097. +// Routine to init a connection with a particular low level driver
  11098. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  11099. + const VCHI_MESSAGE_DRIVER_T * driver );
  11100. +
  11101. +// Routine to control CRC enabling at a connection level
  11102. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  11103. + VCHI_CRC_CONTROL_T control );
  11104. +
  11105. +// Routine to create a service
  11106. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  11107. + int32_t service_id,
  11108. + uint32_t rx_fifo_size,
  11109. + uint32_t tx_fifo_size,
  11110. + int server,
  11111. + VCHI_CALLBACK_T callback,
  11112. + void *callback_param,
  11113. + int32_t want_crc,
  11114. + int32_t want_unaligned_bulk_rx,
  11115. + int32_t want_unaligned_bulk_tx,
  11116. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  11117. +
  11118. +// Routine to close a service
  11119. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  11120. +
  11121. +// Routine to queue a message
  11122. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11123. + const void *data,
  11124. + uint32_t data_size,
  11125. + VCHI_FLAGS_T flags,
  11126. + void *msg_handle );
  11127. +
  11128. +// scatter-gather (vector) message queueing
  11129. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11130. + VCHI_MSG_VECTOR_T *vector,
  11131. + uint32_t count,
  11132. + VCHI_FLAGS_T flags,
  11133. + void *msg_handle );
  11134. +
  11135. +// Routine to dequeue a message
  11136. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11137. + void *data,
  11138. + uint32_t max_data_size_to_read,
  11139. + uint32_t *actual_msg_size,
  11140. + VCHI_FLAGS_T flags );
  11141. +
  11142. +// Routine to peek at a message
  11143. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11144. + void **data,
  11145. + uint32_t *msg_size,
  11146. + VCHI_FLAGS_T flags );
  11147. +
  11148. +// Routine to hold a message
  11149. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11150. + void **data,
  11151. + uint32_t *msg_size,
  11152. + VCHI_FLAGS_T flags,
  11153. + void **message_handle );
  11154. +
  11155. +// Routine to initialise a received message iterator
  11156. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11157. + VCHI_MSG_ITER_T *iter,
  11158. + VCHI_FLAGS_T flags );
  11159. +
  11160. +// Routine to release a held message
  11161. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11162. + void *message_handle );
  11163. +
  11164. +// Routine to get info on a held message
  11165. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11166. + void *message_handle,
  11167. + void **data,
  11168. + int32_t *msg_size,
  11169. + uint32_t *tx_timestamp,
  11170. + uint32_t *rx_timestamp );
  11171. +
  11172. +// Routine to check whether the iterator has a next message
  11173. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  11174. + const VCHI_MSG_ITER_T *iter );
  11175. +
  11176. +// Routine to advance the iterator
  11177. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  11178. + VCHI_MSG_ITER_T *iter,
  11179. + void **data,
  11180. + uint32_t *msg_size );
  11181. +
  11182. +// Routine to remove the last message returned by the iterator
  11183. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  11184. + VCHI_MSG_ITER_T *iter );
  11185. +
  11186. +// Routine to hold the last message returned by the iterator
  11187. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  11188. + VCHI_MSG_ITER_T *iter,
  11189. + void **msg_handle );
  11190. +
  11191. +// Routine to transmit bulk data
  11192. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11193. + const void *data_src,
  11194. + uint32_t data_size,
  11195. + VCHI_FLAGS_T flags,
  11196. + void *bulk_handle );
  11197. +
  11198. +// Routine to receive data
  11199. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  11200. + void *data_dst,
  11201. + uint32_t data_size,
  11202. + VCHI_FLAGS_T flags,
  11203. + void *bulk_handle );
  11204. +
  11205. +// Routine to report if a server is available
  11206. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  11207. +
  11208. +// Routine to report the number of RX slots available
  11209. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  11210. +
  11211. +// Routine to report the RX slot size
  11212. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  11213. +
  11214. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  11215. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  11216. + int32_t service,
  11217. + uint32_t length,
  11218. + MESSAGE_TX_CHANNEL_T channel,
  11219. + uint32_t channel_params,
  11220. + uint32_t data_length,
  11221. + uint32_t data_offset);
  11222. +
  11223. +// Callback to inform a service that a Xon or Xoff message has been received
  11224. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  11225. +
  11226. +// Callback to inform a service that a server available reply message has been received
  11227. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  11228. +
  11229. +// Callback to indicate that bulk auxiliary messages have arrived
  11230. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  11231. +
  11232. +// Callback to indicate that bulk auxiliary messages have arrived
  11233. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  11234. +
  11235. +// Callback with all the connection info you require
  11236. +typedef void (*VCHI_CONNECTION_INFO)(VCHI_CONNECTION_STATE_T *state, uint32_t protocol_version, uint32_t slot_size, uint32_t num_slots, uint32_t min_bulk_size);
  11237. +
  11238. +// Callback to inform of a disconnect
  11239. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  11240. +
  11241. +// Callback to inform of a power control request
  11242. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  11243. +
  11244. +// allocate memory suitably aligned for this connection
  11245. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  11246. +
  11247. +// free memory allocated by buffer_allocate
  11248. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  11249. +
  11250. +
  11251. +/******************************************************************************
  11252. + System driver struct
  11253. + *****************************************************************************/
  11254. +
  11255. +struct opaque_vchi_connection_api_t
  11256. +{
  11257. + // Routine to init the connection
  11258. + VCHI_CONNECTION_INIT_T init;
  11259. +
  11260. + // Connection-level CRC control
  11261. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  11262. +
  11263. + // Routine to connect to or create service
  11264. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  11265. +
  11266. + // Routine to disconnect from a service
  11267. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  11268. +
  11269. + // Routine to queue a message
  11270. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  11271. +
  11272. + // scatter-gather (vector) message queue
  11273. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  11274. +
  11275. + // Routine to dequeue a message
  11276. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  11277. +
  11278. + // Routine to peek at a message
  11279. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  11280. +
  11281. + // Routine to hold a message
  11282. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  11283. +
  11284. + // Routine to initialise a received message iterator
  11285. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  11286. +
  11287. + // Routine to release a message
  11288. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  11289. +
  11290. + // Routine to get information on a held message
  11291. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  11292. +
  11293. + // Routine to check for next message on iterator
  11294. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  11295. +
  11296. + // Routine to get next message on iterator
  11297. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  11298. +
  11299. + // Routine to remove the last message returned by iterator
  11300. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  11301. +
  11302. + // Routine to hold the last message returned by iterator
  11303. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  11304. +
  11305. + // Routine to transmit bulk data
  11306. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  11307. +
  11308. + // Routine to receive data
  11309. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  11310. +
  11311. + // Routine to report the available servers
  11312. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  11313. +
  11314. + // Routine to report the number of RX slots available
  11315. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  11316. +
  11317. + // Routine to report the RX slot size
  11318. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  11319. +
  11320. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  11321. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  11322. +
  11323. + // Callback to inform a service that a Xon or Xoff message has been received
  11324. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  11325. +
  11326. + // Callback to inform a service that a server available reply message has been received
  11327. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  11328. +
  11329. + // Callback to indicate that bulk auxiliary messages have arrived
  11330. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  11331. +
  11332. + // Callback to indicate that a bulk auxiliary message has been transmitted
  11333. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  11334. +
  11335. + // Callback to provide information about the connection
  11336. + VCHI_CONNECTION_INFO connection_info;
  11337. +
  11338. + // Callback to notify that peer has requested disconnect
  11339. + VCHI_CONNECTION_DISCONNECT disconnect;
  11340. +
  11341. + // Callback to notify that peer has requested power change
  11342. + VCHI_CONNECTION_POWER_CONTROL power_control;
  11343. +
  11344. + // allocate memory suitably aligned for this connection
  11345. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  11346. +
  11347. + // free memory allocated by buffer_allocate
  11348. + VCHI_BUFFER_FREE buffer_free;
  11349. +
  11350. +};
  11351. +
  11352. +struct vchi_connection_t {
  11353. + const VCHI_CONNECTION_API_T *api;
  11354. + VCHI_CONNECTION_STATE_T *state;
  11355. +#ifdef VCHI_COARSE_LOCKING
  11356. + struct semaphore sem;
  11357. +#endif
  11358. +};
  11359. +
  11360. +
  11361. +#endif /* CONNECTION_H_ */
  11362. +
  11363. +/****************************** End of file **********************************/
  11364. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  11365. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  11366. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-02-07 19:57:28.000000000 +0100
  11367. @@ -0,0 +1,204 @@
  11368. +/**
  11369. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  11370. + *
  11371. + * Redistribution and use in source and binary forms, with or without
  11372. + * modification, are permitted provided that the following conditions
  11373. + * are met:
  11374. + * 1. Redistributions of source code must retain the above copyright
  11375. + * notice, this list of conditions, and the following disclaimer,
  11376. + * without modification.
  11377. + * 2. Redistributions in binary form must reproduce the above copyright
  11378. + * notice, this list of conditions and the following disclaimer in the
  11379. + * documentation and/or other materials provided with the distribution.
  11380. + * 3. The names of the above-listed copyright holders may not be used
  11381. + * to endorse or promote products derived from this software without
  11382. + * specific prior written permission.
  11383. + *
  11384. + * ALTERNATIVELY, this software may be distributed under the terms of the
  11385. + * GNU General Public License ("GPL") version 2, as published by the Free
  11386. + * Software Foundation.
  11387. + *
  11388. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  11389. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  11390. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11391. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  11392. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  11393. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  11394. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  11395. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11396. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  11397. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  11398. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11399. + */
  11400. +
  11401. +#ifndef _VCHI_MESSAGE_H_
  11402. +#define _VCHI_MESSAGE_H_
  11403. +
  11404. +#include <linux/kernel.h>
  11405. +#include <linux/types.h>
  11406. +#include <linux/semaphore.h>
  11407. +
  11408. +#include "interface/vchi/vchi_cfg_internal.h"
  11409. +#include "interface/vchi/vchi_common.h"
  11410. +
  11411. +
  11412. +typedef enum message_event_type {
  11413. + MESSAGE_EVENT_NONE,
  11414. + MESSAGE_EVENT_NOP,
  11415. + MESSAGE_EVENT_MESSAGE,
  11416. + MESSAGE_EVENT_SLOT_COMPLETE,
  11417. + MESSAGE_EVENT_RX_BULK_PAUSED,
  11418. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  11419. + MESSAGE_EVENT_TX_COMPLETE,
  11420. + MESSAGE_EVENT_MSG_DISCARDED
  11421. +} MESSAGE_EVENT_TYPE_T;
  11422. +
  11423. +typedef enum vchi_msg_flags
  11424. +{
  11425. + VCHI_MSG_FLAGS_NONE = 0x0,
  11426. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  11427. +} VCHI_MSG_FLAGS_T;
  11428. +
  11429. +typedef enum message_tx_channel
  11430. +{
  11431. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  11432. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  11433. +} MESSAGE_TX_CHANNEL_T;
  11434. +
  11435. +// Macros used for cycling through bulk channels
  11436. +#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  11437. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  11438. +
  11439. +typedef enum message_rx_channel
  11440. +{
  11441. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  11442. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  11443. +} MESSAGE_RX_CHANNEL_T;
  11444. +
  11445. +// Message receive slot information
  11446. +typedef struct rx_msg_slot_info {
  11447. +
  11448. + struct rx_msg_slot_info *next;
  11449. + //struct slot_info *prev;
  11450. +#if !defined VCHI_COARSE_LOCKING
  11451. + struct semaphore sem;
  11452. +#endif
  11453. +
  11454. + uint8_t *addr; // base address of slot
  11455. + uint32_t len; // length of slot in bytes
  11456. +
  11457. + uint32_t write_ptr; // hardware causes this to advance
  11458. + uint32_t read_ptr; // this module does the reading
  11459. + int active; // is this slot in the hardware dma fifo?
  11460. + uint32_t msgs_parsed; // count how many messages are in this slot
  11461. + uint32_t msgs_released; // how many messages have been released
  11462. + void *state; // connection state information
  11463. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  11464. +} RX_MSG_SLOTINFO_T;
  11465. +
  11466. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  11467. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  11468. +// driver will be tasked with sending the aligned core section.
  11469. +typedef struct rx_bulk_slotinfo_t {
  11470. + struct rx_bulk_slotinfo_t *next;
  11471. +
  11472. + struct semaphore *blocking;
  11473. +
  11474. + // needed by DMA
  11475. + void *addr;
  11476. + uint32_t len;
  11477. +
  11478. + // needed for the callback
  11479. + void *service;
  11480. + void *handle;
  11481. + VCHI_FLAGS_T flags;
  11482. +} RX_BULK_SLOTINFO_T;
  11483. +
  11484. +
  11485. +/* ----------------------------------------------------------------------
  11486. + * each connection driver will have a pool of the following struct.
  11487. + *
  11488. + * the pool will be managed by vchi_qman_*
  11489. + * this means there will be multiple queues (single linked lists)
  11490. + * a given struct message_info will be on exactly one of these queues
  11491. + * at any one time
  11492. + * -------------------------------------------------------------------- */
  11493. +typedef struct rx_message_info {
  11494. +
  11495. + struct message_info *next;
  11496. + //struct message_info *prev;
  11497. +
  11498. + uint8_t *addr;
  11499. + uint32_t len;
  11500. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  11501. + uint32_t tx_timestamp;
  11502. + uint32_t rx_timestamp;
  11503. +
  11504. +} RX_MESSAGE_INFO_T;
  11505. +
  11506. +typedef struct {
  11507. + MESSAGE_EVENT_TYPE_T type;
  11508. +
  11509. + struct {
  11510. + // for messages
  11511. + void *addr; // address of message
  11512. + uint16_t slot_delta; // whether this message indicated slot delta
  11513. + uint32_t len; // length of message
  11514. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  11515. + int32_t service; // service id this message is destined for
  11516. + uint32_t tx_timestamp; // timestamp from the header
  11517. + uint32_t rx_timestamp; // timestamp when we parsed it
  11518. + } message;
  11519. +
  11520. + // FIXME: cleanup slot reporting...
  11521. + RX_MSG_SLOTINFO_T *rx_msg;
  11522. + RX_BULK_SLOTINFO_T *rx_bulk;
  11523. + void *tx_handle;
  11524. + MESSAGE_TX_CHANNEL_T tx_channel;
  11525. +
  11526. +} MESSAGE_EVENT_T;
  11527. +
  11528. +
  11529. +// callbacks
  11530. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  11531. +
  11532. +typedef struct {
  11533. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  11534. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  11535. +
  11536. +
  11537. +// handle to this instance of message driver (as returned by ->open)
  11538. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  11539. +
  11540. +struct opaque_vchi_message_driver_t {
  11541. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  11542. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  11543. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  11544. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  11545. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  11546. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  11547. + int32_t (*send)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, VCHI_MSG_FLAGS_T flags, void *send_handle ); // tx (message & bulk)
  11548. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  11549. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  11550. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  11551. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  11552. +
  11553. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  11554. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  11555. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  11556. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  11557. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  11558. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  11559. +
  11560. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  11561. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  11562. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  11563. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  11564. + void (*form_bulk_aux)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel, const void *data, uint32_t len, uint32_t chunk_size, const void **aux_data, int32_t *aux_len );
  11565. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  11566. +};
  11567. +
  11568. +
  11569. +#endif // _VCHI_MESSAGE_H_
  11570. +
  11571. +/****************************** End of file ***********************************/
  11572. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  11573. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  11574. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-02-07 19:57:28.000000000 +0100
  11575. @@ -0,0 +1,224 @@
  11576. +/**
  11577. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  11578. + *
  11579. + * Redistribution and use in source and binary forms, with or without
  11580. + * modification, are permitted provided that the following conditions
  11581. + * are met:
  11582. + * 1. Redistributions of source code must retain the above copyright
  11583. + * notice, this list of conditions, and the following disclaimer,
  11584. + * without modification.
  11585. + * 2. Redistributions in binary form must reproduce the above copyright
  11586. + * notice, this list of conditions and the following disclaimer in the
  11587. + * documentation and/or other materials provided with the distribution.
  11588. + * 3. The names of the above-listed copyright holders may not be used
  11589. + * to endorse or promote products derived from this software without
  11590. + * specific prior written permission.
  11591. + *
  11592. + * ALTERNATIVELY, this software may be distributed under the terms of the
  11593. + * GNU General Public License ("GPL") version 2, as published by the Free
  11594. + * Software Foundation.
  11595. + *
  11596. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  11597. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  11598. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11599. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  11600. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  11601. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  11602. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  11603. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11604. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  11605. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  11606. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11607. + */
  11608. +
  11609. +#ifndef VCHI_CFG_H_
  11610. +#define VCHI_CFG_H_
  11611. +
  11612. +/****************************************************************************************
  11613. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  11614. + * services.
  11615. + ***************************************************************************************/
  11616. +
  11617. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  11618. +/* Really determined by the message driver, and should be available from a run-time call. */
  11619. +#ifndef VCHI_BULK_ALIGN
  11620. +# if __VCCOREVER__ >= 0x04000000
  11621. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  11622. +# else
  11623. +# define VCHI_BULK_ALIGN 16
  11624. +# endif
  11625. +#endif
  11626. +
  11627. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  11628. +/* May be less than or greater than VCHI_BULK_ALIGN */
  11629. +/* Really determined by the message driver, and should be available from a run-time call. */
  11630. +#ifndef VCHI_BULK_GRANULARITY
  11631. +# if __VCCOREVER__ >= 0x04000000
  11632. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  11633. +# else
  11634. +# define VCHI_BULK_GRANULARITY 16
  11635. +# endif
  11636. +#endif
  11637. +
  11638. +/* The largest possible message to be queued with vchi_msg_queue. */
  11639. +#ifndef VCHI_MAX_MSG_SIZE
  11640. +# if defined VCHI_LOCAL_HOST_PORT
  11641. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  11642. +# else
  11643. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  11644. +# endif
  11645. +#endif
  11646. +
  11647. +/******************************************************************************************
  11648. + * Defines below are system configuration options, and should not be used by VCHI services.
  11649. + *****************************************************************************************/
  11650. +
  11651. +/* How many connections can we support? A localhost implementation uses 2 connections,
  11652. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  11653. + * driver. */
  11654. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  11655. +# define VCHI_MAX_NUM_CONNECTIONS 3
  11656. +#endif
  11657. +
  11658. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  11659. + * amount of static memory. */
  11660. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  11661. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  11662. +#endif
  11663. +
  11664. +/* Adjust if using a message driver that supports more logical TX channels */
  11665. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  11666. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  11667. +#endif
  11668. +
  11669. +/* Adjust if using a message driver that supports more logical RX channels */
  11670. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  11671. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  11672. +#endif
  11673. +
  11674. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  11675. + * receive queue space, less message headers. */
  11676. +#ifndef VCHI_NUM_READ_SLOTS
  11677. +# if defined(VCHI_LOCAL_HOST_PORT)
  11678. +# define VCHI_NUM_READ_SLOTS 4
  11679. +# else
  11680. +# define VCHI_NUM_READ_SLOTS 48
  11681. +# endif
  11682. +#endif
  11683. +
  11684. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  11685. + * performance. Only define on VideoCore end, talking to host.
  11686. + */
  11687. +//#define VCHI_MSG_RX_OVERRUN
  11688. +
  11689. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  11690. + * underneath VCHI will usually have its own buffering. */
  11691. +#ifndef VCHI_NUM_WRITE_SLOTS
  11692. +# define VCHI_NUM_WRITE_SLOTS 4
  11693. +#endif
  11694. +
  11695. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  11696. + * then it's taking up too much buffer space, and the peer service will be told to stop
  11697. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  11698. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  11699. + * is too high. */
  11700. +#ifndef VCHI_XOFF_THRESHOLD
  11701. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  11702. +#endif
  11703. +
  11704. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  11705. + * service has dequeued/released enough messages that it's now occupying
  11706. + * VCHI_XON_THRESHOLD slots or fewer. */
  11707. +#ifndef VCHI_XON_THRESHOLD
  11708. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  11709. +#endif
  11710. +
  11711. +/* A size below which a bulk transfer omits the handshake completely and always goes
  11712. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  11713. + * can guarantee this by enabling unaligned transmits).
  11714. + * Not API. */
  11715. +#ifndef VCHI_MIN_BULK_SIZE
  11716. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  11717. +#endif
  11718. +
  11719. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  11720. + * speed and latency; the smaller the chunk size the better change of messages and other
  11721. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  11722. + * break transmissions into chunks.
  11723. + */
  11724. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  11725. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  11726. +#endif
  11727. +
  11728. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  11729. + * with multiple-line frames. Only use if the receiver can cope. */
  11730. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  11731. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  11732. +#endif
  11733. +
  11734. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  11735. + * vchi_msg_queue will be blocked. */
  11736. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  11737. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  11738. +#endif
  11739. +
  11740. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  11741. + * will be suspended until older messages are dequeued/released. */
  11742. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  11743. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  11744. +#endif
  11745. +
  11746. +/* Really should be able to cope if we run out of received message descriptors, by
  11747. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  11748. + * under the carpet. */
  11749. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  11750. +# undef VCHI_RX_MSG_QUEUE_SIZE
  11751. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  11752. +#endif
  11753. +
  11754. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  11755. + * will be blocked. */
  11756. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  11757. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  11758. +#endif
  11759. +
  11760. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  11761. + * will be blocked. */
  11762. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  11763. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  11764. +#endif
  11765. +
  11766. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  11767. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  11768. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  11769. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  11770. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  11771. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  11772. +#endif
  11773. +
  11774. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  11775. + * transmitter on and off.
  11776. + */
  11777. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  11778. +
  11779. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  11780. +
  11781. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  11782. + * negative for no IDLE.
  11783. + */
  11784. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  11785. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  11786. +# endif
  11787. +
  11788. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  11789. + * negative for no OFF.
  11790. + */
  11791. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  11792. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  11793. +# endif
  11794. +
  11795. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  11796. +
  11797. +#endif /* VCHI_CFG_H_ */
  11798. +
  11799. +/****************************** End of file **********************************/
  11800. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  11801. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  11802. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-02-07 19:57:28.000000000 +0100
  11803. @@ -0,0 +1,71 @@
  11804. +/**
  11805. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  11806. + *
  11807. + * Redistribution and use in source and binary forms, with or without
  11808. + * modification, are permitted provided that the following conditions
  11809. + * are met:
  11810. + * 1. Redistributions of source code must retain the above copyright
  11811. + * notice, this list of conditions, and the following disclaimer,
  11812. + * without modification.
  11813. + * 2. Redistributions in binary form must reproduce the above copyright
  11814. + * notice, this list of conditions and the following disclaimer in the
  11815. + * documentation and/or other materials provided with the distribution.
  11816. + * 3. The names of the above-listed copyright holders may not be used
  11817. + * to endorse or promote products derived from this software without
  11818. + * specific prior written permission.
  11819. + *
  11820. + * ALTERNATIVELY, this software may be distributed under the terms of the
  11821. + * GNU General Public License ("GPL") version 2, as published by the Free
  11822. + * Software Foundation.
  11823. + *
  11824. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  11825. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  11826. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11827. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  11828. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  11829. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  11830. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  11831. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11832. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  11833. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  11834. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11835. + */
  11836. +
  11837. +#ifndef VCHI_CFG_INTERNAL_H_
  11838. +#define VCHI_CFG_INTERNAL_H_
  11839. +
  11840. +/****************************************************************************************
  11841. + * Control optimisation attempts.
  11842. + ***************************************************************************************/
  11843. +
  11844. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  11845. +#define VCHI_COARSE_LOCKING
  11846. +
  11847. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  11848. +// (only relevant if VCHI_COARSE_LOCKING)
  11849. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  11850. +
  11851. +// Avoid lock on non-blocking peek
  11852. +// (only relevant if VCHI_COARSE_LOCKING)
  11853. +#define VCHI_AVOID_PEEK_LOCK
  11854. +
  11855. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  11856. +#define VCHI_MULTIPLE_HANDLER_THREADS
  11857. +
  11858. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  11859. +// our way through the pool of descriptors.
  11860. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  11861. +
  11862. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  11863. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  11864. +
  11865. +// Don't use message descriptors for TX messages that don't need them
  11866. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  11867. +
  11868. +// Nano-locks for multiqueue
  11869. +//#define VCHI_MQUEUE_NANOLOCKS
  11870. +
  11871. +// Lock-free(er) dequeuing
  11872. +//#define VCHI_RX_NANOLOCKS
  11873. +
  11874. +#endif /*VCHI_CFG_INTERNAL_H_*/
  11875. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  11876. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  11877. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-02-07 19:57:28.000000000 +0100
  11878. @@ -0,0 +1,163 @@
  11879. +/**
  11880. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  11881. + *
  11882. + * Redistribution and use in source and binary forms, with or without
  11883. + * modification, are permitted provided that the following conditions
  11884. + * are met:
  11885. + * 1. Redistributions of source code must retain the above copyright
  11886. + * notice, this list of conditions, and the following disclaimer,
  11887. + * without modification.
  11888. + * 2. Redistributions in binary form must reproduce the above copyright
  11889. + * notice, this list of conditions and the following disclaimer in the
  11890. + * documentation and/or other materials provided with the distribution.
  11891. + * 3. The names of the above-listed copyright holders may not be used
  11892. + * to endorse or promote products derived from this software without
  11893. + * specific prior written permission.
  11894. + *
  11895. + * ALTERNATIVELY, this software may be distributed under the terms of the
  11896. + * GNU General Public License ("GPL") version 2, as published by the Free
  11897. + * Software Foundation.
  11898. + *
  11899. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  11900. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  11901. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11902. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  11903. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  11904. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  11905. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  11906. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11907. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  11908. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  11909. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  11910. + */
  11911. +
  11912. +#ifndef VCHI_COMMON_H_
  11913. +#define VCHI_COMMON_H_
  11914. +
  11915. +
  11916. +//flags used when sending messages (must be bitmapped)
  11917. +typedef enum
  11918. +{
  11919. + VCHI_FLAGS_NONE = 0x0,
  11920. + VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE = 0x1, // waits for message to be received, or sent (NB. not the same as being seen on other side)
  11921. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  11922. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  11923. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  11924. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  11925. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  11926. +
  11927. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  11928. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  11929. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  11930. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  11931. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  11932. + VCHI_FLAGS_INTERNAL = 0xFF0000
  11933. +} VCHI_FLAGS_T;
  11934. +
  11935. +// constants for vchi_crc_control()
  11936. +typedef enum {
  11937. + VCHI_CRC_NOTHING = -1,
  11938. + VCHI_CRC_PER_SERVICE = 0,
  11939. + VCHI_CRC_EVERYTHING = 1,
  11940. +} VCHI_CRC_CONTROL_T;
  11941. +
  11942. +//callback reasons when an event occurs on a service
  11943. +typedef enum
  11944. +{
  11945. + VCHI_CALLBACK_REASON_MIN,
  11946. +
  11947. + //This indicates that there is data available
  11948. + //handle is the msg id that was transmitted with the data
  11949. + // When a message is received and there was no FULL message available previously, send callback
  11950. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  11951. + VCHI_CALLBACK_MSG_AVAILABLE,
  11952. + VCHI_CALLBACK_MSG_SENT,
  11953. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  11954. +
  11955. + // This indicates that a transfer from the other side has completed
  11956. + VCHI_CALLBACK_BULK_RECEIVED,
  11957. + //This indicates that data queued up to be sent has now gone
  11958. + //handle is the msg id that was used when sending the data
  11959. + VCHI_CALLBACK_BULK_SENT,
  11960. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  11961. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  11962. +
  11963. + VCHI_CALLBACK_SERVICE_CLOSED,
  11964. +
  11965. + // this side has sent XOFF to peer due to lack of data consumption by service
  11966. + // (suggests the service may need to take some recovery action if it has
  11967. + // been deliberately holding off consuming data)
  11968. + VCHI_CALLBACK_SENT_XOFF,
  11969. + VCHI_CALLBACK_SENT_XON,
  11970. +
  11971. + // indicates that a bulk transfer has finished reading the source buffer
  11972. + VCHI_CALLBACK_BULK_DATA_READ,
  11973. +
  11974. + // power notification events (currently host side only)
  11975. + VCHI_CALLBACK_PEER_OFF,
  11976. + VCHI_CALLBACK_PEER_SUSPENDED,
  11977. + VCHI_CALLBACK_PEER_ON,
  11978. + VCHI_CALLBACK_PEER_RESUMED,
  11979. + VCHI_CALLBACK_FORCED_POWER_OFF,
  11980. +
  11981. +#ifdef USE_VCHIQ_ARM
  11982. + // some extra notifications provided by vchiq_arm
  11983. + VCHI_CALLBACK_SERVICE_OPENED,
  11984. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  11985. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  11986. +#endif
  11987. +
  11988. + VCHI_CALLBACK_REASON_MAX
  11989. +} VCHI_CALLBACK_REASON_T;
  11990. +
  11991. +//Calback used by all services / bulk transfers
  11992. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  11993. + VCHI_CALLBACK_REASON_T reason,
  11994. + void *handle ); //for transmitting msg's only
  11995. +
  11996. +
  11997. +
  11998. +/*
  11999. + * Define vector struct for scatter-gather (vector) operations
  12000. + * Vectors can be nested - if a vector element has negative length, then
  12001. + * the data pointer is treated as pointing to another vector array, with
  12002. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  12003. + * you can do this:
  12004. + *
  12005. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  12006. + * {
  12007. + * VCHI_MSG_VECTOR_T nv[2];
  12008. + * nv[0].vec_base = my_header;
  12009. + * nv[0].vec_len = sizeof my_header;
  12010. + * nv[1].vec_base = v;
  12011. + * nv[1].vec_len = -n;
  12012. + * ...
  12013. + *
  12014. + */
  12015. +typedef struct vchi_msg_vector {
  12016. + const void *vec_base;
  12017. + int32_t vec_len;
  12018. +} VCHI_MSG_VECTOR_T;
  12019. +
  12020. +// Opaque type for a connection API
  12021. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  12022. +
  12023. +// Opaque type for a message driver
  12024. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  12025. +
  12026. +
  12027. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  12028. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  12029. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  12030. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  12031. +// is used again after messages for that service are removed/dequeued by any
  12032. +// means other than vchi_msg_iter_... calls on the iterator itself.
  12033. +typedef struct {
  12034. + struct opaque_vchi_service_t *service;
  12035. + void *last;
  12036. + void *next;
  12037. + void *remove;
  12038. +} VCHI_MSG_ITER_T;
  12039. +
  12040. +
  12041. +#endif // VCHI_COMMON_H_
  12042. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi.h
  12043. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  12044. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-02-07 19:57:28.000000000 +0100
  12045. @@ -0,0 +1,373 @@
  12046. +/**
  12047. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  12048. + *
  12049. + * Redistribution and use in source and binary forms, with or without
  12050. + * modification, are permitted provided that the following conditions
  12051. + * are met:
  12052. + * 1. Redistributions of source code must retain the above copyright
  12053. + * notice, this list of conditions, and the following disclaimer,
  12054. + * without modification.
  12055. + * 2. Redistributions in binary form must reproduce the above copyright
  12056. + * notice, this list of conditions and the following disclaimer in the
  12057. + * documentation and/or other materials provided with the distribution.
  12058. + * 3. The names of the above-listed copyright holders may not be used
  12059. + * to endorse or promote products derived from this software without
  12060. + * specific prior written permission.
  12061. + *
  12062. + * ALTERNATIVELY, this software may be distributed under the terms of the
  12063. + * GNU General Public License ("GPL") version 2, as published by the Free
  12064. + * Software Foundation.
  12065. + *
  12066. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  12067. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  12068. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  12069. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  12070. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  12071. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12072. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  12073. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  12074. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  12075. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  12076. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  12077. + */
  12078. +
  12079. +#ifndef VCHI_H_
  12080. +#define VCHI_H_
  12081. +
  12082. +#include "interface/vchi/vchi_cfg.h"
  12083. +#include "interface/vchi/vchi_common.h"
  12084. +#include "interface/vchi/connections/connection.h"
  12085. +#include "vchi_mh.h"
  12086. +
  12087. +
  12088. +/******************************************************************************
  12089. + Global defs
  12090. + *****************************************************************************/
  12091. +
  12092. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  12093. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  12094. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  12095. +
  12096. +#ifdef USE_VCHIQ_ARM
  12097. +#define VCHI_BULK_ALIGNED(x) 1
  12098. +#else
  12099. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  12100. +#endif
  12101. +
  12102. +struct vchi_version {
  12103. + uint32_t version;
  12104. + uint32_t version_min;
  12105. +};
  12106. +#define VCHI_VERSION(v_) { v_, v_ }
  12107. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  12108. +
  12109. +typedef enum
  12110. +{
  12111. + VCHI_VEC_POINTER,
  12112. + VCHI_VEC_HANDLE,
  12113. + VCHI_VEC_LIST
  12114. +} VCHI_MSG_VECTOR_TYPE_T;
  12115. +
  12116. +typedef struct vchi_msg_vector_ex {
  12117. +
  12118. + VCHI_MSG_VECTOR_TYPE_T type;
  12119. + union
  12120. + {
  12121. + // a memory handle
  12122. + struct
  12123. + {
  12124. + VCHI_MEM_HANDLE_T handle;
  12125. + uint32_t offset;
  12126. + int32_t vec_len;
  12127. + } handle;
  12128. +
  12129. + // an ordinary data pointer
  12130. + struct
  12131. + {
  12132. + const void *vec_base;
  12133. + int32_t vec_len;
  12134. + } ptr;
  12135. +
  12136. + // a nested vector list
  12137. + struct
  12138. + {
  12139. + struct vchi_msg_vector_ex *vec;
  12140. + uint32_t vec_len;
  12141. + } list;
  12142. + } u;
  12143. +} VCHI_MSG_VECTOR_EX_T;
  12144. +
  12145. +
  12146. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  12147. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  12148. +
  12149. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  12150. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  12151. +
  12152. +// Macros to manipulate 'FOURCC' values
  12153. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  12154. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  12155. +
  12156. +
  12157. +// Opaque service information
  12158. +struct opaque_vchi_service_t;
  12159. +
  12160. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  12161. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  12162. +typedef struct
  12163. +{
  12164. + struct opaque_vchi_service_t *service;
  12165. + void *message;
  12166. +} VCHI_HELD_MSG_T;
  12167. +
  12168. +
  12169. +
  12170. +// structure used to provide the information needed to open a server or a client
  12171. +typedef struct {
  12172. + struct vchi_version version;
  12173. + int32_t service_id;
  12174. + VCHI_CONNECTION_T *connection;
  12175. + uint32_t rx_fifo_size;
  12176. + uint32_t tx_fifo_size;
  12177. + VCHI_CALLBACK_T callback;
  12178. + void *callback_param;
  12179. + /* client intends to receive bulk transfers of
  12180. + odd lengths or into unaligned buffers */
  12181. + int32_t want_unaligned_bulk_rx;
  12182. + /* client intends to transmit bulk transfers of
  12183. + odd lengths or out of unaligned buffers */
  12184. + int32_t want_unaligned_bulk_tx;
  12185. + /* client wants to check CRCs on (bulk) xfers.
  12186. + Only needs to be set at 1 end - will do both directions. */
  12187. + int32_t want_crc;
  12188. +} SERVICE_CREATION_T;
  12189. +
  12190. +// Opaque handle for a VCHI instance
  12191. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  12192. +
  12193. +// Opaque handle for a server or client
  12194. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  12195. +
  12196. +// Service registration & startup
  12197. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  12198. +
  12199. +typedef struct service_info_tag {
  12200. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  12201. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  12202. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  12203. +} SERVICE_INFO_T;
  12204. +
  12205. +/******************************************************************************
  12206. + Global funcs - implementation is specific to which side you are on (local / remote)
  12207. + *****************************************************************************/
  12208. +
  12209. +#ifdef __cplusplus
  12210. +extern "C" {
  12211. +#endif
  12212. +
  12213. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  12214. + const VCHI_MESSAGE_DRIVER_T * low_level);
  12215. +
  12216. +
  12217. +// Routine used to initialise the vchi on both local + remote connections
  12218. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  12219. +
  12220. +extern int32_t vchi_exit( void );
  12221. +
  12222. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  12223. + const uint32_t num_connections,
  12224. + VCHI_INSTANCE_T instance_handle );
  12225. +
  12226. +//When this is called, ensure that all services have no data pending.
  12227. +//Bulk transfers can remain 'queued'
  12228. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  12229. +
  12230. +// Global control over bulk CRC checking
  12231. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  12232. + VCHI_CRC_CONTROL_T control );
  12233. +
  12234. +// helper functions
  12235. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  12236. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  12237. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  12238. +
  12239. +
  12240. +/******************************************************************************
  12241. + Global service API
  12242. + *****************************************************************************/
  12243. +// Routine to create a named service
  12244. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  12245. + SERVICE_CREATION_T *setup,
  12246. + VCHI_SERVICE_HANDLE_T *handle );
  12247. +
  12248. +// Routine to destory a service
  12249. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  12250. +
  12251. +// Routine to open a named service
  12252. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  12253. + SERVICE_CREATION_T *setup,
  12254. + VCHI_SERVICE_HANDLE_T *handle);
  12255. +
  12256. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  12257. + short *peer_version );
  12258. +
  12259. +// Routine to close a named service
  12260. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  12261. +
  12262. +// Routine to increment ref count on a named service
  12263. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  12264. +
  12265. +// Routine to decrement ref count on a named service
  12266. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  12267. +
  12268. +// Routine to send a message accross a service
  12269. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  12270. + const void *data,
  12271. + uint32_t data_size,
  12272. + VCHI_FLAGS_T flags,
  12273. + void *msg_handle );
  12274. +
  12275. +// scatter-gather (vector) and send message
  12276. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  12277. + VCHI_MSG_VECTOR_EX_T *vector,
  12278. + uint32_t count,
  12279. + VCHI_FLAGS_T flags,
  12280. + void *msg_handle );
  12281. +
  12282. +// legacy scatter-gather (vector) and send message, only handles pointers
  12283. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  12284. + VCHI_MSG_VECTOR_T *vector,
  12285. + uint32_t count,
  12286. + VCHI_FLAGS_T flags,
  12287. + void *msg_handle );
  12288. +
  12289. +// Routine to receive a msg from a service
  12290. +// Dequeue is equivalent to hold, copy into client buffer, release
  12291. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  12292. + void *data,
  12293. + uint32_t max_data_size_to_read,
  12294. + uint32_t *actual_msg_size,
  12295. + VCHI_FLAGS_T flags );
  12296. +
  12297. +// Routine to look at a message in place.
  12298. +// The message is not dequeued, so a subsequent call to peek or dequeue
  12299. +// will return the same message.
  12300. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  12301. + void **data,
  12302. + uint32_t *msg_size,
  12303. + VCHI_FLAGS_T flags );
  12304. +
  12305. +// Routine to remove a message after it has been read in place with peek
  12306. +// The first message on the queue is dequeued.
  12307. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  12308. +
  12309. +// Routine to look at a message in place.
  12310. +// The message is dequeued, so the caller is left holding it; the descriptor is
  12311. +// filled in and must be released when the user has finished with the message.
  12312. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  12313. + void **data, // } may be NULL, as info can be
  12314. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  12315. + VCHI_FLAGS_T flags,
  12316. + VCHI_HELD_MSG_T *message_descriptor );
  12317. +
  12318. +// Initialise an iterator to look through messages in place
  12319. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  12320. + VCHI_MSG_ITER_T *iter,
  12321. + VCHI_FLAGS_T flags );
  12322. +
  12323. +/******************************************************************************
  12324. + Global service support API - operations on held messages and message iterators
  12325. + *****************************************************************************/
  12326. +
  12327. +// Routine to get the address of a held message
  12328. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  12329. +
  12330. +// Routine to get the size of a held message
  12331. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  12332. +
  12333. +// Routine to get the transmit timestamp as written into the header by the peer
  12334. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  12335. +
  12336. +// Routine to get the reception timestamp, written as we parsed the header
  12337. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  12338. +
  12339. +// Routine to release a held message after it has been processed
  12340. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  12341. +
  12342. +// Indicates whether the iterator has a next message.
  12343. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  12344. +
  12345. +// Return the pointer and length for the next message and advance the iterator.
  12346. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  12347. + void **data,
  12348. + uint32_t *msg_size );
  12349. +
  12350. +// Remove the last message returned by vchi_msg_iter_next.
  12351. +// Can only be called once after each call to vchi_msg_iter_next.
  12352. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  12353. +
  12354. +// Hold the last message returned by vchi_msg_iter_next.
  12355. +// Can only be called once after each call to vchi_msg_iter_next.
  12356. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  12357. + VCHI_HELD_MSG_T *message );
  12358. +
  12359. +// Return information for the next message, and hold it, advancing the iterator.
  12360. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  12361. + void **data, // } may be NULL
  12362. + uint32_t *msg_size, // }
  12363. + VCHI_HELD_MSG_T *message );
  12364. +
  12365. +
  12366. +/******************************************************************************
  12367. + Global bulk API
  12368. + *****************************************************************************/
  12369. +
  12370. +// Routine to prepare interface for a transfer from the other side
  12371. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  12372. + void *data_dst,
  12373. + uint32_t data_size,
  12374. + VCHI_FLAGS_T flags,
  12375. + void *transfer_handle );
  12376. +
  12377. +
  12378. +// Prepare interface for a transfer from the other side into relocatable memory.
  12379. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  12380. + VCHI_MEM_HANDLE_T h_dst,
  12381. + uint32_t offset,
  12382. + uint32_t data_size,
  12383. + const VCHI_FLAGS_T flags,
  12384. + void * const bulk_handle );
  12385. +
  12386. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  12387. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  12388. + const void *data_src,
  12389. + uint32_t data_size,
  12390. + VCHI_FLAGS_T flags,
  12391. + void *transfer_handle );
  12392. +
  12393. +
  12394. +/******************************************************************************
  12395. + Configuration plumbing
  12396. + *****************************************************************************/
  12397. +
  12398. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  12399. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  12400. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  12401. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  12402. +
  12403. +// declare all message drivers here
  12404. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  12405. +
  12406. +#ifdef __cplusplus
  12407. +}
  12408. +#endif
  12409. +
  12410. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  12411. + VCHI_MEM_HANDLE_T h_src,
  12412. + uint32_t offset,
  12413. + uint32_t data_size,
  12414. + VCHI_FLAGS_T flags,
  12415. + void *transfer_handle );
  12416. +#endif /* VCHI_H_ */
  12417. +
  12418. +/****************************** End of file **********************************/
  12419. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  12420. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  12421. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-02-07 19:57:28.000000000 +0100
  12422. @@ -0,0 +1,42 @@
  12423. +/**
  12424. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  12425. + *
  12426. + * Redistribution and use in source and binary forms, with or without
  12427. + * modification, are permitted provided that the following conditions
  12428. + * are met:
  12429. + * 1. Redistributions of source code must retain the above copyright
  12430. + * notice, this list of conditions, and the following disclaimer,
  12431. + * without modification.
  12432. + * 2. Redistributions in binary form must reproduce the above copyright
  12433. + * notice, this list of conditions and the following disclaimer in the
  12434. + * documentation and/or other materials provided with the distribution.
  12435. + * 3. The names of the above-listed copyright holders may not be used
  12436. + * to endorse or promote products derived from this software without
  12437. + * specific prior written permission.
  12438. + *
  12439. + * ALTERNATIVELY, this software may be distributed under the terms of the
  12440. + * GNU General Public License ("GPL") version 2, as published by the Free
  12441. + * Software Foundation.
  12442. + *
  12443. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  12444. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  12445. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  12446. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  12447. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  12448. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12449. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  12450. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  12451. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  12452. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  12453. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  12454. + */
  12455. +
  12456. +#ifndef VCHI_MH_H_
  12457. +#define VCHI_MH_H_
  12458. +
  12459. +#include <linux/types.h>
  12460. +
  12461. +typedef int32_t VCHI_MEM_HANDLE_T;
  12462. +#define VCHI_MEM_HANDLE_INVALID 0
  12463. +
  12464. +#endif
  12465. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  12466. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  12467. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-02-07 19:57:28.000000000 +0100
  12468. @@ -0,0 +1,538 @@
  12469. +/**
  12470. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  12471. + *
  12472. + * Redistribution and use in source and binary forms, with or without
  12473. + * modification, are permitted provided that the following conditions
  12474. + * are met:
  12475. + * 1. Redistributions of source code must retain the above copyright
  12476. + * notice, this list of conditions, and the following disclaimer,
  12477. + * without modification.
  12478. + * 2. Redistributions in binary form must reproduce the above copyright
  12479. + * notice, this list of conditions and the following disclaimer in the
  12480. + * documentation and/or other materials provided with the distribution.
  12481. + * 3. The names of the above-listed copyright holders may not be used
  12482. + * to endorse or promote products derived from this software without
  12483. + * specific prior written permission.
  12484. + *
  12485. + * ALTERNATIVELY, this software may be distributed under the terms of the
  12486. + * GNU General Public License ("GPL") version 2, as published by the Free
  12487. + * Software Foundation.
  12488. + *
  12489. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  12490. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  12491. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  12492. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  12493. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  12494. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12495. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  12496. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  12497. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  12498. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  12499. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  12500. + */
  12501. +
  12502. +#include <linux/kernel.h>
  12503. +#include <linux/types.h>
  12504. +#include <linux/errno.h>
  12505. +#include <linux/interrupt.h>
  12506. +#include <linux/irq.h>
  12507. +#include <linux/pagemap.h>
  12508. +#include <linux/dma-mapping.h>
  12509. +#include <linux/version.h>
  12510. +#include <linux/io.h>
  12511. +#include <linux/uaccess.h>
  12512. +#include <asm/pgtable.h>
  12513. +
  12514. +#include <mach/irqs.h>
  12515. +
  12516. +#include <mach/platform.h>
  12517. +#include <mach/vcio.h>
  12518. +
  12519. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  12520. +
  12521. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  12522. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  12523. +
  12524. +#include "vchiq_arm.h"
  12525. +#include "vchiq_2835.h"
  12526. +#include "vchiq_connected.h"
  12527. +
  12528. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  12529. +
  12530. +typedef struct vchiq_2835_state_struct {
  12531. + int inited;
  12532. + VCHIQ_ARM_STATE_T arm_state;
  12533. +} VCHIQ_2835_ARM_STATE_T;
  12534. +
  12535. +static char *g_slot_mem;
  12536. +static int g_slot_mem_size;
  12537. +dma_addr_t g_slot_phys;
  12538. +static FRAGMENTS_T *g_fragments_base;
  12539. +static FRAGMENTS_T *g_free_fragments;
  12540. +struct semaphore g_free_fragments_sema;
  12541. +
  12542. +extern int vchiq_arm_log_level;
  12543. +
  12544. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  12545. +
  12546. +static irqreturn_t
  12547. +vchiq_doorbell_irq(int irq, void *dev_id);
  12548. +
  12549. +static int
  12550. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  12551. + struct task_struct *task, PAGELIST_T ** ppagelist);
  12552. +
  12553. +static void
  12554. +free_pagelist(PAGELIST_T *pagelist, int actual);
  12555. +
  12556. +int __init
  12557. +vchiq_platform_init(VCHIQ_STATE_T *state)
  12558. +{
  12559. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  12560. + int frag_mem_size;
  12561. + int err;
  12562. + int i;
  12563. +
  12564. + /* Allocate space for the channels in coherent memory */
  12565. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  12566. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  12567. +
  12568. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  12569. + &g_slot_phys, GFP_ATOMIC);
  12570. +
  12571. + if (!g_slot_mem) {
  12572. + vchiq_log_error(vchiq_arm_log_level,
  12573. + "Unable to allocate channel memory");
  12574. + err = -ENOMEM;
  12575. + goto failed_alloc;
  12576. + }
  12577. +
  12578. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  12579. +
  12580. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  12581. + if (!vchiq_slot_zero) {
  12582. + err = -EINVAL;
  12583. + goto failed_init_slots;
  12584. + }
  12585. +
  12586. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  12587. + (int)g_slot_phys + g_slot_mem_size;
  12588. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  12589. + MAX_FRAGMENTS;
  12590. +
  12591. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  12592. + g_slot_mem_size += frag_mem_size;
  12593. +
  12594. + g_free_fragments = g_fragments_base;
  12595. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  12596. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  12597. + &g_fragments_base[i + 1];
  12598. + }
  12599. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  12600. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  12601. +
  12602. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  12603. + VCHIQ_SUCCESS) {
  12604. + err = -EINVAL;
  12605. + goto failed_vchiq_init;
  12606. + }
  12607. +
  12608. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  12609. + IRQF_IRQPOLL, "VCHIQ doorbell",
  12610. + state);
  12611. + if (err < 0) {
  12612. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  12613. + "irq=%d err=%d", __func__,
  12614. + VCHIQ_DOORBELL_IRQ, err);
  12615. + goto failed_request_irq;
  12616. + }
  12617. +
  12618. + /* Send the base address of the slots to VideoCore */
  12619. +
  12620. + dsb(); /* Ensure all writes have completed */
  12621. +
  12622. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  12623. +
  12624. + vchiq_log_info(vchiq_arm_log_level,
  12625. + "vchiq_init - done (slots %x, phys %x)",
  12626. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  12627. +
  12628. + vchiq_call_connected_callbacks();
  12629. +
  12630. + return 0;
  12631. +
  12632. +failed_request_irq:
  12633. +failed_vchiq_init:
  12634. +failed_init_slots:
  12635. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  12636. +
  12637. +failed_alloc:
  12638. + return err;
  12639. +}
  12640. +
  12641. +void __exit
  12642. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  12643. +{
  12644. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  12645. + dma_free_coherent(NULL, g_slot_mem_size,
  12646. + g_slot_mem, g_slot_phys);
  12647. +}
  12648. +
  12649. +
  12650. +VCHIQ_STATUS_T
  12651. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  12652. +{
  12653. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  12654. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  12655. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  12656. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  12657. + if(status != VCHIQ_SUCCESS)
  12658. + {
  12659. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  12660. + }
  12661. + return status;
  12662. +}
  12663. +
  12664. +VCHIQ_ARM_STATE_T*
  12665. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  12666. +{
  12667. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  12668. + {
  12669. + BUG();
  12670. + }
  12671. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  12672. +}
  12673. +
  12674. +void
  12675. +remote_event_signal(REMOTE_EVENT_T *event)
  12676. +{
  12677. + wmb();
  12678. +
  12679. + event->fired = 1;
  12680. +
  12681. + dsb(); /* data barrier operation */
  12682. +
  12683. + if (event->armed) {
  12684. + /* trigger vc interrupt */
  12685. +
  12686. + writel(0, __io_address(ARM_0_BELL2));
  12687. + }
  12688. +}
  12689. +
  12690. +int
  12691. +vchiq_copy_from_user(void *dst, const void *src, int size)
  12692. +{
  12693. + if ((uint32_t)src < TASK_SIZE) {
  12694. + return copy_from_user(dst, src, size);
  12695. + } else {
  12696. + memcpy(dst, src, size);
  12697. + return 0;
  12698. + }
  12699. +}
  12700. +
  12701. +VCHIQ_STATUS_T
  12702. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  12703. + void *offset, int size, int dir)
  12704. +{
  12705. + PAGELIST_T *pagelist;
  12706. + int ret;
  12707. +
  12708. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  12709. +
  12710. + ret = create_pagelist((char __user *)offset, size,
  12711. + (dir == VCHIQ_BULK_RECEIVE)
  12712. + ? PAGELIST_READ
  12713. + : PAGELIST_WRITE,
  12714. + current,
  12715. + &pagelist);
  12716. + if (ret != 0)
  12717. + return VCHIQ_ERROR;
  12718. +
  12719. + bulk->handle = memhandle;
  12720. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  12721. +
  12722. + /* Store the pagelist address in remote_data, which isn't used by the
  12723. + slave. */
  12724. + bulk->remote_data = pagelist;
  12725. +
  12726. + return VCHIQ_SUCCESS;
  12727. +}
  12728. +
  12729. +void
  12730. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  12731. +{
  12732. + if (bulk && bulk->remote_data && bulk->actual)
  12733. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  12734. +}
  12735. +
  12736. +void
  12737. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  12738. +{
  12739. + /*
  12740. + * This should only be called on the master (VideoCore) side, but
  12741. + * provide an implementation to avoid the need for ifdefery.
  12742. + */
  12743. + BUG();
  12744. +}
  12745. +
  12746. +void
  12747. +vchiq_dump_platform_state(void *dump_context)
  12748. +{
  12749. + char buf[80];
  12750. + int len;
  12751. + len = snprintf(buf, sizeof(buf),
  12752. + " Platform: 2835 (VC master)");
  12753. + vchiq_dump(dump_context, buf, len + 1);
  12754. +}
  12755. +
  12756. +VCHIQ_STATUS_T
  12757. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  12758. +{
  12759. + return VCHIQ_ERROR;
  12760. +}
  12761. +
  12762. +VCHIQ_STATUS_T
  12763. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  12764. +{
  12765. + return VCHIQ_SUCCESS;
  12766. +}
  12767. +
  12768. +void
  12769. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  12770. +{
  12771. +}
  12772. +
  12773. +void
  12774. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  12775. +{
  12776. +}
  12777. +
  12778. +int
  12779. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  12780. +{
  12781. + return 1; // autosuspend not supported - videocore always wanted
  12782. +}
  12783. +
  12784. +int
  12785. +vchiq_platform_use_suspend_timer(void)
  12786. +{
  12787. + return 0;
  12788. +}
  12789. +void
  12790. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  12791. +{
  12792. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  12793. +}
  12794. +void
  12795. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  12796. +{
  12797. + (void)state;
  12798. +}
  12799. +/*
  12800. + * Local functions
  12801. + */
  12802. +
  12803. +static irqreturn_t
  12804. +vchiq_doorbell_irq(int irq, void *dev_id)
  12805. +{
  12806. + VCHIQ_STATE_T *state = dev_id;
  12807. + irqreturn_t ret = IRQ_NONE;
  12808. + unsigned int status;
  12809. +
  12810. + /* Read (and clear) the doorbell */
  12811. + status = readl(__io_address(ARM_0_BELL0));
  12812. +
  12813. + if (status & 0x4) { /* Was the doorbell rung? */
  12814. + remote_event_pollall(state);
  12815. + ret = IRQ_HANDLED;
  12816. + }
  12817. +
  12818. + return ret;
  12819. +}
  12820. +
  12821. +/* There is a potential problem with partial cache lines (pages?)
  12822. +** at the ends of the block when reading. If the CPU accessed anything in
  12823. +** the same line (page?) then it may have pulled old data into the cache,
  12824. +** obscuring the new data underneath. We can solve this by transferring the
  12825. +** partial cache lines separately, and allowing the ARM to copy into the
  12826. +** cached area.
  12827. +
  12828. +** N.B. This implementation plays slightly fast and loose with the Linux
  12829. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  12830. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  12831. +** from increased speed as a result.
  12832. +*/
  12833. +
  12834. +static int
  12835. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  12836. + struct task_struct *task, PAGELIST_T ** ppagelist)
  12837. +{
  12838. + PAGELIST_T *pagelist;
  12839. + struct page **pages;
  12840. + struct page *page;
  12841. + unsigned long *addrs;
  12842. + unsigned int num_pages, offset, i;
  12843. + char *addr, *base_addr, *next_addr;
  12844. + int run, addridx, actual_pages;
  12845. +
  12846. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  12847. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  12848. +
  12849. + *ppagelist = NULL;
  12850. +
  12851. + /* Allocate enough storage to hold the page pointers and the page
  12852. + ** list
  12853. + */
  12854. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  12855. + (num_pages * sizeof(unsigned long)) +
  12856. + (num_pages * sizeof(pages[0])),
  12857. + GFP_KERNEL);
  12858. +
  12859. + vchiq_log_trace(vchiq_arm_log_level,
  12860. + "create_pagelist - %x", (unsigned int)pagelist);
  12861. + if (!pagelist)
  12862. + return -ENOMEM;
  12863. +
  12864. + addrs = pagelist->addrs;
  12865. + pages = (struct page **)(addrs + num_pages);
  12866. +
  12867. + down_read(&task->mm->mmap_sem);
  12868. + actual_pages = get_user_pages(task, task->mm,
  12869. + (unsigned long)buf & ~(PAGE_SIZE - 1), num_pages,
  12870. + (type == PAGELIST_READ) /*Write */ , 0 /*Force */ ,
  12871. + pages, NULL /*vmas */);
  12872. + up_read(&task->mm->mmap_sem);
  12873. +
  12874. + if (actual_pages != num_pages)
  12875. + {
  12876. + /* This is probably due to the process being killed */
  12877. + while (actual_pages > 0)
  12878. + {
  12879. + actual_pages--;
  12880. + page_cache_release(pages[actual_pages]);
  12881. + }
  12882. + kfree(pagelist);
  12883. + if (actual_pages == 0)
  12884. + actual_pages = -ENOMEM;
  12885. + return actual_pages;
  12886. + }
  12887. +
  12888. + pagelist->length = count;
  12889. + pagelist->type = type;
  12890. + pagelist->offset = offset;
  12891. +
  12892. + /* Group the pages into runs of contiguous pages */
  12893. +
  12894. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  12895. + next_addr = base_addr + PAGE_SIZE;
  12896. + addridx = 0;
  12897. + run = 0;
  12898. +
  12899. + for (i = 1; i < num_pages; i++) {
  12900. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  12901. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  12902. + next_addr += PAGE_SIZE;
  12903. + run++;
  12904. + } else {
  12905. + addrs[addridx] = (unsigned long)base_addr + run;
  12906. + addridx++;
  12907. + base_addr = addr;
  12908. + next_addr = addr + PAGE_SIZE;
  12909. + run = 0;
  12910. + }
  12911. + }
  12912. +
  12913. + addrs[addridx] = (unsigned long)base_addr + run;
  12914. + addridx++;
  12915. +
  12916. + /* Partial cache lines (fragments) require special measures */
  12917. + if ((type == PAGELIST_READ) &&
  12918. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  12919. + ((pagelist->offset + pagelist->length) &
  12920. + (CACHE_LINE_SIZE - 1)))) {
  12921. + FRAGMENTS_T *fragments;
  12922. +
  12923. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  12924. + kfree(pagelist);
  12925. + return -EINTR;
  12926. + }
  12927. +
  12928. + WARN_ON(g_free_fragments == NULL);
  12929. +
  12930. + down(&g_free_fragments_mutex);
  12931. + fragments = (FRAGMENTS_T *) g_free_fragments;
  12932. + WARN_ON(fragments == NULL);
  12933. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  12934. + up(&g_free_fragments_mutex);
  12935. + pagelist->type =
  12936. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  12937. + g_fragments_base);
  12938. + }
  12939. +
  12940. + for (page = virt_to_page(pagelist);
  12941. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  12942. + flush_dcache_page(page);
  12943. + }
  12944. +
  12945. + *ppagelist = pagelist;
  12946. +
  12947. + return 0;
  12948. +}
  12949. +
  12950. +static void
  12951. +free_pagelist(PAGELIST_T *pagelist, int actual)
  12952. +{
  12953. + struct page **pages;
  12954. + unsigned int num_pages, i;
  12955. +
  12956. + vchiq_log_trace(vchiq_arm_log_level,
  12957. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  12958. +
  12959. + num_pages =
  12960. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  12961. + PAGE_SIZE;
  12962. +
  12963. + pages = (struct page **)(pagelist->addrs + num_pages);
  12964. +
  12965. + /* Deal with any partial cache lines (fragments) */
  12966. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  12967. + FRAGMENTS_T *fragments = g_fragments_base +
  12968. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  12969. + int head_bytes, tail_bytes;
  12970. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  12971. + (CACHE_LINE_SIZE - 1);
  12972. + tail_bytes = (pagelist->offset + actual) &
  12973. + (CACHE_LINE_SIZE - 1);
  12974. +
  12975. + if ((actual >= 0) && (head_bytes != 0)) {
  12976. + if (head_bytes > actual)
  12977. + head_bytes = actual;
  12978. +
  12979. + memcpy((char *)page_address(pages[0]) +
  12980. + pagelist->offset,
  12981. + fragments->headbuf,
  12982. + head_bytes);
  12983. + }
  12984. + if ((actual >= 0) && (head_bytes < actual) &&
  12985. + (tail_bytes != 0)) {
  12986. + memcpy((char *)page_address(pages[num_pages - 1]) +
  12987. + ((pagelist->offset + actual) &
  12988. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  12989. + fragments->tailbuf, tail_bytes);
  12990. + }
  12991. +
  12992. + down(&g_free_fragments_mutex);
  12993. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  12994. + g_free_fragments = fragments;
  12995. + up(&g_free_fragments_mutex);
  12996. + up(&g_free_fragments_sema);
  12997. + }
  12998. +
  12999. + for (i = 0; i < num_pages; i++) {
  13000. + if (pagelist->type != PAGELIST_WRITE)
  13001. + set_page_dirty(pages[i]);
  13002. + page_cache_release(pages[i]);
  13003. + }
  13004. +
  13005. + kfree(pagelist);
  13006. +}
  13007. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  13008. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  13009. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-02-07 19:57:28.000000000 +0100
  13010. @@ -0,0 +1,42 @@
  13011. +/**
  13012. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  13013. + *
  13014. + * Redistribution and use in source and binary forms, with or without
  13015. + * modification, are permitted provided that the following conditions
  13016. + * are met:
  13017. + * 1. Redistributions of source code must retain the above copyright
  13018. + * notice, this list of conditions, and the following disclaimer,
  13019. + * without modification.
  13020. + * 2. Redistributions in binary form must reproduce the above copyright
  13021. + * notice, this list of conditions and the following disclaimer in the
  13022. + * documentation and/or other materials provided with the distribution.
  13023. + * 3. The names of the above-listed copyright holders may not be used
  13024. + * to endorse or promote products derived from this software without
  13025. + * specific prior written permission.
  13026. + *
  13027. + * ALTERNATIVELY, this software may be distributed under the terms of the
  13028. + * GNU General Public License ("GPL") version 2, as published by the Free
  13029. + * Software Foundation.
  13030. + *
  13031. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  13032. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  13033. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13034. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  13035. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  13036. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  13037. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  13038. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  13039. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  13040. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  13041. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13042. + */
  13043. +
  13044. +#ifndef VCHIQ_2835_H
  13045. +#define VCHIQ_2835_H
  13046. +
  13047. +#include "vchiq_pagelist.h"
  13048. +
  13049. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  13050. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  13051. +
  13052. +#endif /* VCHIQ_2835_H */
  13053. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  13054. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  13055. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-02-07 19:57:28.000000000 +0100
  13056. @@ -0,0 +1,2813 @@
  13057. +/**
  13058. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  13059. + *
  13060. + * Redistribution and use in source and binary forms, with or without
  13061. + * modification, are permitted provided that the following conditions
  13062. + * are met:
  13063. + * 1. Redistributions of source code must retain the above copyright
  13064. + * notice, this list of conditions, and the following disclaimer,
  13065. + * without modification.
  13066. + * 2. Redistributions in binary form must reproduce the above copyright
  13067. + * notice, this list of conditions and the following disclaimer in the
  13068. + * documentation and/or other materials provided with the distribution.
  13069. + * 3. The names of the above-listed copyright holders may not be used
  13070. + * to endorse or promote products derived from this software without
  13071. + * specific prior written permission.
  13072. + *
  13073. + * ALTERNATIVELY, this software may be distributed under the terms of the
  13074. + * GNU General Public License ("GPL") version 2, as published by the Free
  13075. + * Software Foundation.
  13076. + *
  13077. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  13078. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  13079. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  13080. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  13081. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  13082. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  13083. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  13084. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  13085. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  13086. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  13087. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13088. + */
  13089. +
  13090. +#include <linux/kernel.h>
  13091. +#include <linux/module.h>
  13092. +#include <linux/types.h>
  13093. +#include <linux/errno.h>
  13094. +#include <linux/cdev.h>
  13095. +#include <linux/fs.h>
  13096. +#include <linux/device.h>
  13097. +#include <linux/mm.h>
  13098. +#include <linux/highmem.h>
  13099. +#include <linux/pagemap.h>
  13100. +#include <linux/bug.h>
  13101. +#include <linux/semaphore.h>
  13102. +#include <linux/list.h>
  13103. +#include <linux/proc_fs.h>
  13104. +
  13105. +#include "vchiq_core.h"
  13106. +#include "vchiq_ioctl.h"
  13107. +#include "vchiq_arm.h"
  13108. +
  13109. +#define DEVICE_NAME "vchiq"
  13110. +
  13111. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  13112. +#undef MODULE_PARAM_PREFIX
  13113. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  13114. +
  13115. +#define VCHIQ_MINOR 0
  13116. +
  13117. +/* Some per-instance constants */
  13118. +#define MAX_COMPLETIONS 16
  13119. +#define MAX_SERVICES 64
  13120. +#define MAX_ELEMENTS 8
  13121. +#define MSG_QUEUE_SIZE 64
  13122. +
  13123. +#define KEEPALIVE_VER 1
  13124. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  13125. +
  13126. +/* Run time control of log level, based on KERN_XXX level. */
  13127. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  13128. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  13129. +
  13130. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  13131. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  13132. +
  13133. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  13134. +static const char *const suspend_state_names[] = {
  13135. + "VC_SUSPEND_FORCE_CANCELED",
  13136. + "VC_SUSPEND_REJECTED",
  13137. + "VC_SUSPEND_FAILED",
  13138. + "VC_SUSPEND_IDLE",
  13139. + "VC_SUSPEND_REQUESTED",
  13140. + "VC_SUSPEND_IN_PROGRESS",
  13141. + "VC_SUSPEND_SUSPENDED"
  13142. +};
  13143. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  13144. +static const char *const resume_state_names[] = {
  13145. + "VC_RESUME_FAILED",
  13146. + "VC_RESUME_IDLE",
  13147. + "VC_RESUME_REQUESTED",
  13148. + "VC_RESUME_IN_PROGRESS",
  13149. + "VC_RESUME_RESUMED"
  13150. +};
  13151. +/* The number of times we allow force suspend to timeout before actually
  13152. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  13153. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  13154. +*/
  13155. +#define FORCE_SUSPEND_FAIL_MAX 8
  13156. +
  13157. +/* The time in ms allowed for videocore to go idle when force suspend has been
  13158. + * requested */
  13159. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  13160. +
  13161. +
  13162. +static void suspend_timer_callback(unsigned long context);
  13163. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  13164. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  13165. +
  13166. +
  13167. +typedef struct user_service_struct {
  13168. + VCHIQ_SERVICE_T *service;
  13169. + void *userdata;
  13170. + VCHIQ_INSTANCE_T instance;
  13171. + int is_vchi;
  13172. + int dequeue_pending;
  13173. + int message_available_pos;
  13174. + int msg_insert;
  13175. + int msg_remove;
  13176. + struct semaphore insert_event;
  13177. + struct semaphore remove_event;
  13178. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  13179. +} USER_SERVICE_T;
  13180. +
  13181. +struct bulk_waiter_node {
  13182. + struct bulk_waiter bulk_waiter;
  13183. + int pid;
  13184. + struct list_head list;
  13185. +};
  13186. +
  13187. +struct vchiq_instance_struct {
  13188. + VCHIQ_STATE_T *state;
  13189. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  13190. + int completion_insert;
  13191. + int completion_remove;
  13192. + struct semaphore insert_event;
  13193. + struct semaphore remove_event;
  13194. + struct mutex completion_mutex;
  13195. +
  13196. + int connected;
  13197. + int closing;
  13198. + int pid;
  13199. + int mark;
  13200. +
  13201. + struct list_head bulk_waiter_list;
  13202. + struct mutex bulk_waiter_list_mutex;
  13203. +
  13204. + struct proc_dir_entry *proc_entry;
  13205. +};
  13206. +
  13207. +typedef struct dump_context_struct {
  13208. + char __user *buf;
  13209. + size_t actual;
  13210. + size_t space;
  13211. + loff_t offset;
  13212. +} DUMP_CONTEXT_T;
  13213. +
  13214. +static struct cdev vchiq_cdev;
  13215. +static dev_t vchiq_devid;
  13216. +static VCHIQ_STATE_T g_state;
  13217. +static struct class *vchiq_class;
  13218. +static struct device *vchiq_dev;
  13219. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  13220. +
  13221. +static const char *const ioctl_names[] = {
  13222. + "CONNECT",
  13223. + "SHUTDOWN",
  13224. + "CREATE_SERVICE",
  13225. + "REMOVE_SERVICE",
  13226. + "QUEUE_MESSAGE",
  13227. + "QUEUE_BULK_TRANSMIT",
  13228. + "QUEUE_BULK_RECEIVE",
  13229. + "AWAIT_COMPLETION",
  13230. + "DEQUEUE_MESSAGE",
  13231. + "GET_CLIENT_ID",
  13232. + "GET_CONFIG",
  13233. + "CLOSE_SERVICE",
  13234. + "USE_SERVICE",
  13235. + "RELEASE_SERVICE",
  13236. + "SET_SERVICE_OPTION",
  13237. + "DUMP_PHYS_MEM"
  13238. +};
  13239. +
  13240. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  13241. + (VCHIQ_IOC_MAX + 1));
  13242. +
  13243. +static void
  13244. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  13245. +
  13246. +/****************************************************************************
  13247. +*
  13248. +* add_completion
  13249. +*
  13250. +***************************************************************************/
  13251. +
  13252. +static VCHIQ_STATUS_T
  13253. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  13254. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  13255. + void *bulk_userdata)
  13256. +{
  13257. + VCHIQ_COMPLETION_DATA_T *completion;
  13258. + DEBUG_INITIALISE(g_state.local)
  13259. +
  13260. + while (instance->completion_insert ==
  13261. + (instance->completion_remove + MAX_COMPLETIONS)) {
  13262. + /* Out of space - wait for the client */
  13263. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13264. + vchiq_log_trace(vchiq_arm_log_level,
  13265. + "add_completion - completion queue full");
  13266. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  13267. + if (down_interruptible(&instance->remove_event) != 0) {
  13268. + vchiq_log_info(vchiq_arm_log_level,
  13269. + "service_callback interrupted");
  13270. + return VCHIQ_RETRY;
  13271. + } else if (instance->closing) {
  13272. + vchiq_log_info(vchiq_arm_log_level,
  13273. + "service_callback closing");
  13274. + return VCHIQ_ERROR;
  13275. + }
  13276. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13277. + }
  13278. +
  13279. + completion =
  13280. + &instance->completions[instance->completion_insert &
  13281. + (MAX_COMPLETIONS - 1)];
  13282. +
  13283. + completion->header = header;
  13284. + completion->reason = reason;
  13285. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  13286. + completion->service_userdata = user_service->service;
  13287. + completion->bulk_userdata = bulk_userdata;
  13288. +
  13289. + if (reason == VCHIQ_SERVICE_CLOSED)
  13290. + /* Take an extra reference, to be held until
  13291. + this CLOSED notification is delivered. */
  13292. + lock_service(user_service->service);
  13293. +
  13294. + /* A write barrier is needed here to ensure that the entire completion
  13295. + record is written out before the insert point. */
  13296. + wmb();
  13297. +
  13298. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  13299. + user_service->message_available_pos =
  13300. + instance->completion_insert;
  13301. + instance->completion_insert++;
  13302. +
  13303. + up(&instance->insert_event);
  13304. +
  13305. + return VCHIQ_SUCCESS;
  13306. +}
  13307. +
  13308. +/****************************************************************************
  13309. +*
  13310. +* service_callback
  13311. +*
  13312. +***************************************************************************/
  13313. +
  13314. +static VCHIQ_STATUS_T
  13315. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  13316. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  13317. +{
  13318. + /* How do we ensure the callback goes to the right client?
  13319. + ** The service_user data points to a USER_SERVICE_T record containing
  13320. + ** the original callback and the user state structure, which contains a
  13321. + ** circular buffer for completion records.
  13322. + */
  13323. + USER_SERVICE_T *user_service;
  13324. + VCHIQ_SERVICE_T *service;
  13325. + VCHIQ_INSTANCE_T instance;
  13326. + DEBUG_INITIALISE(g_state.local)
  13327. +
  13328. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13329. +
  13330. + service = handle_to_service(handle);
  13331. + BUG_ON(!service);
  13332. + user_service = (USER_SERVICE_T *)service->base.userdata;
  13333. + instance = user_service->instance;
  13334. +
  13335. + if (!instance || instance->closing)
  13336. + return VCHIQ_SUCCESS;
  13337. +
  13338. + vchiq_log_trace(vchiq_arm_log_level,
  13339. + "service_callback - service %lx(%d), reason %d, header %lx, "
  13340. + "instance %lx, bulk_userdata %lx",
  13341. + (unsigned long)user_service,
  13342. + service->localport,
  13343. + reason, (unsigned long)header,
  13344. + (unsigned long)instance, (unsigned long)bulk_userdata);
  13345. +
  13346. + if (header && user_service->is_vchi) {
  13347. + spin_lock(&msg_queue_spinlock);
  13348. + while (user_service->msg_insert ==
  13349. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  13350. + spin_unlock(&msg_queue_spinlock);
  13351. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13352. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  13353. + vchiq_log_trace(vchiq_arm_log_level,
  13354. + "service_callback - msg queue full");
  13355. + /* If there is no MESSAGE_AVAILABLE in the completion
  13356. + ** queue, add one
  13357. + */
  13358. + if ((user_service->message_available_pos -
  13359. + instance->completion_remove) < 0) {
  13360. + VCHIQ_STATUS_T status;
  13361. + vchiq_log_info(vchiq_arm_log_level,
  13362. + "Inserting extra MESSAGE_AVAILABLE");
  13363. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13364. + status = add_completion(instance, reason,
  13365. + NULL, user_service, bulk_userdata);
  13366. + if (status != VCHIQ_SUCCESS) {
  13367. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13368. + return status;
  13369. + }
  13370. + }
  13371. +
  13372. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13373. + if (down_interruptible(&user_service->remove_event)
  13374. + != 0) {
  13375. + vchiq_log_info(vchiq_arm_log_level,
  13376. + "service_callback interrupted");
  13377. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13378. + return VCHIQ_RETRY;
  13379. + } else if (instance->closing) {
  13380. + vchiq_log_info(vchiq_arm_log_level,
  13381. + "service_callback closing");
  13382. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13383. + return VCHIQ_ERROR;
  13384. + }
  13385. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13386. + spin_lock(&msg_queue_spinlock);
  13387. + }
  13388. +
  13389. + user_service->msg_queue[user_service->msg_insert &
  13390. + (MSG_QUEUE_SIZE - 1)] = header;
  13391. + user_service->msg_insert++;
  13392. + spin_unlock(&msg_queue_spinlock);
  13393. +
  13394. + up(&user_service->insert_event);
  13395. +
  13396. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  13397. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  13398. + ** bypass the completion queue.
  13399. + */
  13400. + if (((user_service->message_available_pos -
  13401. + instance->completion_remove) >= 0) ||
  13402. + user_service->dequeue_pending) {
  13403. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13404. + user_service->dequeue_pending = 0;
  13405. + return VCHIQ_SUCCESS;
  13406. + }
  13407. +
  13408. + header = NULL;
  13409. + }
  13410. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  13411. +
  13412. + return add_completion(instance, reason, header, user_service,
  13413. + bulk_userdata);
  13414. +}
  13415. +
  13416. +/****************************************************************************
  13417. +*
  13418. +* user_service_free
  13419. +*
  13420. +***************************************************************************/
  13421. +static void
  13422. +user_service_free(void *userdata)
  13423. +{
  13424. + kfree(userdata);
  13425. +}
  13426. +
  13427. +/****************************************************************************
  13428. +*
  13429. +* vchiq_ioctl
  13430. +*
  13431. +***************************************************************************/
  13432. +
  13433. +static long
  13434. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  13435. +{
  13436. + VCHIQ_INSTANCE_T instance = file->private_data;
  13437. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  13438. + VCHIQ_SERVICE_T *service = NULL;
  13439. + long ret = 0;
  13440. + int i, rc;
  13441. + DEBUG_INITIALISE(g_state.local)
  13442. +
  13443. + vchiq_log_trace(vchiq_arm_log_level,
  13444. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  13445. + (unsigned int)instance,
  13446. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  13447. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  13448. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  13449. +
  13450. + switch (cmd) {
  13451. + case VCHIQ_IOC_SHUTDOWN:
  13452. + if (!instance->connected)
  13453. + break;
  13454. +
  13455. + /* Remove all services */
  13456. + i = 0;
  13457. + while ((service = next_service_by_instance(instance->state,
  13458. + instance, &i)) != NULL) {
  13459. + status = vchiq_remove_service(service->handle);
  13460. + unlock_service(service);
  13461. + if (status != VCHIQ_SUCCESS)
  13462. + break;
  13463. + }
  13464. + service = NULL;
  13465. +
  13466. + if (status == VCHIQ_SUCCESS) {
  13467. + /* Wake the completion thread and ask it to exit */
  13468. + instance->closing = 1;
  13469. + up(&instance->insert_event);
  13470. + }
  13471. +
  13472. + break;
  13473. +
  13474. + case VCHIQ_IOC_CONNECT:
  13475. + if (instance->connected) {
  13476. + ret = -EINVAL;
  13477. + break;
  13478. + }
  13479. + rc = mutex_lock_interruptible(&instance->state->mutex);
  13480. + if (rc != 0) {
  13481. + vchiq_log_error(vchiq_arm_log_level,
  13482. + "vchiq: connect: could not lock mutex for "
  13483. + "state %d: %d",
  13484. + instance->state->id, rc);
  13485. + ret = -EINTR;
  13486. + break;
  13487. + }
  13488. + status = vchiq_connect_internal(instance->state, instance);
  13489. + mutex_unlock(&instance->state->mutex);
  13490. +
  13491. + if (status == VCHIQ_SUCCESS)
  13492. + instance->connected = 1;
  13493. + else
  13494. + vchiq_log_error(vchiq_arm_log_level,
  13495. + "vchiq: could not connect: %d", status);
  13496. + break;
  13497. +
  13498. + case VCHIQ_IOC_CREATE_SERVICE: {
  13499. + VCHIQ_CREATE_SERVICE_T args;
  13500. + USER_SERVICE_T *user_service = NULL;
  13501. + void *userdata;
  13502. + int srvstate;
  13503. +
  13504. + if (copy_from_user
  13505. + (&args, (const void __user *)arg,
  13506. + sizeof(args)) != 0) {
  13507. + ret = -EFAULT;
  13508. + break;
  13509. + }
  13510. +
  13511. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  13512. + if (!user_service) {
  13513. + ret = -ENOMEM;
  13514. + break;
  13515. + }
  13516. +
  13517. + if (args.is_open) {
  13518. + if (!instance->connected) {
  13519. + ret = -ENOTCONN;
  13520. + kfree(user_service);
  13521. + break;
  13522. + }
  13523. + srvstate = VCHIQ_SRVSTATE_OPENING;
  13524. + } else {
  13525. + srvstate =
  13526. + instance->connected ?
  13527. + VCHIQ_SRVSTATE_LISTENING :
  13528. + VCHIQ_SRVSTATE_HIDDEN;
  13529. + }
  13530. +
  13531. + userdata = args.params.userdata;
  13532. + args.params.callback = service_callback;
  13533. + args.params.userdata = user_service;
  13534. + service = vchiq_add_service_internal(
  13535. + instance->state,
  13536. + &args.params, srvstate,
  13537. + instance, user_service_free);
  13538. +
  13539. + if (service != NULL) {
  13540. + user_service->service = service;
  13541. + user_service->userdata = userdata;
  13542. + user_service->instance = instance;
  13543. + user_service->is_vchi = args.is_vchi;
  13544. + user_service->dequeue_pending = 0;
  13545. + user_service->message_available_pos =
  13546. + instance->completion_remove - 1;
  13547. + user_service->msg_insert = 0;
  13548. + user_service->msg_remove = 0;
  13549. + sema_init(&user_service->insert_event, 0);
  13550. + sema_init(&user_service->remove_event, 0);
  13551. +
  13552. + if (args.is_open) {
  13553. + status = vchiq_open_service_internal
  13554. + (service, instance->pid);
  13555. + if (status != VCHIQ_SUCCESS) {
  13556. + vchiq_remove_service(service->handle);
  13557. + service = NULL;
  13558. + ret = (status == VCHIQ_RETRY) ?
  13559. + -EINTR : -EIO;
  13560. + break;
  13561. + }
  13562. + }
  13563. +
  13564. + if (copy_to_user((void __user *)
  13565. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  13566. + arg)->handle),
  13567. + (const void *)&service->handle,
  13568. + sizeof(service->handle)) != 0) {
  13569. + ret = -EFAULT;
  13570. + vchiq_remove_service(service->handle);
  13571. + }
  13572. +
  13573. + service = NULL;
  13574. + } else {
  13575. + ret = -EEXIST;
  13576. + kfree(user_service);
  13577. + }
  13578. + } break;
  13579. +
  13580. + case VCHIQ_IOC_CLOSE_SERVICE: {
  13581. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  13582. +
  13583. + service = find_service_for_instance(instance, handle);
  13584. + if (service != NULL)
  13585. + status = vchiq_close_service(service->handle);
  13586. + else
  13587. + ret = -EINVAL;
  13588. + } break;
  13589. +
  13590. + case VCHIQ_IOC_REMOVE_SERVICE: {
  13591. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  13592. +
  13593. + service = find_service_for_instance(instance, handle);
  13594. + if (service != NULL)
  13595. + status = vchiq_remove_service(service->handle);
  13596. + else
  13597. + ret = -EINVAL;
  13598. + } break;
  13599. +
  13600. + case VCHIQ_IOC_USE_SERVICE:
  13601. + case VCHIQ_IOC_RELEASE_SERVICE: {
  13602. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  13603. +
  13604. + service = find_service_for_instance(instance, handle);
  13605. + if (service != NULL) {
  13606. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  13607. + vchiq_use_service_internal(service) :
  13608. + vchiq_release_service_internal(service);
  13609. + if (status != VCHIQ_SUCCESS) {
  13610. + vchiq_log_error(vchiq_susp_log_level,
  13611. + "%s: cmd %s returned error %d for "
  13612. + "service %c%c%c%c:%03d",
  13613. + __func__,
  13614. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  13615. + "VCHIQ_IOC_USE_SERVICE" :
  13616. + "VCHIQ_IOC_RELEASE_SERVICE",
  13617. + status,
  13618. + VCHIQ_FOURCC_AS_4CHARS(
  13619. + service->base.fourcc),
  13620. + service->client_id);
  13621. + ret = -EINVAL;
  13622. + }
  13623. + } else
  13624. + ret = -EINVAL;
  13625. + } break;
  13626. +
  13627. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  13628. + VCHIQ_QUEUE_MESSAGE_T args;
  13629. + if (copy_from_user
  13630. + (&args, (const void __user *)arg,
  13631. + sizeof(args)) != 0) {
  13632. + ret = -EFAULT;
  13633. + break;
  13634. + }
  13635. +
  13636. + service = find_service_for_instance(instance, args.handle);
  13637. +
  13638. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  13639. + /* Copy elements into kernel space */
  13640. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  13641. + if (copy_from_user(elements, args.elements,
  13642. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  13643. + status = vchiq_queue_message
  13644. + (args.handle,
  13645. + elements, args.count);
  13646. + else
  13647. + ret = -EFAULT;
  13648. + } else {
  13649. + ret = -EINVAL;
  13650. + }
  13651. + } break;
  13652. +
  13653. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  13654. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  13655. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  13656. + struct bulk_waiter_node *waiter = NULL;
  13657. + VCHIQ_BULK_DIR_T dir =
  13658. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  13659. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  13660. +
  13661. + if (copy_from_user
  13662. + (&args, (const void __user *)arg,
  13663. + sizeof(args)) != 0) {
  13664. + ret = -EFAULT;
  13665. + break;
  13666. + }
  13667. +
  13668. + service = find_service_for_instance(instance, args.handle);
  13669. + if (!service) {
  13670. + ret = -EINVAL;
  13671. + break;
  13672. + }
  13673. +
  13674. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  13675. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  13676. + GFP_KERNEL);
  13677. + if (!waiter) {
  13678. + ret = -ENOMEM;
  13679. + break;
  13680. + }
  13681. + args.userdata = &waiter->bulk_waiter;
  13682. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  13683. + struct list_head *pos;
  13684. + mutex_lock(&instance->bulk_waiter_list_mutex);
  13685. + list_for_each(pos, &instance->bulk_waiter_list) {
  13686. + if (list_entry(pos, struct bulk_waiter_node,
  13687. + list)->pid == current->pid) {
  13688. + waiter = list_entry(pos,
  13689. + struct bulk_waiter_node,
  13690. + list);
  13691. + list_del(pos);
  13692. + break;
  13693. + }
  13694. +
  13695. + }
  13696. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  13697. + if (!waiter) {
  13698. + vchiq_log_error(vchiq_arm_log_level,
  13699. + "no bulk_waiter found for pid %d",
  13700. + current->pid);
  13701. + ret = -ESRCH;
  13702. + break;
  13703. + }
  13704. + vchiq_log_info(vchiq_arm_log_level,
  13705. + "found bulk_waiter %x for pid %d",
  13706. + (unsigned int)waiter, current->pid);
  13707. + args.userdata = &waiter->bulk_waiter;
  13708. + }
  13709. + status = vchiq_bulk_transfer
  13710. + (args.handle,
  13711. + VCHI_MEM_HANDLE_INVALID,
  13712. + args.data, args.size,
  13713. + args.userdata, args.mode,
  13714. + dir);
  13715. + if (!waiter)
  13716. + break;
  13717. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  13718. + !waiter->bulk_waiter.bulk) {
  13719. + if (waiter->bulk_waiter.bulk) {
  13720. + /* Cancel the signal when the transfer
  13721. + ** completes. */
  13722. + spin_lock(&bulk_waiter_spinlock);
  13723. + waiter->bulk_waiter.bulk->userdata = NULL;
  13724. + spin_unlock(&bulk_waiter_spinlock);
  13725. + }
  13726. + kfree(waiter);
  13727. + } else {
  13728. + const VCHIQ_BULK_MODE_T mode_waiting =
  13729. + VCHIQ_BULK_MODE_WAITING;
  13730. + waiter->pid = current->pid;
  13731. + mutex_lock(&instance->bulk_waiter_list_mutex);
  13732. + list_add(&waiter->list, &instance->bulk_waiter_list);
  13733. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  13734. + vchiq_log_info(vchiq_arm_log_level,
  13735. + "saved bulk_waiter %x for pid %d",
  13736. + (unsigned int)waiter, current->pid);
  13737. +
  13738. + if (copy_to_user((void __user *)
  13739. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  13740. + arg)->mode),
  13741. + (const void *)&mode_waiting,
  13742. + sizeof(mode_waiting)) != 0)
  13743. + ret = -EFAULT;
  13744. + }
  13745. + } break;
  13746. +
  13747. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  13748. + VCHIQ_AWAIT_COMPLETION_T args;
  13749. +
  13750. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13751. + if (!instance->connected) {
  13752. + ret = -ENOTCONN;
  13753. + break;
  13754. + }
  13755. +
  13756. + if (copy_from_user(&args, (const void __user *)arg,
  13757. + sizeof(args)) != 0) {
  13758. + ret = -EFAULT;
  13759. + break;
  13760. + }
  13761. +
  13762. + mutex_lock(&instance->completion_mutex);
  13763. +
  13764. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13765. + while ((instance->completion_remove ==
  13766. + instance->completion_insert)
  13767. + && !instance->closing) {
  13768. + int rc;
  13769. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13770. + mutex_unlock(&instance->completion_mutex);
  13771. + rc = down_interruptible(&instance->insert_event);
  13772. + mutex_lock(&instance->completion_mutex);
  13773. + if (rc != 0) {
  13774. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13775. + vchiq_log_info(vchiq_arm_log_level,
  13776. + "AWAIT_COMPLETION interrupted");
  13777. + ret = -EINTR;
  13778. + break;
  13779. + }
  13780. + }
  13781. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13782. +
  13783. + /* A read memory barrier is needed to stop prefetch of a stale
  13784. + ** completion record
  13785. + */
  13786. + rmb();
  13787. +
  13788. + if (ret == 0) {
  13789. + int msgbufcount = args.msgbufcount;
  13790. + for (ret = 0; ret < args.count; ret++) {
  13791. + VCHIQ_COMPLETION_DATA_T *completion;
  13792. + VCHIQ_SERVICE_T *service;
  13793. + USER_SERVICE_T *user_service;
  13794. + VCHIQ_HEADER_T *header;
  13795. + if (instance->completion_remove ==
  13796. + instance->completion_insert)
  13797. + break;
  13798. + completion = &instance->completions[
  13799. + instance->completion_remove &
  13800. + (MAX_COMPLETIONS - 1)];
  13801. +
  13802. + service = completion->service_userdata;
  13803. + user_service = service->base.userdata;
  13804. + completion->service_userdata =
  13805. + user_service->userdata;
  13806. +
  13807. + header = completion->header;
  13808. + if (header) {
  13809. + void __user *msgbuf;
  13810. + int msglen;
  13811. +
  13812. + msglen = header->size +
  13813. + sizeof(VCHIQ_HEADER_T);
  13814. + /* This must be a VCHIQ-style service */
  13815. + if (args.msgbufsize < msglen) {
  13816. + vchiq_log_error(
  13817. + vchiq_arm_log_level,
  13818. + "header %x: msgbufsize"
  13819. + " %x < msglen %x",
  13820. + (unsigned int)header,
  13821. + args.msgbufsize,
  13822. + msglen);
  13823. + WARN(1, "invalid message "
  13824. + "size\n");
  13825. + if (ret == 0)
  13826. + ret = -EMSGSIZE;
  13827. + break;
  13828. + }
  13829. + if (msgbufcount <= 0)
  13830. + /* Stall here for lack of a
  13831. + ** buffer for the message. */
  13832. + break;
  13833. + /* Get the pointer from user space */
  13834. + msgbufcount--;
  13835. + if (copy_from_user(&msgbuf,
  13836. + (const void __user *)
  13837. + &args.msgbufs[msgbufcount],
  13838. + sizeof(msgbuf)) != 0) {
  13839. + if (ret == 0)
  13840. + ret = -EFAULT;
  13841. + break;
  13842. + }
  13843. +
  13844. + /* Copy the message to user space */
  13845. + if (copy_to_user(msgbuf, header,
  13846. + msglen) != 0) {
  13847. + if (ret == 0)
  13848. + ret = -EFAULT;
  13849. + break;
  13850. + }
  13851. +
  13852. + /* Now it has been copied, the message
  13853. + ** can be released. */
  13854. + vchiq_release_message(service->handle,
  13855. + header);
  13856. +
  13857. + /* The completion must point to the
  13858. + ** msgbuf. */
  13859. + completion->header = msgbuf;
  13860. + }
  13861. +
  13862. + if (completion->reason ==
  13863. + VCHIQ_SERVICE_CLOSED)
  13864. + unlock_service(service);
  13865. +
  13866. + if (copy_to_user((void __user *)(
  13867. + (size_t)args.buf +
  13868. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  13869. + completion,
  13870. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  13871. + if (ret == 0)
  13872. + ret = -EFAULT;
  13873. + break;
  13874. + }
  13875. +
  13876. + instance->completion_remove++;
  13877. + }
  13878. +
  13879. + if (msgbufcount != args.msgbufcount) {
  13880. + if (copy_to_user((void __user *)
  13881. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  13882. + msgbufcount,
  13883. + &msgbufcount,
  13884. + sizeof(msgbufcount)) != 0) {
  13885. + ret = -EFAULT;
  13886. + }
  13887. + }
  13888. + }
  13889. +
  13890. + if (ret != 0)
  13891. + up(&instance->remove_event);
  13892. + mutex_unlock(&instance->completion_mutex);
  13893. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  13894. + } break;
  13895. +
  13896. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  13897. + VCHIQ_DEQUEUE_MESSAGE_T args;
  13898. + USER_SERVICE_T *user_service;
  13899. + VCHIQ_HEADER_T *header;
  13900. +
  13901. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  13902. + if (copy_from_user
  13903. + (&args, (const void __user *)arg,
  13904. + sizeof(args)) != 0) {
  13905. + ret = -EFAULT;
  13906. + break;
  13907. + }
  13908. + service = find_service_for_instance(instance, args.handle);
  13909. + if (!service) {
  13910. + ret = -EINVAL;
  13911. + break;
  13912. + }
  13913. + user_service = (USER_SERVICE_T *)service->base.userdata;
  13914. + if (user_service->is_vchi == 0) {
  13915. + ret = -EINVAL;
  13916. + break;
  13917. + }
  13918. +
  13919. + spin_lock(&msg_queue_spinlock);
  13920. + if (user_service->msg_remove == user_service->msg_insert) {
  13921. + if (!args.blocking) {
  13922. + spin_unlock(&msg_queue_spinlock);
  13923. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  13924. + ret = -EWOULDBLOCK;
  13925. + break;
  13926. + }
  13927. + user_service->dequeue_pending = 1;
  13928. + do {
  13929. + spin_unlock(&msg_queue_spinlock);
  13930. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  13931. + if (down_interruptible(
  13932. + &user_service->insert_event) != 0) {
  13933. + vchiq_log_info(vchiq_arm_log_level,
  13934. + "DEQUEUE_MESSAGE interrupted");
  13935. + ret = -EINTR;
  13936. + break;
  13937. + }
  13938. + spin_lock(&msg_queue_spinlock);
  13939. + } while (user_service->msg_remove ==
  13940. + user_service->msg_insert);
  13941. +
  13942. + if (ret)
  13943. + break;
  13944. + }
  13945. +
  13946. + BUG_ON((int)(user_service->msg_insert -
  13947. + user_service->msg_remove) < 0);
  13948. +
  13949. + header = user_service->msg_queue[user_service->msg_remove &
  13950. + (MSG_QUEUE_SIZE - 1)];
  13951. + user_service->msg_remove++;
  13952. + spin_unlock(&msg_queue_spinlock);
  13953. +
  13954. + up(&user_service->remove_event);
  13955. + if (header == NULL)
  13956. + ret = -ENOTCONN;
  13957. + else if (header->size <= args.bufsize) {
  13958. + /* Copy to user space if msgbuf is not NULL */
  13959. + if ((args.buf == NULL) ||
  13960. + (copy_to_user((void __user *)args.buf,
  13961. + header->data,
  13962. + header->size) == 0)) {
  13963. + ret = header->size;
  13964. + vchiq_release_message(
  13965. + service->handle,
  13966. + header);
  13967. + } else
  13968. + ret = -EFAULT;
  13969. + } else {
  13970. + vchiq_log_error(vchiq_arm_log_level,
  13971. + "header %x: bufsize %x < size %x",
  13972. + (unsigned int)header, args.bufsize,
  13973. + header->size);
  13974. + WARN(1, "invalid size\n");
  13975. + ret = -EMSGSIZE;
  13976. + }
  13977. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  13978. + } break;
  13979. +
  13980. + case VCHIQ_IOC_GET_CLIENT_ID: {
  13981. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  13982. +
  13983. + ret = vchiq_get_client_id(handle);
  13984. + } break;
  13985. +
  13986. + case VCHIQ_IOC_GET_CONFIG: {
  13987. + VCHIQ_GET_CONFIG_T args;
  13988. + VCHIQ_CONFIG_T config;
  13989. +
  13990. + if (copy_from_user(&args, (const void __user *)arg,
  13991. + sizeof(args)) != 0) {
  13992. + ret = -EFAULT;
  13993. + break;
  13994. + }
  13995. + if (args.config_size > sizeof(config)) {
  13996. + ret = -EINVAL;
  13997. + break;
  13998. + }
  13999. + status = vchiq_get_config(instance, args.config_size, &config);
  14000. + if (status == VCHIQ_SUCCESS) {
  14001. + if (copy_to_user((void __user *)args.pconfig,
  14002. + &config, args.config_size) != 0) {
  14003. + ret = -EFAULT;
  14004. + break;
  14005. + }
  14006. + }
  14007. + } break;
  14008. +
  14009. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  14010. + VCHIQ_SET_SERVICE_OPTION_T args;
  14011. +
  14012. + if (copy_from_user(
  14013. + &args, (const void __user *)arg,
  14014. + sizeof(args)) != 0) {
  14015. + ret = -EFAULT;
  14016. + break;
  14017. + }
  14018. +
  14019. + service = find_service_for_instance(instance, args.handle);
  14020. + if (!service) {
  14021. + ret = -EINVAL;
  14022. + break;
  14023. + }
  14024. +
  14025. + status = vchiq_set_service_option(
  14026. + args.handle, args.option, args.value);
  14027. + } break;
  14028. +
  14029. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  14030. + VCHIQ_DUMP_MEM_T args;
  14031. +
  14032. + if (copy_from_user
  14033. + (&args, (const void __user *)arg,
  14034. + sizeof(args)) != 0) {
  14035. + ret = -EFAULT;
  14036. + break;
  14037. + }
  14038. + dump_phys_mem(args.virt_addr, args.num_bytes);
  14039. + } break;
  14040. +
  14041. + default:
  14042. + ret = -ENOTTY;
  14043. + break;
  14044. + }
  14045. +
  14046. + if (service)
  14047. + unlock_service(service);
  14048. +
  14049. + if (ret == 0) {
  14050. + if (status == VCHIQ_ERROR)
  14051. + ret = -EIO;
  14052. + else if (status == VCHIQ_RETRY)
  14053. + ret = -EINTR;
  14054. + }
  14055. +
  14056. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  14057. + (ret != -EWOULDBLOCK))
  14058. + vchiq_log_info(vchiq_arm_log_level,
  14059. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  14060. + (unsigned long)instance,
  14061. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  14062. + ioctl_names[_IOC_NR(cmd)] :
  14063. + "<invalid>",
  14064. + status, ret);
  14065. + else
  14066. + vchiq_log_trace(vchiq_arm_log_level,
  14067. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  14068. + (unsigned long)instance,
  14069. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  14070. + ioctl_names[_IOC_NR(cmd)] :
  14071. + "<invalid>",
  14072. + status, ret);
  14073. +
  14074. + return ret;
  14075. +}
  14076. +
  14077. +/****************************************************************************
  14078. +*
  14079. +* vchiq_open
  14080. +*
  14081. +***************************************************************************/
  14082. +
  14083. +static int
  14084. +vchiq_open(struct inode *inode, struct file *file)
  14085. +{
  14086. + int dev = iminor(inode) & 0x0f;
  14087. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  14088. + switch (dev) {
  14089. + case VCHIQ_MINOR: {
  14090. + int ret;
  14091. + VCHIQ_STATE_T *state = vchiq_get_state();
  14092. + VCHIQ_INSTANCE_T instance;
  14093. +
  14094. + if (!state) {
  14095. + vchiq_log_error(vchiq_arm_log_level,
  14096. + "vchiq has no connection to VideoCore");
  14097. + return -ENOTCONN;
  14098. + }
  14099. +
  14100. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  14101. + if (!instance)
  14102. + return -ENOMEM;
  14103. +
  14104. + instance->state = state;
  14105. + instance->pid = current->tgid;
  14106. +
  14107. + ret = vchiq_proc_add_instance(instance);
  14108. + if (ret != 0) {
  14109. + kfree(instance);
  14110. + return ret;
  14111. + }
  14112. +
  14113. + sema_init(&instance->insert_event, 0);
  14114. + sema_init(&instance->remove_event, 0);
  14115. + mutex_init(&instance->completion_mutex);
  14116. + mutex_init(&instance->bulk_waiter_list_mutex);
  14117. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  14118. +
  14119. + file->private_data = instance;
  14120. + } break;
  14121. +
  14122. + default:
  14123. + vchiq_log_error(vchiq_arm_log_level,
  14124. + "Unknown minor device: %d", dev);
  14125. + return -ENXIO;
  14126. + }
  14127. +
  14128. + return 0;
  14129. +}
  14130. +
  14131. +/****************************************************************************
  14132. +*
  14133. +* vchiq_release
  14134. +*
  14135. +***************************************************************************/
  14136. +
  14137. +static int
  14138. +vchiq_release(struct inode *inode, struct file *file)
  14139. +{
  14140. + int dev = iminor(inode) & 0x0f;
  14141. + int ret = 0;
  14142. + switch (dev) {
  14143. + case VCHIQ_MINOR: {
  14144. + VCHIQ_INSTANCE_T instance = file->private_data;
  14145. + VCHIQ_STATE_T *state = vchiq_get_state();
  14146. + VCHIQ_SERVICE_T *service;
  14147. + int i;
  14148. +
  14149. + vchiq_log_info(vchiq_arm_log_level,
  14150. + "vchiq_release: instance=%lx",
  14151. + (unsigned long)instance);
  14152. +
  14153. + if (!state) {
  14154. + ret = -EPERM;
  14155. + goto out;
  14156. + }
  14157. +
  14158. + /* Ensure videocore is awake to allow termination. */
  14159. + vchiq_use_internal(instance->state, NULL,
  14160. + USE_TYPE_VCHIQ);
  14161. +
  14162. + mutex_lock(&instance->completion_mutex);
  14163. +
  14164. + /* Wake the completion thread and ask it to exit */
  14165. + instance->closing = 1;
  14166. + up(&instance->insert_event);
  14167. +
  14168. + mutex_unlock(&instance->completion_mutex);
  14169. +
  14170. + /* Wake the slot handler if the completion queue is full. */
  14171. + up(&instance->remove_event);
  14172. +
  14173. + /* Mark all services for termination... */
  14174. + i = 0;
  14175. + while ((service = next_service_by_instance(state, instance,
  14176. + &i)) != NULL) {
  14177. + USER_SERVICE_T *user_service = service->base.userdata;
  14178. +
  14179. + /* Wake the slot handler if the msg queue is full. */
  14180. + up(&user_service->remove_event);
  14181. +
  14182. + vchiq_terminate_service_internal(service);
  14183. + unlock_service(service);
  14184. + }
  14185. +
  14186. + /* ...and wait for them to die */
  14187. + i = 0;
  14188. + while ((service = next_service_by_instance(state, instance, &i))
  14189. + != NULL) {
  14190. + USER_SERVICE_T *user_service = service->base.userdata;
  14191. +
  14192. + down(&service->remove_event);
  14193. +
  14194. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  14195. +
  14196. + spin_lock(&msg_queue_spinlock);
  14197. +
  14198. + while (user_service->msg_remove !=
  14199. + user_service->msg_insert) {
  14200. + VCHIQ_HEADER_T *header = user_service->
  14201. + msg_queue[user_service->msg_remove &
  14202. + (MSG_QUEUE_SIZE - 1)];
  14203. + user_service->msg_remove++;
  14204. + spin_unlock(&msg_queue_spinlock);
  14205. +
  14206. + if (header)
  14207. + vchiq_release_message(
  14208. + service->handle,
  14209. + header);
  14210. + spin_lock(&msg_queue_spinlock);
  14211. + }
  14212. +
  14213. + spin_unlock(&msg_queue_spinlock);
  14214. +
  14215. + unlock_service(service);
  14216. + }
  14217. +
  14218. + /* Release any closed services */
  14219. + while (instance->completion_remove !=
  14220. + instance->completion_insert) {
  14221. + VCHIQ_COMPLETION_DATA_T *completion;
  14222. + VCHIQ_SERVICE_T *service;
  14223. + completion = &instance->completions[
  14224. + instance->completion_remove &
  14225. + (MAX_COMPLETIONS - 1)];
  14226. + service = completion->service_userdata;
  14227. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  14228. + unlock_service(service);
  14229. + instance->completion_remove++;
  14230. + }
  14231. +
  14232. + /* Release the PEER service count. */
  14233. + vchiq_release_internal(instance->state, NULL);
  14234. +
  14235. + {
  14236. + struct list_head *pos, *next;
  14237. + list_for_each_safe(pos, next,
  14238. + &instance->bulk_waiter_list) {
  14239. + struct bulk_waiter_node *waiter;
  14240. + waiter = list_entry(pos,
  14241. + struct bulk_waiter_node,
  14242. + list);
  14243. + list_del(pos);
  14244. + vchiq_log_info(vchiq_arm_log_level,
  14245. + "bulk_waiter - cleaned up %x "
  14246. + "for pid %d",
  14247. + (unsigned int)waiter, waiter->pid);
  14248. + kfree(waiter);
  14249. + }
  14250. + }
  14251. +
  14252. + vchiq_proc_remove_instance(instance);
  14253. +
  14254. + kfree(instance);
  14255. + file->private_data = NULL;
  14256. + } break;
  14257. +
  14258. + default:
  14259. + vchiq_log_error(vchiq_arm_log_level,
  14260. + "Unknown minor device: %d", dev);
  14261. + ret = -ENXIO;
  14262. + }
  14263. +
  14264. +out:
  14265. + return ret;
  14266. +}
  14267. +
  14268. +/****************************************************************************
  14269. +*
  14270. +* vchiq_dump
  14271. +*
  14272. +***************************************************************************/
  14273. +
  14274. +void
  14275. +vchiq_dump(void *dump_context, const char *str, int len)
  14276. +{
  14277. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  14278. +
  14279. + if (context->actual < context->space) {
  14280. + int copy_bytes;
  14281. + if (context->offset > 0) {
  14282. + int skip_bytes = min(len, (int)context->offset);
  14283. + str += skip_bytes;
  14284. + len -= skip_bytes;
  14285. + context->offset -= skip_bytes;
  14286. + if (context->offset > 0)
  14287. + return;
  14288. + }
  14289. + copy_bytes = min(len, (int)(context->space - context->actual));
  14290. + if (copy_bytes == 0)
  14291. + return;
  14292. + if (copy_to_user(context->buf + context->actual, str,
  14293. + copy_bytes))
  14294. + context->actual = -EFAULT;
  14295. + context->actual += copy_bytes;
  14296. + len -= copy_bytes;
  14297. +
  14298. + /* If tne terminating NUL is included in the length, then it
  14299. + ** marks the end of a line and should be replaced with a
  14300. + ** carriage return. */
  14301. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  14302. + char cr = '\n';
  14303. + if (copy_to_user(context->buf + context->actual - 1,
  14304. + &cr, 1))
  14305. + context->actual = -EFAULT;
  14306. + }
  14307. + }
  14308. +}
  14309. +
  14310. +/****************************************************************************
  14311. +*
  14312. +* vchiq_dump_platform_instance_state
  14313. +*
  14314. +***************************************************************************/
  14315. +
  14316. +void
  14317. +vchiq_dump_platform_instances(void *dump_context)
  14318. +{
  14319. + VCHIQ_STATE_T *state = vchiq_get_state();
  14320. + char buf[80];
  14321. + int len;
  14322. + int i;
  14323. +
  14324. + /* There is no list of instances, so instead scan all services,
  14325. + marking those that have been dumped. */
  14326. +
  14327. + for (i = 0; i < state->unused_service; i++) {
  14328. + VCHIQ_SERVICE_T *service = state->services[i];
  14329. + VCHIQ_INSTANCE_T instance;
  14330. +
  14331. + if (service && (service->base.callback == service_callback)) {
  14332. + instance = service->instance;
  14333. + if (instance)
  14334. + instance->mark = 0;
  14335. + }
  14336. + }
  14337. +
  14338. + for (i = 0; i < state->unused_service; i++) {
  14339. + VCHIQ_SERVICE_T *service = state->services[i];
  14340. + VCHIQ_INSTANCE_T instance;
  14341. +
  14342. + if (service && (service->base.callback == service_callback)) {
  14343. + instance = service->instance;
  14344. + if (instance && !instance->mark) {
  14345. + len = snprintf(buf, sizeof(buf),
  14346. + "Instance %x: pid %d,%s completions "
  14347. + "%d/%d",
  14348. + (unsigned int)instance, instance->pid,
  14349. + instance->connected ? " connected, " :
  14350. + "",
  14351. + instance->completion_insert -
  14352. + instance->completion_remove,
  14353. + MAX_COMPLETIONS);
  14354. +
  14355. + vchiq_dump(dump_context, buf, len + 1);
  14356. +
  14357. + instance->mark = 1;
  14358. + }
  14359. + }
  14360. + }
  14361. +}
  14362. +
  14363. +/****************************************************************************
  14364. +*
  14365. +* vchiq_dump_platform_service_state
  14366. +*
  14367. +***************************************************************************/
  14368. +
  14369. +void
  14370. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  14371. +{
  14372. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  14373. + char buf[80];
  14374. + int len;
  14375. +
  14376. + len = snprintf(buf, sizeof(buf), " instance %x",
  14377. + (unsigned int)service->instance);
  14378. +
  14379. + if ((service->base.callback == service_callback) &&
  14380. + user_service->is_vchi) {
  14381. + len += snprintf(buf + len, sizeof(buf) - len,
  14382. + ", %d/%d messages",
  14383. + user_service->msg_insert - user_service->msg_remove,
  14384. + MSG_QUEUE_SIZE);
  14385. +
  14386. + if (user_service->dequeue_pending)
  14387. + len += snprintf(buf + len, sizeof(buf) - len,
  14388. + " (dequeue pending)");
  14389. + }
  14390. +
  14391. + vchiq_dump(dump_context, buf, len + 1);
  14392. +}
  14393. +
  14394. +/****************************************************************************
  14395. +*
  14396. +* dump_user_mem
  14397. +*
  14398. +***************************************************************************/
  14399. +
  14400. +static void
  14401. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  14402. +{
  14403. + int rc;
  14404. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  14405. + int num_pages;
  14406. + int offset;
  14407. + int end_offset;
  14408. + int page_idx;
  14409. + int prev_idx;
  14410. + struct page *page;
  14411. + struct page **pages;
  14412. + uint8_t *kmapped_virt_ptr;
  14413. +
  14414. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  14415. +
  14416. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  14417. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  14418. + ~0x0fuL);
  14419. +
  14420. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  14421. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  14422. +
  14423. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  14424. +
  14425. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  14426. + if (pages == NULL) {
  14427. + vchiq_log_error(vchiq_arm_log_level,
  14428. + "Unable to allocation memory for %d pages\n",
  14429. + num_pages);
  14430. + return;
  14431. + }
  14432. +
  14433. + down_read(&current->mm->mmap_sem);
  14434. + rc = get_user_pages(current, /* task */
  14435. + current->mm, /* mm */
  14436. + (unsigned long)virt_addr, /* start */
  14437. + num_pages, /* len */
  14438. + 0, /* write */
  14439. + 0, /* force */
  14440. + pages, /* pages (array of page pointers) */
  14441. + NULL); /* vmas */
  14442. + up_read(&current->mm->mmap_sem);
  14443. +
  14444. + prev_idx = -1;
  14445. + page = NULL;
  14446. +
  14447. + while (offset < end_offset) {
  14448. +
  14449. + int page_offset = offset % PAGE_SIZE;
  14450. + page_idx = offset / PAGE_SIZE;
  14451. +
  14452. + if (page_idx != prev_idx) {
  14453. +
  14454. + if (page != NULL)
  14455. + kunmap(page);
  14456. + page = pages[page_idx];
  14457. + kmapped_virt_ptr = kmap(page);
  14458. +
  14459. + prev_idx = page_idx;
  14460. + }
  14461. +
  14462. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  14463. + vchiq_log_dump_mem("ph",
  14464. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  14465. + page_offset],
  14466. + &kmapped_virt_ptr[page_offset], 16);
  14467. +
  14468. + offset += 16;
  14469. + }
  14470. + if (page != NULL)
  14471. + kunmap(page);
  14472. +
  14473. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  14474. + page_cache_release(pages[page_idx]);
  14475. +
  14476. + kfree(pages);
  14477. +}
  14478. +
  14479. +/****************************************************************************
  14480. +*
  14481. +* vchiq_read
  14482. +*
  14483. +***************************************************************************/
  14484. +
  14485. +static ssize_t
  14486. +vchiq_read(struct file *file, char __user *buf,
  14487. + size_t count, loff_t *ppos)
  14488. +{
  14489. + DUMP_CONTEXT_T context;
  14490. + context.buf = buf;
  14491. + context.actual = 0;
  14492. + context.space = count;
  14493. + context.offset = *ppos;
  14494. +
  14495. + vchiq_dump_state(&context, &g_state);
  14496. +
  14497. + *ppos += context.actual;
  14498. +
  14499. + return context.actual;
  14500. +}
  14501. +
  14502. +VCHIQ_STATE_T *
  14503. +vchiq_get_state(void)
  14504. +{
  14505. +
  14506. + if (g_state.remote == NULL)
  14507. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  14508. + else if (g_state.remote->initialised != 1)
  14509. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  14510. + __func__, g_state.remote->initialised);
  14511. +
  14512. + return ((g_state.remote != NULL) &&
  14513. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  14514. +}
  14515. +
  14516. +static const struct file_operations
  14517. +vchiq_fops = {
  14518. + .owner = THIS_MODULE,
  14519. + .unlocked_ioctl = vchiq_ioctl,
  14520. + .open = vchiq_open,
  14521. + .release = vchiq_release,
  14522. + .read = vchiq_read
  14523. +};
  14524. +
  14525. +/*
  14526. + * Autosuspend related functionality
  14527. + */
  14528. +
  14529. +int
  14530. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  14531. +{
  14532. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14533. + if (!arm_state)
  14534. + /* autosuspend not supported - always return wanted */
  14535. + return 1;
  14536. + else if (arm_state->blocked_count)
  14537. + return 1;
  14538. + else if (!arm_state->videocore_use_count)
  14539. + /* usage count zero - check for override unless we're forcing */
  14540. + if (arm_state->resume_blocked)
  14541. + return 0;
  14542. + else
  14543. + return vchiq_platform_videocore_wanted(state);
  14544. + else
  14545. + /* non-zero usage count - videocore still required */
  14546. + return 1;
  14547. +}
  14548. +
  14549. +static VCHIQ_STATUS_T
  14550. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  14551. + VCHIQ_HEADER_T *header,
  14552. + VCHIQ_SERVICE_HANDLE_T service_user,
  14553. + void *bulk_user)
  14554. +{
  14555. + vchiq_log_error(vchiq_susp_log_level,
  14556. + "%s callback reason %d", __func__, reason);
  14557. + return 0;
  14558. +}
  14559. +
  14560. +static int
  14561. +vchiq_keepalive_thread_func(void *v)
  14562. +{
  14563. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  14564. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14565. +
  14566. + VCHIQ_STATUS_T status;
  14567. + VCHIQ_INSTANCE_T instance;
  14568. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  14569. +
  14570. + VCHIQ_SERVICE_PARAMS_T params = {
  14571. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  14572. + .callback = vchiq_keepalive_vchiq_callback,
  14573. + .version = KEEPALIVE_VER,
  14574. + .version_min = KEEPALIVE_VER_MIN
  14575. + };
  14576. +
  14577. + status = vchiq_initialise(&instance);
  14578. + if (status != VCHIQ_SUCCESS) {
  14579. + vchiq_log_error(vchiq_susp_log_level,
  14580. + "%s vchiq_initialise failed %d", __func__, status);
  14581. + goto exit;
  14582. + }
  14583. +
  14584. + status = vchiq_connect(instance);
  14585. + if (status != VCHIQ_SUCCESS) {
  14586. + vchiq_log_error(vchiq_susp_log_level,
  14587. + "%s vchiq_connect failed %d", __func__, status);
  14588. + goto shutdown;
  14589. + }
  14590. +
  14591. + status = vchiq_add_service(instance, &params, &ka_handle);
  14592. + if (status != VCHIQ_SUCCESS) {
  14593. + vchiq_log_error(vchiq_susp_log_level,
  14594. + "%s vchiq_open_service failed %d", __func__, status);
  14595. + goto shutdown;
  14596. + }
  14597. +
  14598. + while (1) {
  14599. + long rc = 0, uc = 0;
  14600. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  14601. + != 0) {
  14602. + vchiq_log_error(vchiq_susp_log_level,
  14603. + "%s interrupted", __func__);
  14604. + flush_signals(current);
  14605. + continue;
  14606. + }
  14607. +
  14608. + /* read and clear counters. Do release_count then use_count to
  14609. + * prevent getting more releases than uses */
  14610. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  14611. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  14612. +
  14613. + /* Call use/release service the requisite number of times.
  14614. + * Process use before release so use counts don't go negative */
  14615. + while (uc--) {
  14616. + atomic_inc(&arm_state->ka_use_ack_count);
  14617. + status = vchiq_use_service(ka_handle);
  14618. + if (status != VCHIQ_SUCCESS) {
  14619. + vchiq_log_error(vchiq_susp_log_level,
  14620. + "%s vchiq_use_service error %d",
  14621. + __func__, status);
  14622. + }
  14623. + }
  14624. + while (rc--) {
  14625. + status = vchiq_release_service(ka_handle);
  14626. + if (status != VCHIQ_SUCCESS) {
  14627. + vchiq_log_error(vchiq_susp_log_level,
  14628. + "%s vchiq_release_service error %d",
  14629. + __func__, status);
  14630. + }
  14631. + }
  14632. + }
  14633. +
  14634. +shutdown:
  14635. + vchiq_shutdown(instance);
  14636. +exit:
  14637. + return 0;
  14638. +}
  14639. +
  14640. +
  14641. +
  14642. +VCHIQ_STATUS_T
  14643. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  14644. +{
  14645. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  14646. +
  14647. + if (arm_state) {
  14648. + rwlock_init(&arm_state->susp_res_lock);
  14649. +
  14650. + init_completion(&arm_state->ka_evt);
  14651. + atomic_set(&arm_state->ka_use_count, 0);
  14652. + atomic_set(&arm_state->ka_use_ack_count, 0);
  14653. + atomic_set(&arm_state->ka_release_count, 0);
  14654. +
  14655. + init_completion(&arm_state->vc_suspend_complete);
  14656. +
  14657. + init_completion(&arm_state->vc_resume_complete);
  14658. + /* Initialise to 'done' state. We only want to block on resume
  14659. + * completion while videocore is suspended. */
  14660. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  14661. +
  14662. + init_completion(&arm_state->resume_blocker);
  14663. + /* Initialise to 'done' state. We only want to block on this
  14664. + * completion while resume is blocked */
  14665. + complete_all(&arm_state->resume_blocker);
  14666. +
  14667. + init_completion(&arm_state->blocked_blocker);
  14668. + /* Initialise to 'done' state. We only want to block on this
  14669. + * completion while things are waiting on the resume blocker */
  14670. + complete_all(&arm_state->blocked_blocker);
  14671. +
  14672. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  14673. + arm_state->suspend_timer_running = 0;
  14674. + init_timer(&arm_state->suspend_timer);
  14675. + arm_state->suspend_timer.data = (unsigned long)(state);
  14676. + arm_state->suspend_timer.function = suspend_timer_callback;
  14677. +
  14678. + arm_state->first_connect = 0;
  14679. +
  14680. + }
  14681. + return status;
  14682. +}
  14683. +
  14684. +/*
  14685. +** Functions to modify the state variables;
  14686. +** set_suspend_state
  14687. +** set_resume_state
  14688. +**
  14689. +** There are more state variables than we might like, so ensure they remain in
  14690. +** step. Suspend and resume state are maintained separately, since most of
  14691. +** these state machines can operate independently. However, there are a few
  14692. +** states where state transitions in one state machine cause a reset to the
  14693. +** other state machine. In addition, there are some completion events which
  14694. +** need to occur on state machine reset and end-state(s), so these are also
  14695. +** dealt with in these functions.
  14696. +**
  14697. +** In all states we set the state variable according to the input, but in some
  14698. +** cases we perform additional steps outlined below;
  14699. +**
  14700. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  14701. +** The suspend completion is completed after any suspend
  14702. +** attempt. When we reset the state machine we also reset
  14703. +** the completion. This reset occurs when videocore is
  14704. +** resumed, and also if we initiate suspend after a suspend
  14705. +** failure.
  14706. +**
  14707. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  14708. +** suspend - ie from this point on we must try to suspend
  14709. +** before resuming can occur. We therefore also reset the
  14710. +** resume state machine to VC_RESUME_IDLE in this state.
  14711. +**
  14712. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  14713. +** complete_all on the suspend completion to notify
  14714. +** anything waiting for suspend to happen.
  14715. +**
  14716. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  14717. +** initiate resume, so no need to alter resume state.
  14718. +** We call complete_all on the suspend completion to notify
  14719. +** of suspend rejection.
  14720. +**
  14721. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  14722. +** suspend completion and reset the resume state machine.
  14723. +**
  14724. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  14725. +** resume completion is in it's 'done' state whenever
  14726. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  14727. +** implies that videocore is suspended.
  14728. +** Hence, any thread which needs to wait until videocore is
  14729. +** running can wait on this completion - it will only block
  14730. +** if videocore is suspended.
  14731. +**
  14732. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  14733. +** Call complete_all on the resume completion to unblock
  14734. +** any threads waiting for resume. Also reset the suspend
  14735. +** state machine to it's idle state.
  14736. +**
  14737. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  14738. +*/
  14739. +
  14740. +inline void
  14741. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  14742. + enum vc_suspend_status new_state)
  14743. +{
  14744. + /* set the state in all cases */
  14745. + arm_state->vc_suspend_state = new_state;
  14746. +
  14747. + /* state specific additional actions */
  14748. + switch (new_state) {
  14749. + case VC_SUSPEND_FORCE_CANCELED:
  14750. + complete_all(&arm_state->vc_suspend_complete);
  14751. + break;
  14752. + case VC_SUSPEND_REJECTED:
  14753. + complete_all(&arm_state->vc_suspend_complete);
  14754. + break;
  14755. + case VC_SUSPEND_FAILED:
  14756. + complete_all(&arm_state->vc_suspend_complete);
  14757. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  14758. + complete_all(&arm_state->vc_resume_complete);
  14759. + break;
  14760. + case VC_SUSPEND_IDLE:
  14761. + INIT_COMPLETION(arm_state->vc_suspend_complete);
  14762. + break;
  14763. + case VC_SUSPEND_REQUESTED:
  14764. + break;
  14765. + case VC_SUSPEND_IN_PROGRESS:
  14766. + set_resume_state(arm_state, VC_RESUME_IDLE);
  14767. + break;
  14768. + case VC_SUSPEND_SUSPENDED:
  14769. + complete_all(&arm_state->vc_suspend_complete);
  14770. + break;
  14771. + default:
  14772. + BUG();
  14773. + break;
  14774. + }
  14775. +}
  14776. +
  14777. +inline void
  14778. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  14779. + enum vc_resume_status new_state)
  14780. +{
  14781. + /* set the state in all cases */
  14782. + arm_state->vc_resume_state = new_state;
  14783. +
  14784. + /* state specific additional actions */
  14785. + switch (new_state) {
  14786. + case VC_RESUME_FAILED:
  14787. + break;
  14788. + case VC_RESUME_IDLE:
  14789. + INIT_COMPLETION(arm_state->vc_resume_complete);
  14790. + break;
  14791. + case VC_RESUME_REQUESTED:
  14792. + break;
  14793. + case VC_RESUME_IN_PROGRESS:
  14794. + break;
  14795. + case VC_RESUME_RESUMED:
  14796. + complete_all(&arm_state->vc_resume_complete);
  14797. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  14798. + break;
  14799. + default:
  14800. + BUG();
  14801. + break;
  14802. + }
  14803. +}
  14804. +
  14805. +
  14806. +/* should be called with the write lock held */
  14807. +inline void
  14808. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  14809. +{
  14810. + del_timer(&arm_state->suspend_timer);
  14811. + arm_state->suspend_timer.expires = jiffies +
  14812. + msecs_to_jiffies(arm_state->
  14813. + suspend_timer_timeout);
  14814. + add_timer(&arm_state->suspend_timer);
  14815. + arm_state->suspend_timer_running = 1;
  14816. +}
  14817. +
  14818. +/* should be called with the write lock held */
  14819. +static inline void
  14820. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  14821. +{
  14822. + if (arm_state->suspend_timer_running) {
  14823. + del_timer(&arm_state->suspend_timer);
  14824. + arm_state->suspend_timer_running = 0;
  14825. + }
  14826. +}
  14827. +
  14828. +static inline int
  14829. +need_resume(VCHIQ_STATE_T *state)
  14830. +{
  14831. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14832. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  14833. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  14834. + vchiq_videocore_wanted(state);
  14835. +}
  14836. +
  14837. +static int
  14838. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  14839. +{
  14840. + int status = VCHIQ_SUCCESS;
  14841. + const unsigned long timeout_val =
  14842. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  14843. + int resume_count = 0;
  14844. +
  14845. + /* Allow any threads which were blocked by the last force suspend to
  14846. + * complete if they haven't already. Only give this one shot; if
  14847. + * blocked_count is incremented after blocked_blocker is completed
  14848. + * (which only happens when blocked_count hits 0) then those threads
  14849. + * will have to wait until next time around */
  14850. + if (arm_state->blocked_count) {
  14851. + INIT_COMPLETION(arm_state->blocked_blocker);
  14852. + write_unlock_bh(&arm_state->susp_res_lock);
  14853. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  14854. + "blocked clients", __func__);
  14855. + if (wait_for_completion_interruptible_timeout(
  14856. + &arm_state->blocked_blocker, timeout_val)
  14857. + <= 0) {
  14858. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  14859. + "previously blocked clients failed" , __func__);
  14860. + status = VCHIQ_ERROR;
  14861. + write_lock_bh(&arm_state->susp_res_lock);
  14862. + goto out;
  14863. + }
  14864. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  14865. + "clients resumed", __func__);
  14866. + write_lock_bh(&arm_state->susp_res_lock);
  14867. + }
  14868. +
  14869. + /* We need to wait for resume to complete if it's in process */
  14870. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  14871. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  14872. + if (resume_count > 1) {
  14873. + status = VCHIQ_ERROR;
  14874. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  14875. + "many times for resume" , __func__);
  14876. + goto out;
  14877. + }
  14878. + write_unlock_bh(&arm_state->susp_res_lock);
  14879. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  14880. + __func__);
  14881. + if (wait_for_completion_interruptible_timeout(
  14882. + &arm_state->vc_resume_complete, timeout_val)
  14883. + <= 0) {
  14884. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  14885. + "resume failed (%s)", __func__,
  14886. + resume_state_names[arm_state->vc_resume_state +
  14887. + VC_RESUME_NUM_OFFSET]);
  14888. + status = VCHIQ_ERROR;
  14889. + write_lock_bh(&arm_state->susp_res_lock);
  14890. + goto out;
  14891. + }
  14892. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  14893. + write_lock_bh(&arm_state->susp_res_lock);
  14894. + resume_count++;
  14895. + }
  14896. + INIT_COMPLETION(arm_state->resume_blocker);
  14897. + arm_state->resume_blocked = 1;
  14898. +
  14899. +out:
  14900. + return status;
  14901. +}
  14902. +
  14903. +static inline void
  14904. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  14905. +{
  14906. + complete_all(&arm_state->resume_blocker);
  14907. + arm_state->resume_blocked = 0;
  14908. +}
  14909. +
  14910. +/* Initiate suspend via slot handler. Should be called with the write lock
  14911. + * held */
  14912. +VCHIQ_STATUS_T
  14913. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  14914. +{
  14915. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  14916. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14917. +
  14918. + if (!arm_state)
  14919. + goto out;
  14920. +
  14921. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  14922. + status = VCHIQ_SUCCESS;
  14923. +
  14924. +
  14925. + switch (arm_state->vc_suspend_state) {
  14926. + case VC_SUSPEND_REQUESTED:
  14927. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  14928. + "requested", __func__);
  14929. + break;
  14930. + case VC_SUSPEND_IN_PROGRESS:
  14931. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  14932. + "progress", __func__);
  14933. + break;
  14934. +
  14935. + default:
  14936. + /* We don't expect to be in other states, so log but continue
  14937. + * anyway */
  14938. + vchiq_log_error(vchiq_susp_log_level,
  14939. + "%s unexpected suspend state %s", __func__,
  14940. + suspend_state_names[arm_state->vc_suspend_state +
  14941. + VC_SUSPEND_NUM_OFFSET]);
  14942. + /* fall through */
  14943. + case VC_SUSPEND_REJECTED:
  14944. + case VC_SUSPEND_FAILED:
  14945. + /* Ensure any idle state actions have been run */
  14946. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  14947. + /* fall through */
  14948. + case VC_SUSPEND_IDLE:
  14949. + vchiq_log_info(vchiq_susp_log_level,
  14950. + "%s: suspending", __func__);
  14951. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  14952. + /* kick the slot handler thread to initiate suspend */
  14953. + request_poll(state, NULL, 0);
  14954. + break;
  14955. + }
  14956. +
  14957. +out:
  14958. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  14959. + return status;
  14960. +}
  14961. +
  14962. +void
  14963. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  14964. +{
  14965. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14966. + int susp = 0;
  14967. +
  14968. + if (!arm_state)
  14969. + goto out;
  14970. +
  14971. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  14972. +
  14973. + write_lock_bh(&arm_state->susp_res_lock);
  14974. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  14975. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  14976. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  14977. + susp = 1;
  14978. + }
  14979. + write_unlock_bh(&arm_state->susp_res_lock);
  14980. +
  14981. + if (susp)
  14982. + vchiq_platform_suspend(state);
  14983. +
  14984. +out:
  14985. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  14986. + return;
  14987. +}
  14988. +
  14989. +
  14990. +static void
  14991. +output_timeout_error(VCHIQ_STATE_T *state)
  14992. +{
  14993. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  14994. + char service_err[50] = "";
  14995. + int vc_use_count = arm_state->videocore_use_count;
  14996. + int active_services = state->unused_service;
  14997. + int i;
  14998. +
  14999. + if (!arm_state->videocore_use_count) {
  15000. + snprintf(service_err, 50, " Videocore usecount is 0");
  15001. + goto output_msg;
  15002. + }
  15003. + for (i = 0; i < active_services; i++) {
  15004. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  15005. + if (service_ptr && service_ptr->service_use_count &&
  15006. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  15007. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  15008. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  15009. + service_ptr->base.fourcc),
  15010. + service_ptr->client_id,
  15011. + service_ptr->service_use_count,
  15012. + service_ptr->service_use_count ==
  15013. + vc_use_count ? "" : " (+ more)");
  15014. + break;
  15015. + }
  15016. + }
  15017. +
  15018. +output_msg:
  15019. + vchiq_log_error(vchiq_susp_log_level,
  15020. + "timed out waiting for vc suspend (%d).%s",
  15021. + arm_state->autosuspend_override, service_err);
  15022. +
  15023. +}
  15024. +
  15025. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  15026. +** We don't actually force suspend, since videocore may get into a bad state
  15027. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  15028. +** determine a good point to suspend. If this doesn't happen within 100ms we
  15029. +** report failure.
  15030. +**
  15031. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  15032. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  15033. +*/
  15034. +VCHIQ_STATUS_T
  15035. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  15036. +{
  15037. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15038. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  15039. + long rc = 0;
  15040. + int repeat = -1;
  15041. +
  15042. + if (!arm_state)
  15043. + goto out;
  15044. +
  15045. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15046. +
  15047. + write_lock_bh(&arm_state->susp_res_lock);
  15048. +
  15049. + status = block_resume(arm_state);
  15050. + if (status != VCHIQ_SUCCESS)
  15051. + goto unlock;
  15052. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  15053. + /* Already suspended - just block resume and exit */
  15054. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  15055. + __func__);
  15056. + status = VCHIQ_SUCCESS;
  15057. + goto unlock;
  15058. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  15059. + /* initiate suspend immediately in the case that we're waiting
  15060. + * for the timeout */
  15061. + stop_suspend_timer(arm_state);
  15062. + if (!vchiq_videocore_wanted(state)) {
  15063. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  15064. + "idle, initiating suspend", __func__);
  15065. + status = vchiq_arm_vcsuspend(state);
  15066. + } else if (arm_state->autosuspend_override <
  15067. + FORCE_SUSPEND_FAIL_MAX) {
  15068. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  15069. + "videocore go idle", __func__);
  15070. + status = VCHIQ_SUCCESS;
  15071. + } else {
  15072. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  15073. + "many times - attempting suspend", __func__);
  15074. + status = vchiq_arm_vcsuspend(state);
  15075. + }
  15076. + } else {
  15077. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  15078. + "in progress - wait for completion", __func__);
  15079. + status = VCHIQ_SUCCESS;
  15080. + }
  15081. +
  15082. + /* Wait for suspend to happen due to system idle (not forced..) */
  15083. + if (status != VCHIQ_SUCCESS)
  15084. + goto unblock_resume;
  15085. +
  15086. + do {
  15087. + write_unlock_bh(&arm_state->susp_res_lock);
  15088. +
  15089. + rc = wait_for_completion_interruptible_timeout(
  15090. + &arm_state->vc_suspend_complete,
  15091. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  15092. +
  15093. + write_lock_bh(&arm_state->susp_res_lock);
  15094. + if (rc < 0) {
  15095. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  15096. + "interrupted waiting for suspend", __func__);
  15097. + status = VCHIQ_ERROR;
  15098. + goto unblock_resume;
  15099. + } else if (rc == 0) {
  15100. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  15101. + /* Repeat timeout once if in progress */
  15102. + if (repeat < 0) {
  15103. + repeat = 1;
  15104. + continue;
  15105. + }
  15106. + }
  15107. + arm_state->autosuspend_override++;
  15108. + output_timeout_error(state);
  15109. +
  15110. + status = VCHIQ_RETRY;
  15111. + goto unblock_resume;
  15112. + }
  15113. + } while (0 < (repeat--));
  15114. +
  15115. + /* Check and report state in case we need to abort ARM suspend */
  15116. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  15117. + status = VCHIQ_RETRY;
  15118. + vchiq_log_error(vchiq_susp_log_level,
  15119. + "%s videocore suspend failed (state %s)", __func__,
  15120. + suspend_state_names[arm_state->vc_suspend_state +
  15121. + VC_SUSPEND_NUM_OFFSET]);
  15122. + /* Reset the state only if it's still in an error state.
  15123. + * Something could have already initiated another suspend. */
  15124. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  15125. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  15126. +
  15127. + goto unblock_resume;
  15128. + }
  15129. +
  15130. + /* successfully suspended - unlock and exit */
  15131. + goto unlock;
  15132. +
  15133. +unblock_resume:
  15134. + /* all error states need to unblock resume before exit */
  15135. + unblock_resume(arm_state);
  15136. +
  15137. +unlock:
  15138. + write_unlock_bh(&arm_state->susp_res_lock);
  15139. +
  15140. +out:
  15141. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  15142. + return status;
  15143. +}
  15144. +
  15145. +void
  15146. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  15147. +{
  15148. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15149. +
  15150. + if (!arm_state)
  15151. + goto out;
  15152. +
  15153. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15154. +
  15155. + write_lock_bh(&arm_state->susp_res_lock);
  15156. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  15157. + arm_state->first_connect &&
  15158. + !vchiq_videocore_wanted(state)) {
  15159. + vchiq_arm_vcsuspend(state);
  15160. + }
  15161. + write_unlock_bh(&arm_state->susp_res_lock);
  15162. +
  15163. +out:
  15164. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  15165. + return;
  15166. +}
  15167. +
  15168. +
  15169. +int
  15170. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  15171. +{
  15172. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15173. + int resume = 0;
  15174. + int ret = -1;
  15175. +
  15176. + if (!arm_state)
  15177. + goto out;
  15178. +
  15179. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15180. +
  15181. + write_lock_bh(&arm_state->susp_res_lock);
  15182. + unblock_resume(arm_state);
  15183. + resume = vchiq_check_resume(state);
  15184. + write_unlock_bh(&arm_state->susp_res_lock);
  15185. +
  15186. + if (resume) {
  15187. + if (wait_for_completion_interruptible(
  15188. + &arm_state->vc_resume_complete) < 0) {
  15189. + vchiq_log_error(vchiq_susp_log_level,
  15190. + "%s interrupted", __func__);
  15191. + /* failed, cannot accurately derive suspend
  15192. + * state, so exit early. */
  15193. + goto out;
  15194. + }
  15195. + }
  15196. +
  15197. + read_lock_bh(&arm_state->susp_res_lock);
  15198. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  15199. + vchiq_log_info(vchiq_susp_log_level,
  15200. + "%s: Videocore remains suspended", __func__);
  15201. + } else {
  15202. + vchiq_log_info(vchiq_susp_log_level,
  15203. + "%s: Videocore resumed", __func__);
  15204. + ret = 0;
  15205. + }
  15206. + read_unlock_bh(&arm_state->susp_res_lock);
  15207. +out:
  15208. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  15209. + return ret;
  15210. +}
  15211. +
  15212. +/* This function should be called with the write lock held */
  15213. +int
  15214. +vchiq_check_resume(VCHIQ_STATE_T *state)
  15215. +{
  15216. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15217. + int resume = 0;
  15218. +
  15219. + if (!arm_state)
  15220. + goto out;
  15221. +
  15222. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15223. +
  15224. + if (need_resume(state)) {
  15225. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  15226. + request_poll(state, NULL, 0);
  15227. + resume = 1;
  15228. + }
  15229. +
  15230. +out:
  15231. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  15232. + return resume;
  15233. +}
  15234. +
  15235. +void
  15236. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  15237. +{
  15238. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15239. + int res = 0;
  15240. +
  15241. + if (!arm_state)
  15242. + goto out;
  15243. +
  15244. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15245. +
  15246. + write_lock_bh(&arm_state->susp_res_lock);
  15247. + if (arm_state->wake_address == 0) {
  15248. + vchiq_log_info(vchiq_susp_log_level,
  15249. + "%s: already awake", __func__);
  15250. + goto unlock;
  15251. + }
  15252. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  15253. + vchiq_log_info(vchiq_susp_log_level,
  15254. + "%s: already resuming", __func__);
  15255. + goto unlock;
  15256. + }
  15257. +
  15258. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  15259. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  15260. + res = 1;
  15261. + } else
  15262. + vchiq_log_trace(vchiq_susp_log_level,
  15263. + "%s: not resuming (resume state %s)", __func__,
  15264. + resume_state_names[arm_state->vc_resume_state +
  15265. + VC_RESUME_NUM_OFFSET]);
  15266. +
  15267. +unlock:
  15268. + write_unlock_bh(&arm_state->susp_res_lock);
  15269. +
  15270. + if (res)
  15271. + vchiq_platform_resume(state);
  15272. +
  15273. +out:
  15274. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  15275. + return;
  15276. +
  15277. +}
  15278. +
  15279. +
  15280. +
  15281. +VCHIQ_STATUS_T
  15282. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  15283. + enum USE_TYPE_E use_type)
  15284. +{
  15285. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15286. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  15287. + char entity[16];
  15288. + int *entity_uc;
  15289. + int local_uc, local_entity_uc;
  15290. +
  15291. + if (!arm_state)
  15292. + goto out;
  15293. +
  15294. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15295. +
  15296. + if (use_type == USE_TYPE_VCHIQ) {
  15297. + sprintf(entity, "VCHIQ: ");
  15298. + entity_uc = &arm_state->peer_use_count;
  15299. + } else if (service) {
  15300. + sprintf(entity, "%c%c%c%c:%03d",
  15301. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  15302. + service->client_id);
  15303. + entity_uc = &service->service_use_count;
  15304. + } else {
  15305. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  15306. + "ptr", __func__);
  15307. + ret = VCHIQ_ERROR;
  15308. + goto out;
  15309. + }
  15310. +
  15311. + write_lock_bh(&arm_state->susp_res_lock);
  15312. + while (arm_state->resume_blocked) {
  15313. + /* If we call 'use' while force suspend is waiting for suspend,
  15314. + * then we're about to block the thread which the force is
  15315. + * waiting to complete, so we're bound to just time out. In this
  15316. + * case, set the suspend state such that the wait will be
  15317. + * canceled, so we can complete as quickly as possible. */
  15318. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  15319. + VC_SUSPEND_IDLE) {
  15320. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  15321. + break;
  15322. + }
  15323. + /* If suspend is already in progress then we need to block */
  15324. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  15325. + /* Indicate that there are threads waiting on the resume
  15326. + * blocker. These need to be allowed to complete before
  15327. + * a _second_ call to force suspend can complete,
  15328. + * otherwise low priority threads might never actually
  15329. + * continue */
  15330. + arm_state->blocked_count++;
  15331. + write_unlock_bh(&arm_state->susp_res_lock);
  15332. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  15333. + "blocked - waiting...", __func__, entity);
  15334. + if (wait_for_completion_killable(
  15335. + &arm_state->resume_blocker) != 0) {
  15336. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  15337. + "wait for resume blocker interrupted",
  15338. + __func__, entity);
  15339. + ret = VCHIQ_ERROR;
  15340. + write_lock_bh(&arm_state->susp_res_lock);
  15341. + arm_state->blocked_count--;
  15342. + write_unlock_bh(&arm_state->susp_res_lock);
  15343. + goto out;
  15344. + }
  15345. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  15346. + "unblocked", __func__, entity);
  15347. + write_lock_bh(&arm_state->susp_res_lock);
  15348. + if (--arm_state->blocked_count == 0)
  15349. + complete_all(&arm_state->blocked_blocker);
  15350. + }
  15351. + }
  15352. +
  15353. + stop_suspend_timer(arm_state);
  15354. +
  15355. + local_uc = ++arm_state->videocore_use_count;
  15356. + local_entity_uc = ++(*entity_uc);
  15357. +
  15358. + /* If there's a pending request which hasn't yet been serviced then
  15359. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  15360. + * vc_resume_complete will block until we either resume or fail to
  15361. + * suspend */
  15362. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  15363. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  15364. +
  15365. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  15366. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  15367. + vchiq_log_info(vchiq_susp_log_level,
  15368. + "%s %s count %d, state count %d",
  15369. + __func__, entity, local_entity_uc, local_uc);
  15370. + request_poll(state, NULL, 0);
  15371. + } else
  15372. + vchiq_log_trace(vchiq_susp_log_level,
  15373. + "%s %s count %d, state count %d",
  15374. + __func__, entity, *entity_uc, local_uc);
  15375. +
  15376. +
  15377. + write_unlock_bh(&arm_state->susp_res_lock);
  15378. +
  15379. + /* Completion is in a done state when we're not suspended, so this won't
  15380. + * block for the non-suspended case. */
  15381. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  15382. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  15383. + __func__, entity);
  15384. + if (wait_for_completion_killable(
  15385. + &arm_state->vc_resume_complete) != 0) {
  15386. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  15387. + "resume interrupted", __func__, entity);
  15388. + ret = VCHIQ_ERROR;
  15389. + goto out;
  15390. + }
  15391. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  15392. + entity);
  15393. + }
  15394. +
  15395. + if (ret == VCHIQ_SUCCESS) {
  15396. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  15397. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  15398. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  15399. + /* Send the use notify to videocore */
  15400. + status = vchiq_send_remote_use_active(state);
  15401. + if (status == VCHIQ_SUCCESS)
  15402. + ack_cnt--;
  15403. + else
  15404. + atomic_add(ack_cnt,
  15405. + &arm_state->ka_use_ack_count);
  15406. + }
  15407. + }
  15408. +
  15409. +out:
  15410. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  15411. + return ret;
  15412. +}
  15413. +
  15414. +VCHIQ_STATUS_T
  15415. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  15416. +{
  15417. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15418. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  15419. + char entity[16];
  15420. + int *entity_uc;
  15421. + int local_uc, local_entity_uc;
  15422. +
  15423. + if (!arm_state)
  15424. + goto out;
  15425. +
  15426. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15427. +
  15428. + if (service) {
  15429. + sprintf(entity, "%c%c%c%c:%03d",
  15430. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  15431. + service->client_id);
  15432. + entity_uc = &service->service_use_count;
  15433. + } else {
  15434. + sprintf(entity, "PEER: ");
  15435. + entity_uc = &arm_state->peer_use_count;
  15436. + }
  15437. +
  15438. + write_lock_bh(&arm_state->susp_res_lock);
  15439. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  15440. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  15441. + WARN_ON(!arm_state->videocore_use_count);
  15442. + WARN_ON(!(*entity_uc));
  15443. + ret = VCHIQ_ERROR;
  15444. + goto unlock;
  15445. + }
  15446. + local_uc = --arm_state->videocore_use_count;
  15447. + local_entity_uc = --(*entity_uc);
  15448. +
  15449. + if (!vchiq_videocore_wanted(state)) {
  15450. + if (vchiq_platform_use_suspend_timer() &&
  15451. + !arm_state->resume_blocked) {
  15452. + /* Only use the timer if we're not trying to force
  15453. + * suspend (=> resume_blocked) */
  15454. + start_suspend_timer(arm_state);
  15455. + } else {
  15456. + vchiq_log_info(vchiq_susp_log_level,
  15457. + "%s %s count %d, state count %d - suspending",
  15458. + __func__, entity, *entity_uc,
  15459. + arm_state->videocore_use_count);
  15460. + vchiq_arm_vcsuspend(state);
  15461. + }
  15462. + } else
  15463. + vchiq_log_trace(vchiq_susp_log_level,
  15464. + "%s %s count %d, state count %d",
  15465. + __func__, entity, *entity_uc,
  15466. + arm_state->videocore_use_count);
  15467. +
  15468. +unlock:
  15469. + write_unlock_bh(&arm_state->susp_res_lock);
  15470. +
  15471. +out:
  15472. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  15473. + return ret;
  15474. +}
  15475. +
  15476. +void
  15477. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  15478. +{
  15479. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15480. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15481. + atomic_inc(&arm_state->ka_use_count);
  15482. + complete(&arm_state->ka_evt);
  15483. +}
  15484. +
  15485. +void
  15486. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  15487. +{
  15488. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15489. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15490. + atomic_inc(&arm_state->ka_release_count);
  15491. + complete(&arm_state->ka_evt);
  15492. +}
  15493. +
  15494. +VCHIQ_STATUS_T
  15495. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  15496. +{
  15497. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  15498. +}
  15499. +
  15500. +VCHIQ_STATUS_T
  15501. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  15502. +{
  15503. + return vchiq_release_internal(service->state, service);
  15504. +}
  15505. +
  15506. +static void suspend_timer_callback(unsigned long context)
  15507. +{
  15508. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  15509. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15510. + if (!arm_state)
  15511. + goto out;
  15512. + vchiq_log_info(vchiq_susp_log_level,
  15513. + "%s - suspend timer expired - check suspend", __func__);
  15514. + vchiq_check_suspend(state);
  15515. +out:
  15516. + return;
  15517. +}
  15518. +
  15519. +VCHIQ_STATUS_T
  15520. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  15521. +{
  15522. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  15523. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  15524. + if (service) {
  15525. + ret = vchiq_use_internal(service->state, service,
  15526. + USE_TYPE_SERVICE_NO_RESUME);
  15527. + unlock_service(service);
  15528. + }
  15529. + return ret;
  15530. +}
  15531. +
  15532. +VCHIQ_STATUS_T
  15533. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  15534. +{
  15535. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  15536. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  15537. + if (service) {
  15538. + ret = vchiq_use_internal(service->state, service,
  15539. + USE_TYPE_SERVICE);
  15540. + unlock_service(service);
  15541. + }
  15542. + return ret;
  15543. +}
  15544. +
  15545. +VCHIQ_STATUS_T
  15546. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  15547. +{
  15548. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  15549. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  15550. + if (service) {
  15551. + ret = vchiq_release_internal(service->state, service);
  15552. + unlock_service(service);
  15553. + }
  15554. + return ret;
  15555. +}
  15556. +
  15557. +void
  15558. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  15559. +{
  15560. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15561. + int i, j = 0;
  15562. + /* Only dump 64 services */
  15563. + static const int local_max_services = 64;
  15564. + /* If there's more than 64 services, only dump ones with
  15565. + * non-zero counts */
  15566. + int only_nonzero = 0;
  15567. + static const char *nz = "<-- preventing suspend";
  15568. +
  15569. + enum vc_suspend_status vc_suspend_state;
  15570. + enum vc_resume_status vc_resume_state;
  15571. + int peer_count;
  15572. + int vc_use_count;
  15573. + int active_services;
  15574. + struct service_data_struct {
  15575. + int fourcc;
  15576. + int clientid;
  15577. + int use_count;
  15578. + } service_data[local_max_services];
  15579. +
  15580. + if (!arm_state)
  15581. + return;
  15582. +
  15583. + read_lock_bh(&arm_state->susp_res_lock);
  15584. + vc_suspend_state = arm_state->vc_suspend_state;
  15585. + vc_resume_state = arm_state->vc_resume_state;
  15586. + peer_count = arm_state->peer_use_count;
  15587. + vc_use_count = arm_state->videocore_use_count;
  15588. + active_services = state->unused_service;
  15589. + if (active_services > local_max_services)
  15590. + only_nonzero = 1;
  15591. +
  15592. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  15593. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  15594. + if (!service_ptr)
  15595. + continue;
  15596. +
  15597. + if (only_nonzero && !service_ptr->service_use_count)
  15598. + continue;
  15599. +
  15600. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  15601. + service_data[j].fourcc = service_ptr->base.fourcc;
  15602. + service_data[j].clientid = service_ptr->client_id;
  15603. + service_data[j++].use_count = service_ptr->
  15604. + service_use_count;
  15605. + }
  15606. + }
  15607. +
  15608. + read_unlock_bh(&arm_state->susp_res_lock);
  15609. +
  15610. + vchiq_log_warning(vchiq_susp_log_level,
  15611. + "-- Videcore suspend state: %s --",
  15612. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  15613. + vchiq_log_warning(vchiq_susp_log_level,
  15614. + "-- Videcore resume state: %s --",
  15615. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  15616. +
  15617. + if (only_nonzero)
  15618. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  15619. + "services (%d). Only dumping up to first %d services "
  15620. + "with non-zero use-count", active_services,
  15621. + local_max_services);
  15622. +
  15623. + for (i = 0; i < j; i++) {
  15624. + vchiq_log_warning(vchiq_susp_log_level,
  15625. + "----- %c%c%c%c:%d service count %d %s",
  15626. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  15627. + service_data[i].clientid,
  15628. + service_data[i].use_count,
  15629. + service_data[i].use_count ? nz : "");
  15630. + }
  15631. + vchiq_log_warning(vchiq_susp_log_level,
  15632. + "----- VCHIQ use count count %d", peer_count);
  15633. + vchiq_log_warning(vchiq_susp_log_level,
  15634. + "--- Overall vchiq instance use count %d", vc_use_count);
  15635. +
  15636. + vchiq_dump_platform_use_state(state);
  15637. +}
  15638. +
  15639. +VCHIQ_STATUS_T
  15640. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  15641. +{
  15642. + VCHIQ_ARM_STATE_T *arm_state;
  15643. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  15644. +
  15645. + if (!service || !service->state)
  15646. + goto out;
  15647. +
  15648. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  15649. +
  15650. + arm_state = vchiq_platform_get_arm_state(service->state);
  15651. +
  15652. + read_lock_bh(&arm_state->susp_res_lock);
  15653. + if (service->service_use_count)
  15654. + ret = VCHIQ_SUCCESS;
  15655. + read_unlock_bh(&arm_state->susp_res_lock);
  15656. +
  15657. + if (ret == VCHIQ_ERROR) {
  15658. + vchiq_log_error(vchiq_susp_log_level,
  15659. + "%s ERROR - %c%c%c%c:%d service count %d, "
  15660. + "state count %d, videocore suspend state %s", __func__,
  15661. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  15662. + service->client_id, service->service_use_count,
  15663. + arm_state->videocore_use_count,
  15664. + suspend_state_names[arm_state->vc_suspend_state +
  15665. + VC_SUSPEND_NUM_OFFSET]);
  15666. + vchiq_dump_service_use_state(service->state);
  15667. + }
  15668. +out:
  15669. + return ret;
  15670. +}
  15671. +
  15672. +/* stub functions */
  15673. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  15674. +{
  15675. + (void)state;
  15676. +}
  15677. +
  15678. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  15679. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  15680. +{
  15681. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  15682. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  15683. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  15684. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  15685. + write_lock_bh(&arm_state->susp_res_lock);
  15686. + if (!arm_state->first_connect) {
  15687. + char threadname[10];
  15688. + arm_state->first_connect = 1;
  15689. + write_unlock_bh(&arm_state->susp_res_lock);
  15690. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  15691. + state->id);
  15692. + arm_state->ka_thread = kthread_create(
  15693. + &vchiq_keepalive_thread_func,
  15694. + (void *)state,
  15695. + threadname);
  15696. + if (arm_state->ka_thread == NULL) {
  15697. + vchiq_log_error(vchiq_susp_log_level,
  15698. + "vchiq: FATAL: couldn't create thread %s",
  15699. + threadname);
  15700. + } else {
  15701. + wake_up_process(arm_state->ka_thread);
  15702. + }
  15703. + } else
  15704. + write_unlock_bh(&arm_state->susp_res_lock);
  15705. + }
  15706. +}
  15707. +
  15708. +
  15709. +/****************************************************************************
  15710. +*
  15711. +* vchiq_init - called when the module is loaded.
  15712. +*
  15713. +***************************************************************************/
  15714. +
  15715. +static int __init
  15716. +vchiq_init(void)
  15717. +{
  15718. + int err;
  15719. + void *ptr_err;
  15720. +
  15721. + /* create proc entries */
  15722. + err = vchiq_proc_init();
  15723. + if (err != 0)
  15724. + goto failed_proc_init;
  15725. +
  15726. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  15727. + if (err != 0) {
  15728. + vchiq_log_error(vchiq_arm_log_level,
  15729. + "Unable to allocate device number");
  15730. + goto failed_alloc_chrdev;
  15731. + }
  15732. + cdev_init(&vchiq_cdev, &vchiq_fops);
  15733. + vchiq_cdev.owner = THIS_MODULE;
  15734. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  15735. + if (err != 0) {
  15736. + vchiq_log_error(vchiq_arm_log_level,
  15737. + "Unable to register device");
  15738. + goto failed_cdev_add;
  15739. + }
  15740. +
  15741. + /* create sysfs entries */
  15742. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  15743. + ptr_err = vchiq_class;
  15744. + if (IS_ERR(ptr_err))
  15745. + goto failed_class_create;
  15746. +
  15747. + vchiq_dev = device_create(vchiq_class, NULL,
  15748. + vchiq_devid, NULL, "vchiq");
  15749. + ptr_err = vchiq_dev;
  15750. + if (IS_ERR(ptr_err))
  15751. + goto failed_device_create;
  15752. +
  15753. + err = vchiq_platform_init(&g_state);
  15754. + if (err != 0)
  15755. + goto failed_platform_init;
  15756. +
  15757. + vchiq_log_info(vchiq_arm_log_level,
  15758. + "vchiq: initialised - version %d (min %d), device %d.%d",
  15759. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  15760. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  15761. +
  15762. + return 0;
  15763. +
  15764. +failed_platform_init:
  15765. + device_destroy(vchiq_class, vchiq_devid);
  15766. +failed_device_create:
  15767. + class_destroy(vchiq_class);
  15768. +failed_class_create:
  15769. + cdev_del(&vchiq_cdev);
  15770. + err = PTR_ERR(ptr_err);
  15771. +failed_cdev_add:
  15772. + unregister_chrdev_region(vchiq_devid, 1);
  15773. +failed_alloc_chrdev:
  15774. + vchiq_proc_deinit();
  15775. +failed_proc_init:
  15776. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  15777. + return err;
  15778. +}
  15779. +
  15780. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  15781. +{
  15782. + VCHIQ_SERVICE_T *service;
  15783. + int use_count = 0, i;
  15784. + i = 0;
  15785. + while ((service = next_service_by_instance(instance->state,
  15786. + instance, &i)) != NULL) {
  15787. + use_count += service->service_use_count;
  15788. + unlock_service(service);
  15789. + }
  15790. + return use_count;
  15791. +}
  15792. +
  15793. +/* read the per-process use-count */
  15794. +static int proc_read_use_count(char *page, char **start,
  15795. + off_t off, int count,
  15796. + int *eof, void *data)
  15797. +{
  15798. + VCHIQ_INSTANCE_T instance = data;
  15799. + int len, use_count;
  15800. +
  15801. + use_count = vchiq_instance_get_use_count(instance);
  15802. + len = snprintf(page+off, count, "%d\n", use_count);
  15803. +
  15804. + return len;
  15805. +}
  15806. +
  15807. +/* add an instance (process) to the proc entries */
  15808. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  15809. +{
  15810. +#if 1
  15811. + return 0;
  15812. +#else
  15813. + char pidstr[32];
  15814. + struct proc_dir_entry *top, *use_count;
  15815. + struct proc_dir_entry *clients = vchiq_clients_top();
  15816. + int pid = instance->pid;
  15817. +
  15818. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  15819. + top = proc_mkdir(pidstr, clients);
  15820. + if (!top)
  15821. + goto fail_top;
  15822. +
  15823. + use_count = create_proc_read_entry("use_count",
  15824. + 0444, top,
  15825. + proc_read_use_count,
  15826. + instance);
  15827. + if (!use_count)
  15828. + goto fail_use_count;
  15829. +
  15830. + instance->proc_entry = top;
  15831. +
  15832. + return 0;
  15833. +
  15834. +fail_use_count:
  15835. + remove_proc_entry(top->name, clients);
  15836. +fail_top:
  15837. + return -ENOMEM;
  15838. +#endif
  15839. +}
  15840. +
  15841. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  15842. +{
  15843. +#if 0
  15844. + struct proc_dir_entry *clients = vchiq_clients_top();
  15845. + remove_proc_entry("use_count", instance->proc_entry);
  15846. + remove_proc_entry(instance->proc_entry->name, clients);
  15847. +#endif
  15848. +}
  15849. +
  15850. +/****************************************************************************
  15851. +*
  15852. +* vchiq_exit - called when the module is unloaded.
  15853. +*
  15854. +***************************************************************************/
  15855. +
  15856. +static void __exit
  15857. +vchiq_exit(void)
  15858. +{
  15859. + vchiq_platform_exit(&g_state);
  15860. + device_destroy(vchiq_class, vchiq_devid);
  15861. + class_destroy(vchiq_class);
  15862. + cdev_del(&vchiq_cdev);
  15863. + unregister_chrdev_region(vchiq_devid, 1);
  15864. +}
  15865. +
  15866. +module_init(vchiq_init);
  15867. +module_exit(vchiq_exit);
  15868. +MODULE_LICENSE("GPL");
  15869. +MODULE_AUTHOR("Broadcom Corporation");
  15870. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  15871. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  15872. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-02-07 19:57:28.000000000 +0100
  15873. @@ -0,0 +1,212 @@
  15874. +/**
  15875. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  15876. + *
  15877. + * Redistribution and use in source and binary forms, with or without
  15878. + * modification, are permitted provided that the following conditions
  15879. + * are met:
  15880. + * 1. Redistributions of source code must retain the above copyright
  15881. + * notice, this list of conditions, and the following disclaimer,
  15882. + * without modification.
  15883. + * 2. Redistributions in binary form must reproduce the above copyright
  15884. + * notice, this list of conditions and the following disclaimer in the
  15885. + * documentation and/or other materials provided with the distribution.
  15886. + * 3. The names of the above-listed copyright holders may not be used
  15887. + * to endorse or promote products derived from this software without
  15888. + * specific prior written permission.
  15889. + *
  15890. + * ALTERNATIVELY, this software may be distributed under the terms of the
  15891. + * GNU General Public License ("GPL") version 2, as published by the Free
  15892. + * Software Foundation.
  15893. + *
  15894. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  15895. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15896. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  15897. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  15898. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  15899. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  15900. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  15901. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  15902. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  15903. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  15904. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15905. + */
  15906. +
  15907. +#ifndef VCHIQ_ARM_H
  15908. +#define VCHIQ_ARM_H
  15909. +
  15910. +#include <linux/mutex.h>
  15911. +#include <linux/semaphore.h>
  15912. +#include <linux/atomic.h>
  15913. +#include "vchiq_core.h"
  15914. +
  15915. +
  15916. +enum vc_suspend_status {
  15917. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  15918. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  15919. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  15920. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  15921. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  15922. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  15923. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  15924. +};
  15925. +
  15926. +enum vc_resume_status {
  15927. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  15928. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  15929. + VC_RESUME_REQUESTED, /* User has requested resume */
  15930. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  15931. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  15932. +};
  15933. +
  15934. +
  15935. +enum USE_TYPE_E {
  15936. + USE_TYPE_SERVICE,
  15937. + USE_TYPE_SERVICE_NO_RESUME,
  15938. + USE_TYPE_VCHIQ
  15939. +};
  15940. +
  15941. +
  15942. +
  15943. +typedef struct vchiq_arm_state_struct {
  15944. + /* Keepalive-related data */
  15945. + struct task_struct *ka_thread;
  15946. + struct completion ka_evt;
  15947. + atomic_t ka_use_count;
  15948. + atomic_t ka_use_ack_count;
  15949. + atomic_t ka_release_count;
  15950. +
  15951. + struct completion vc_suspend_complete;
  15952. + struct completion vc_resume_complete;
  15953. +
  15954. + rwlock_t susp_res_lock;
  15955. + enum vc_suspend_status vc_suspend_state;
  15956. + enum vc_resume_status vc_resume_state;
  15957. +
  15958. + unsigned int wake_address;
  15959. +
  15960. + struct timer_list suspend_timer;
  15961. + int suspend_timer_timeout;
  15962. + int suspend_timer_running;
  15963. +
  15964. + /* Global use count for videocore.
  15965. + ** This is equal to the sum of the use counts for all services. When
  15966. + ** this hits zero the videocore suspend procedure will be initiated.
  15967. + */
  15968. + int videocore_use_count;
  15969. +
  15970. + /* Use count to track requests from videocore peer.
  15971. + ** This use count is not associated with a service, so needs to be
  15972. + ** tracked separately with the state.
  15973. + */
  15974. + int peer_use_count;
  15975. +
  15976. + /* Flag to indicate whether resume is blocked. This happens when the
  15977. + ** ARM is suspending
  15978. + */
  15979. + struct completion resume_blocker;
  15980. + int resume_blocked;
  15981. + struct completion blocked_blocker;
  15982. + int blocked_count;
  15983. +
  15984. + int autosuspend_override;
  15985. +
  15986. + /* Flag to indicate that the first vchiq connect has made it through.
  15987. + ** This means that both sides should be fully ready, and we should
  15988. + ** be able to suspend after this point.
  15989. + */
  15990. + int first_connect;
  15991. +
  15992. + unsigned long long suspend_start_time;
  15993. + unsigned long long sleep_start_time;
  15994. + unsigned long long resume_start_time;
  15995. + unsigned long long last_wake_time;
  15996. +
  15997. +} VCHIQ_ARM_STATE_T;
  15998. +
  15999. +extern int vchiq_arm_log_level;
  16000. +extern int vchiq_susp_log_level;
  16001. +
  16002. +extern int __init
  16003. +vchiq_platform_init(VCHIQ_STATE_T *state);
  16004. +
  16005. +extern void __exit
  16006. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  16007. +
  16008. +extern VCHIQ_STATE_T *
  16009. +vchiq_get_state(void);
  16010. +
  16011. +extern VCHIQ_STATUS_T
  16012. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  16013. +
  16014. +extern VCHIQ_STATUS_T
  16015. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  16016. +
  16017. +extern int
  16018. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  16019. +
  16020. +extern VCHIQ_STATUS_T
  16021. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  16022. +
  16023. +extern VCHIQ_STATUS_T
  16024. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  16025. +
  16026. +extern int
  16027. +vchiq_check_resume(VCHIQ_STATE_T *state);
  16028. +
  16029. +extern void
  16030. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  16031. +
  16032. +extern VCHIQ_STATUS_T
  16033. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  16034. +
  16035. +extern VCHIQ_STATUS_T
  16036. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  16037. +
  16038. +extern VCHIQ_STATUS_T
  16039. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  16040. +
  16041. +extern VCHIQ_STATUS_T
  16042. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  16043. +
  16044. +extern int
  16045. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  16046. +
  16047. +extern int
  16048. +vchiq_platform_use_suspend_timer(void);
  16049. +
  16050. +extern void
  16051. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  16052. +
  16053. +extern void
  16054. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  16055. +
  16056. +extern VCHIQ_ARM_STATE_T*
  16057. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  16058. +
  16059. +extern int
  16060. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  16061. +
  16062. +extern VCHIQ_STATUS_T
  16063. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  16064. + enum USE_TYPE_E use_type);
  16065. +extern VCHIQ_STATUS_T
  16066. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  16067. +
  16068. +void
  16069. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  16070. + enum vc_suspend_status new_state);
  16071. +
  16072. +void
  16073. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  16074. + enum vc_resume_status new_state);
  16075. +
  16076. +void
  16077. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  16078. +
  16079. +extern int vchiq_proc_init(void);
  16080. +extern void vchiq_proc_deinit(void);
  16081. +extern struct proc_dir_entry *vchiq_proc_top(void);
  16082. +extern struct proc_dir_entry *vchiq_clients_top(void);
  16083. +
  16084. +
  16085. +#endif /* VCHIQ_ARM_H */
  16086. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  16087. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  16088. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-02-07 19:57:28.000000000 +0100
  16089. @@ -0,0 +1,37 @@
  16090. +/**
  16091. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  16092. + *
  16093. + * Redistribution and use in source and binary forms, with or without
  16094. + * modification, are permitted provided that the following conditions
  16095. + * are met:
  16096. + * 1. Redistributions of source code must retain the above copyright
  16097. + * notice, this list of conditions, and the following disclaimer,
  16098. + * without modification.
  16099. + * 2. Redistributions in binary form must reproduce the above copyright
  16100. + * notice, this list of conditions and the following disclaimer in the
  16101. + * documentation and/or other materials provided with the distribution.
  16102. + * 3. The names of the above-listed copyright holders may not be used
  16103. + * to endorse or promote products derived from this software without
  16104. + * specific prior written permission.
  16105. + *
  16106. + * ALTERNATIVELY, this software may be distributed under the terms of the
  16107. + * GNU General Public License ("GPL") version 2, as published by the Free
  16108. + * Software Foundation.
  16109. + *
  16110. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16111. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16112. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16113. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16114. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16115. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16116. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  16117. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  16118. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  16119. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  16120. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16121. + */
  16122. +
  16123. +const char *vchiq_get_build_hostname(void);
  16124. +const char *vchiq_get_build_version(void);
  16125. +const char *vchiq_get_build_time(void);
  16126. +const char *vchiq_get_build_date(void);
  16127. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  16128. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  16129. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-02-07 19:57:28.000000000 +0100
  16130. @@ -0,0 +1,60 @@
  16131. +/**
  16132. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  16133. + *
  16134. + * Redistribution and use in source and binary forms, with or without
  16135. + * modification, are permitted provided that the following conditions
  16136. + * are met:
  16137. + * 1. Redistributions of source code must retain the above copyright
  16138. + * notice, this list of conditions, and the following disclaimer,
  16139. + * without modification.
  16140. + * 2. Redistributions in binary form must reproduce the above copyright
  16141. + * notice, this list of conditions and the following disclaimer in the
  16142. + * documentation and/or other materials provided with the distribution.
  16143. + * 3. The names of the above-listed copyright holders may not be used
  16144. + * to endorse or promote products derived from this software without
  16145. + * specific prior written permission.
  16146. + *
  16147. + * ALTERNATIVELY, this software may be distributed under the terms of the
  16148. + * GNU General Public License ("GPL") version 2, as published by the Free
  16149. + * Software Foundation.
  16150. + *
  16151. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16152. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16153. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16154. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16155. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16156. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16157. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  16158. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  16159. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  16160. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  16161. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16162. + */
  16163. +
  16164. +#ifndef VCHIQ_CFG_H
  16165. +#define VCHIQ_CFG_H
  16166. +
  16167. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  16168. +/* The version of VCHIQ - change with any non-trivial change */
  16169. +#define VCHIQ_VERSION 6
  16170. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  16171. +** incompatible change */
  16172. +#define VCHIQ_VERSION_MIN 3
  16173. +
  16174. +#define VCHIQ_MAX_STATES 1
  16175. +#define VCHIQ_MAX_SERVICES 4096
  16176. +#define VCHIQ_MAX_SLOTS 128
  16177. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  16178. +
  16179. +#define VCHIQ_NUM_CURRENT_BULKS 32
  16180. +#define VCHIQ_NUM_SERVICE_BULKS 4
  16181. +
  16182. +#ifndef VCHIQ_ENABLE_DEBUG
  16183. +#define VCHIQ_ENABLE_DEBUG 1
  16184. +#endif
  16185. +
  16186. +#ifndef VCHIQ_ENABLE_STATS
  16187. +#define VCHIQ_ENABLE_STATS 1
  16188. +#endif
  16189. +
  16190. +#endif /* VCHIQ_CFG_H */
  16191. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  16192. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  16193. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-02-07 19:57:28.000000000 +0100
  16194. @@ -0,0 +1,119 @@
  16195. +/**
  16196. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  16197. + *
  16198. + * Redistribution and use in source and binary forms, with or without
  16199. + * modification, are permitted provided that the following conditions
  16200. + * are met:
  16201. + * 1. Redistributions of source code must retain the above copyright
  16202. + * notice, this list of conditions, and the following disclaimer,
  16203. + * without modification.
  16204. + * 2. Redistributions in binary form must reproduce the above copyright
  16205. + * notice, this list of conditions and the following disclaimer in the
  16206. + * documentation and/or other materials provided with the distribution.
  16207. + * 3. The names of the above-listed copyright holders may not be used
  16208. + * to endorse or promote products derived from this software without
  16209. + * specific prior written permission.
  16210. + *
  16211. + * ALTERNATIVELY, this software may be distributed under the terms of the
  16212. + * GNU General Public License ("GPL") version 2, as published by the Free
  16213. + * Software Foundation.
  16214. + *
  16215. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16216. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16217. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16218. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16219. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16220. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16221. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  16222. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  16223. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  16224. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  16225. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16226. + */
  16227. +
  16228. +#include "vchiq_connected.h"
  16229. +#include "vchiq_core.h"
  16230. +#include <linux/module.h>
  16231. +#include <linux/mutex.h>
  16232. +
  16233. +#define MAX_CALLBACKS 10
  16234. +
  16235. +static int g_connected;
  16236. +static int g_num_deferred_callbacks;
  16237. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  16238. +static int g_once_init;
  16239. +static struct mutex g_connected_mutex;
  16240. +
  16241. +/****************************************************************************
  16242. +*
  16243. +* Function to initialize our lock.
  16244. +*
  16245. +***************************************************************************/
  16246. +
  16247. +static void connected_init(void)
  16248. +{
  16249. + if (!g_once_init) {
  16250. + mutex_init(&g_connected_mutex);
  16251. + g_once_init = 1;
  16252. + }
  16253. +}
  16254. +
  16255. +/****************************************************************************
  16256. +*
  16257. +* This function is used to defer initialization until the vchiq stack is
  16258. +* initialized. If the stack is already initialized, then the callback will
  16259. +* be made immediately, otherwise it will be deferred until
  16260. +* vchiq_call_connected_callbacks is called.
  16261. +*
  16262. +***************************************************************************/
  16263. +
  16264. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  16265. +{
  16266. + connected_init();
  16267. +
  16268. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  16269. + return;
  16270. +
  16271. + if (g_connected)
  16272. + /* We're already connected. Call the callback immediately. */
  16273. +
  16274. + callback();
  16275. + else {
  16276. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  16277. + vchiq_log_error(vchiq_core_log_level,
  16278. + "There already %d callback registered - "
  16279. + "please increase MAX_CALLBACKS",
  16280. + g_num_deferred_callbacks);
  16281. + else {
  16282. + g_deferred_callback[g_num_deferred_callbacks] =
  16283. + callback;
  16284. + g_num_deferred_callbacks++;
  16285. + }
  16286. + }
  16287. + mutex_unlock(&g_connected_mutex);
  16288. +}
  16289. +
  16290. +/****************************************************************************
  16291. +*
  16292. +* This function is called by the vchiq stack once it has been connected to
  16293. +* the videocore and clients can start to use the stack.
  16294. +*
  16295. +***************************************************************************/
  16296. +
  16297. +void vchiq_call_connected_callbacks(void)
  16298. +{
  16299. + int i;
  16300. +
  16301. + connected_init();
  16302. +
  16303. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  16304. + return;
  16305. +
  16306. + for (i = 0; i < g_num_deferred_callbacks; i++)
  16307. + g_deferred_callback[i]();
  16308. +
  16309. + g_num_deferred_callbacks = 0;
  16310. + g_connected = 1;
  16311. + mutex_unlock(&g_connected_mutex);
  16312. +}
  16313. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  16314. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  16315. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  16316. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-02-07 19:57:28.000000000 +0100
  16317. @@ -0,0 +1,50 @@
  16318. +/**
  16319. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  16320. + *
  16321. + * Redistribution and use in source and binary forms, with or without
  16322. + * modification, are permitted provided that the following conditions
  16323. + * are met:
  16324. + * 1. Redistributions of source code must retain the above copyright
  16325. + * notice, this list of conditions, and the following disclaimer,
  16326. + * without modification.
  16327. + * 2. Redistributions in binary form must reproduce the above copyright
  16328. + * notice, this list of conditions and the following disclaimer in the
  16329. + * documentation and/or other materials provided with the distribution.
  16330. + * 3. The names of the above-listed copyright holders may not be used
  16331. + * to endorse or promote products derived from this software without
  16332. + * specific prior written permission.
  16333. + *
  16334. + * ALTERNATIVELY, this software may be distributed under the terms of the
  16335. + * GNU General Public License ("GPL") version 2, as published by the Free
  16336. + * Software Foundation.
  16337. + *
  16338. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16339. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16340. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16341. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16342. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16343. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16344. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  16345. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  16346. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  16347. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  16348. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16349. + */
  16350. +
  16351. +#ifndef VCHIQ_CONNECTED_H
  16352. +#define VCHIQ_CONNECTED_H
  16353. +
  16354. +/* ---- Include Files ----------------------------------------------------- */
  16355. +
  16356. +/* ---- Constants and Types ---------------------------------------------- */
  16357. +
  16358. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  16359. +
  16360. +/* ---- Variable Externs ------------------------------------------------- */
  16361. +
  16362. +/* ---- Function Prototypes ---------------------------------------------- */
  16363. +
  16364. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  16365. +void vchiq_call_connected_callbacks(void);
  16366. +
  16367. +#endif /* VCHIQ_CONNECTED_H */
  16368. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  16369. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  16370. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-02-07 19:57:28.000000000 +0100
  16371. @@ -0,0 +1,3824 @@
  16372. +/**
  16373. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  16374. + *
  16375. + * Redistribution and use in source and binary forms, with or without
  16376. + * modification, are permitted provided that the following conditions
  16377. + * are met:
  16378. + * 1. Redistributions of source code must retain the above copyright
  16379. + * notice, this list of conditions, and the following disclaimer,
  16380. + * without modification.
  16381. + * 2. Redistributions in binary form must reproduce the above copyright
  16382. + * notice, this list of conditions and the following disclaimer in the
  16383. + * documentation and/or other materials provided with the distribution.
  16384. + * 3. The names of the above-listed copyright holders may not be used
  16385. + * to endorse or promote products derived from this software without
  16386. + * specific prior written permission.
  16387. + *
  16388. + * ALTERNATIVELY, this software may be distributed under the terms of the
  16389. + * GNU General Public License ("GPL") version 2, as published by the Free
  16390. + * Software Foundation.
  16391. + *
  16392. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16393. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16394. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16395. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16396. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16397. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16398. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  16399. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  16400. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  16401. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  16402. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16403. + */
  16404. +
  16405. +#include "vchiq_core.h"
  16406. +
  16407. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  16408. +
  16409. +#define HANDLE_STATE_SHIFT 12
  16410. +
  16411. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  16412. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  16413. +#define SLOT_INDEX_FROM_DATA(state, data) \
  16414. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  16415. + VCHIQ_SLOT_SIZE)
  16416. +#define SLOT_INDEX_FROM_INFO(state, info) \
  16417. + ((unsigned int)(info - state->slot_info))
  16418. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  16419. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  16420. +
  16421. +
  16422. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  16423. +
  16424. +
  16425. +struct vchiq_open_payload {
  16426. + int fourcc;
  16427. + int client_id;
  16428. + short version;
  16429. + short version_min;
  16430. +};
  16431. +
  16432. +struct vchiq_openack_payload {
  16433. + short version;
  16434. +};
  16435. +
  16436. +/* we require this for consistency between endpoints */
  16437. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  16438. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  16439. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  16440. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  16441. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  16442. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  16443. +
  16444. +/* Run time control of log level, based on KERN_XXX level. */
  16445. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  16446. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  16447. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  16448. +
  16449. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  16450. +
  16451. +static DEFINE_SPINLOCK(service_spinlock);
  16452. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  16453. +DEFINE_SPINLOCK(quota_spinlock);
  16454. +
  16455. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  16456. +static unsigned int handle_seq;
  16457. +
  16458. +static const char *const srvstate_names[] = {
  16459. + "FREE",
  16460. + "HIDDEN",
  16461. + "LISTENING",
  16462. + "OPENING",
  16463. + "OPEN",
  16464. + "OPENSYNC",
  16465. + "CLOSESENT",
  16466. + "CLOSERECVD",
  16467. + "CLOSEWAIT",
  16468. + "CLOSED"
  16469. +};
  16470. +
  16471. +static const char *const reason_names[] = {
  16472. + "SERVICE_OPENED",
  16473. + "SERVICE_CLOSED",
  16474. + "MESSAGE_AVAILABLE",
  16475. + "BULK_TRANSMIT_DONE",
  16476. + "BULK_RECEIVE_DONE",
  16477. + "BULK_TRANSMIT_ABORTED",
  16478. + "BULK_RECEIVE_ABORTED"
  16479. +};
  16480. +
  16481. +static const char *const conn_state_names[] = {
  16482. + "DISCONNECTED",
  16483. + "CONNECTING",
  16484. + "CONNECTED",
  16485. + "PAUSING",
  16486. + "PAUSE_SENT",
  16487. + "PAUSED",
  16488. + "RESUMING",
  16489. + "PAUSE_TIMEOUT",
  16490. + "RESUME_TIMEOUT"
  16491. +};
  16492. +
  16493. +
  16494. +static void
  16495. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  16496. +
  16497. +static const char *msg_type_str(unsigned int msg_type)
  16498. +{
  16499. + switch (msg_type) {
  16500. + case VCHIQ_MSG_PADDING: return "PADDING";
  16501. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  16502. + case VCHIQ_MSG_OPEN: return "OPEN";
  16503. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  16504. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  16505. + case VCHIQ_MSG_DATA: return "DATA";
  16506. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  16507. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  16508. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  16509. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  16510. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  16511. + case VCHIQ_MSG_RESUME: return "RESUME";
  16512. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  16513. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  16514. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  16515. + }
  16516. + return "???";
  16517. +}
  16518. +
  16519. +static inline void
  16520. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  16521. +{
  16522. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  16523. + service->state->id, service->localport,
  16524. + srvstate_names[service->srvstate],
  16525. + srvstate_names[newstate]);
  16526. + service->srvstate = newstate;
  16527. +}
  16528. +
  16529. +VCHIQ_SERVICE_T *
  16530. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  16531. +{
  16532. + VCHIQ_SERVICE_T *service;
  16533. +
  16534. + spin_lock(&service_spinlock);
  16535. + service = handle_to_service(handle);
  16536. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  16537. + (service->handle == handle)) {
  16538. + BUG_ON(service->ref_count == 0);
  16539. + service->ref_count++;
  16540. + } else
  16541. + service = NULL;
  16542. + spin_unlock(&service_spinlock);
  16543. +
  16544. + if (!service)
  16545. + vchiq_log_info(vchiq_core_log_level,
  16546. + "Invalid service handle 0x%x", handle);
  16547. +
  16548. + return service;
  16549. +}
  16550. +
  16551. +VCHIQ_SERVICE_T *
  16552. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  16553. +{
  16554. + VCHIQ_SERVICE_T *service = NULL;
  16555. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  16556. + spin_lock(&service_spinlock);
  16557. + service = state->services[localport];
  16558. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  16559. + BUG_ON(service->ref_count == 0);
  16560. + service->ref_count++;
  16561. + } else
  16562. + service = NULL;
  16563. + spin_unlock(&service_spinlock);
  16564. + }
  16565. +
  16566. + if (!service)
  16567. + vchiq_log_info(vchiq_core_log_level,
  16568. + "Invalid port %d", localport);
  16569. +
  16570. + return service;
  16571. +}
  16572. +
  16573. +VCHIQ_SERVICE_T *
  16574. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  16575. + VCHIQ_SERVICE_HANDLE_T handle) {
  16576. + VCHIQ_SERVICE_T *service;
  16577. +
  16578. + spin_lock(&service_spinlock);
  16579. + service = handle_to_service(handle);
  16580. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  16581. + (service->handle == handle) &&
  16582. + (service->instance == instance)) {
  16583. + BUG_ON(service->ref_count == 0);
  16584. + service->ref_count++;
  16585. + } else
  16586. + service = NULL;
  16587. + spin_unlock(&service_spinlock);
  16588. +
  16589. + if (!service)
  16590. + vchiq_log_info(vchiq_core_log_level,
  16591. + "Invalid service handle 0x%x", handle);
  16592. +
  16593. + return service;
  16594. +}
  16595. +
  16596. +VCHIQ_SERVICE_T *
  16597. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  16598. + int *pidx)
  16599. +{
  16600. + VCHIQ_SERVICE_T *service = NULL;
  16601. + int idx = *pidx;
  16602. +
  16603. + spin_lock(&service_spinlock);
  16604. + while (idx < state->unused_service) {
  16605. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  16606. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  16607. + (srv->instance == instance)) {
  16608. + service = srv;
  16609. + BUG_ON(service->ref_count == 0);
  16610. + service->ref_count++;
  16611. + break;
  16612. + }
  16613. + }
  16614. + spin_unlock(&service_spinlock);
  16615. +
  16616. + *pidx = idx;
  16617. +
  16618. + return service;
  16619. +}
  16620. +
  16621. +void
  16622. +lock_service(VCHIQ_SERVICE_T *service)
  16623. +{
  16624. + spin_lock(&service_spinlock);
  16625. + BUG_ON(!service || (service->ref_count == 0));
  16626. + if (service)
  16627. + service->ref_count++;
  16628. + spin_unlock(&service_spinlock);
  16629. +}
  16630. +
  16631. +void
  16632. +unlock_service(VCHIQ_SERVICE_T *service)
  16633. +{
  16634. + VCHIQ_STATE_T *state = service->state;
  16635. + spin_lock(&service_spinlock);
  16636. + BUG_ON(!service || (service->ref_count == 0));
  16637. + if (service && service->ref_count) {
  16638. + service->ref_count--;
  16639. + if (!service->ref_count) {
  16640. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  16641. + state->services[service->localport] = NULL;
  16642. + } else
  16643. + service = NULL;
  16644. + }
  16645. + spin_unlock(&service_spinlock);
  16646. +
  16647. + if (service && service->userdata_term)
  16648. + service->userdata_term(service->base.userdata);
  16649. +
  16650. + kfree(service);
  16651. +}
  16652. +
  16653. +int
  16654. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  16655. +{
  16656. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  16657. + int id;
  16658. +
  16659. + id = service ? service->client_id : 0;
  16660. + if (service)
  16661. + unlock_service(service);
  16662. +
  16663. + return id;
  16664. +}
  16665. +
  16666. +void *
  16667. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  16668. +{
  16669. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  16670. +
  16671. + return service ? service->base.userdata : NULL;
  16672. +}
  16673. +
  16674. +int
  16675. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  16676. +{
  16677. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  16678. +
  16679. + return service ? service->base.fourcc : 0;
  16680. +}
  16681. +
  16682. +static void
  16683. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  16684. +{
  16685. + VCHIQ_STATE_T *state = service->state;
  16686. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  16687. +
  16688. + service->closing = 1;
  16689. +
  16690. + /* Synchronise with other threads. */
  16691. + mutex_lock(&state->recycle_mutex);
  16692. + mutex_unlock(&state->recycle_mutex);
  16693. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  16694. + /* If we're pausing then the slot_mutex is held until resume
  16695. + * by the slot handler. Therefore don't try to acquire this
  16696. + * mutex if we're the slot handler and in the pause sent state.
  16697. + * We don't need to in this case anyway. */
  16698. + mutex_lock(&state->slot_mutex);
  16699. + mutex_unlock(&state->slot_mutex);
  16700. + }
  16701. +
  16702. + /* Unblock any sending thread. */
  16703. + service_quota = &state->service_quotas[service->localport];
  16704. + up(&service_quota->quota_event);
  16705. +}
  16706. +
  16707. +static void
  16708. +mark_service_closing(VCHIQ_SERVICE_T *service)
  16709. +{
  16710. + mark_service_closing_internal(service, 0);
  16711. +}
  16712. +
  16713. +static inline VCHIQ_STATUS_T
  16714. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  16715. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  16716. +{
  16717. + VCHIQ_STATUS_T status;
  16718. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  16719. + service->state->id, service->localport, reason_names[reason],
  16720. + (unsigned int)header, (unsigned int)bulk_userdata);
  16721. + status = service->base.callback(reason, header, service->handle,
  16722. + bulk_userdata);
  16723. + if (status == VCHIQ_ERROR) {
  16724. + vchiq_log_warning(vchiq_core_log_level,
  16725. + "%d: ignoring ERROR from callback to service %x",
  16726. + service->state->id, service->handle);
  16727. + status = VCHIQ_SUCCESS;
  16728. + }
  16729. + return status;
  16730. +}
  16731. +
  16732. +inline void
  16733. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  16734. +{
  16735. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  16736. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  16737. + conn_state_names[oldstate],
  16738. + conn_state_names[newstate]);
  16739. + state->conn_state = newstate;
  16740. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  16741. +}
  16742. +
  16743. +static inline void
  16744. +remote_event_create(REMOTE_EVENT_T *event)
  16745. +{
  16746. + event->armed = 0;
  16747. + /* Don't clear the 'fired' flag because it may already have been set
  16748. + ** by the other side. */
  16749. + sema_init(event->event, 0);
  16750. +}
  16751. +
  16752. +static inline void
  16753. +remote_event_destroy(REMOTE_EVENT_T *event)
  16754. +{
  16755. + (void)event;
  16756. +}
  16757. +
  16758. +static inline int
  16759. +remote_event_wait(REMOTE_EVENT_T *event)
  16760. +{
  16761. + if (!event->fired) {
  16762. + event->armed = 1;
  16763. + dsb();
  16764. + if (!event->fired) {
  16765. + if (down_interruptible(event->event) != 0) {
  16766. + event->armed = 0;
  16767. + return 0;
  16768. + }
  16769. + }
  16770. + event->armed = 0;
  16771. + wmb();
  16772. + }
  16773. +
  16774. + event->fired = 0;
  16775. + return 1;
  16776. +}
  16777. +
  16778. +static inline void
  16779. +remote_event_signal_local(REMOTE_EVENT_T *event)
  16780. +{
  16781. + event->armed = 0;
  16782. + up(event->event);
  16783. +}
  16784. +
  16785. +static inline void
  16786. +remote_event_poll(REMOTE_EVENT_T *event)
  16787. +{
  16788. + if (event->fired && event->armed)
  16789. + remote_event_signal_local(event);
  16790. +}
  16791. +
  16792. +void
  16793. +remote_event_pollall(VCHIQ_STATE_T *state)
  16794. +{
  16795. + remote_event_poll(&state->local->sync_trigger);
  16796. + remote_event_poll(&state->local->sync_release);
  16797. + remote_event_poll(&state->local->trigger);
  16798. + remote_event_poll(&state->local->recycle);
  16799. +}
  16800. +
  16801. +/* Round up message sizes so that any space at the end of a slot is always big
  16802. +** enough for a header. This relies on header size being a power of two, which
  16803. +** has been verified earlier by a static assertion. */
  16804. +
  16805. +static inline unsigned int
  16806. +calc_stride(unsigned int size)
  16807. +{
  16808. + /* Allow room for the header */
  16809. + size += sizeof(VCHIQ_HEADER_T);
  16810. +
  16811. + /* Round up */
  16812. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  16813. + - 1);
  16814. +}
  16815. +
  16816. +/* Called by the slot handler thread */
  16817. +static VCHIQ_SERVICE_T *
  16818. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  16819. +{
  16820. + int i;
  16821. +
  16822. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  16823. +
  16824. + for (i = 0; i < state->unused_service; i++) {
  16825. + VCHIQ_SERVICE_T *service = state->services[i];
  16826. + if (service &&
  16827. + (service->public_fourcc == fourcc) &&
  16828. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  16829. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  16830. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  16831. + lock_service(service);
  16832. + return service;
  16833. + }
  16834. + }
  16835. +
  16836. + return NULL;
  16837. +}
  16838. +
  16839. +/* Called by the slot handler thread */
  16840. +static VCHIQ_SERVICE_T *
  16841. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  16842. +{
  16843. + int i;
  16844. + for (i = 0; i < state->unused_service; i++) {
  16845. + VCHIQ_SERVICE_T *service = state->services[i];
  16846. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  16847. + && (service->remoteport == port)) {
  16848. + lock_service(service);
  16849. + return service;
  16850. + }
  16851. + }
  16852. + return NULL;
  16853. +}
  16854. +
  16855. +inline void
  16856. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  16857. +{
  16858. + uint32_t value;
  16859. +
  16860. + if (service) {
  16861. + do {
  16862. + value = atomic_read(&service->poll_flags);
  16863. + } while (atomic_cmpxchg(&service->poll_flags, value,
  16864. + value | (1 << poll_type)) != value);
  16865. +
  16866. + do {
  16867. + value = atomic_read(&state->poll_services[
  16868. + service->localport>>5]);
  16869. + } while (atomic_cmpxchg(
  16870. + &state->poll_services[service->localport>>5],
  16871. + value, value | (1 << (service->localport & 0x1f)))
  16872. + != value);
  16873. + }
  16874. +
  16875. + state->poll_needed = 1;
  16876. + wmb();
  16877. +
  16878. + /* ... and ensure the slot handler runs. */
  16879. + remote_event_signal_local(&state->local->trigger);
  16880. +}
  16881. +
  16882. +/* Called from queue_message, by the slot handler and application threads,
  16883. +** with slot_mutex held */
  16884. +static VCHIQ_HEADER_T *
  16885. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  16886. +{
  16887. + VCHIQ_SHARED_STATE_T *local = state->local;
  16888. + int tx_pos = state->local_tx_pos;
  16889. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  16890. +
  16891. + if (space > slot_space) {
  16892. + VCHIQ_HEADER_T *header;
  16893. + /* Fill the remaining space with padding */
  16894. + WARN_ON(state->tx_data == NULL);
  16895. + header = (VCHIQ_HEADER_T *)
  16896. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  16897. + header->msgid = VCHIQ_MSGID_PADDING;
  16898. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  16899. +
  16900. + tx_pos += slot_space;
  16901. + }
  16902. +
  16903. + /* If necessary, get the next slot. */
  16904. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  16905. + int slot_index;
  16906. +
  16907. + /* If there is no free slot... */
  16908. +
  16909. + if (down_trylock(&state->slot_available_event) != 0) {
  16910. + /* ...wait for one. */
  16911. +
  16912. + VCHIQ_STATS_INC(state, slot_stalls);
  16913. +
  16914. + /* But first, flush through the last slot. */
  16915. + state->local_tx_pos = tx_pos;
  16916. + local->tx_pos = tx_pos;
  16917. + remote_event_signal(&state->remote->trigger);
  16918. +
  16919. + if (!is_blocking ||
  16920. + (down_interruptible(
  16921. + &state->slot_available_event) != 0))
  16922. + return NULL; /* No space available */
  16923. + }
  16924. +
  16925. + BUG_ON(tx_pos ==
  16926. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  16927. +
  16928. + slot_index = local->slot_queue[
  16929. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  16930. + VCHIQ_SLOT_QUEUE_MASK];
  16931. + state->tx_data =
  16932. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  16933. + }
  16934. +
  16935. + state->local_tx_pos = tx_pos + space;
  16936. +
  16937. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  16938. +}
  16939. +
  16940. +/* Called by the recycle thread. */
  16941. +static void
  16942. +process_free_queue(VCHIQ_STATE_T *state)
  16943. +{
  16944. + VCHIQ_SHARED_STATE_T *local = state->local;
  16945. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  16946. + int slot_queue_available;
  16947. +
  16948. + /* Use a read memory barrier to ensure that any state that may have
  16949. + ** been modified by another thread is not masked by stale prefetched
  16950. + ** values. */
  16951. + rmb();
  16952. +
  16953. + /* Find slots which have been freed by the other side, and return them
  16954. + ** to the available queue. */
  16955. + slot_queue_available = state->slot_queue_available;
  16956. +
  16957. + while (slot_queue_available != local->slot_queue_recycle) {
  16958. + unsigned int pos;
  16959. + int slot_index = local->slot_queue[slot_queue_available++ &
  16960. + VCHIQ_SLOT_QUEUE_MASK];
  16961. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  16962. + int data_found = 0;
  16963. +
  16964. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  16965. + state->id, slot_index, (unsigned int)data,
  16966. + local->slot_queue_recycle, slot_queue_available);
  16967. +
  16968. + /* Initialise the bitmask for services which have used this
  16969. + ** slot */
  16970. + BITSET_ZERO(service_found);
  16971. +
  16972. + pos = 0;
  16973. +
  16974. + while (pos < VCHIQ_SLOT_SIZE) {
  16975. + VCHIQ_HEADER_T *header =
  16976. + (VCHIQ_HEADER_T *)(data + pos);
  16977. + int msgid = header->msgid;
  16978. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  16979. + int port = VCHIQ_MSG_SRCPORT(msgid);
  16980. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  16981. + &state->service_quotas[port];
  16982. + int count;
  16983. + spin_lock(&quota_spinlock);
  16984. + count = service_quota->message_use_count;
  16985. + if (count > 0)
  16986. + service_quota->message_use_count =
  16987. + count - 1;
  16988. + spin_unlock(&quota_spinlock);
  16989. +
  16990. + if (count == service_quota->message_quota)
  16991. + /* Signal the service that it
  16992. + ** has dropped below its quota
  16993. + */
  16994. + up(&service_quota->quota_event);
  16995. + else if (count == 0) {
  16996. + vchiq_log_error(vchiq_core_log_level,
  16997. + "service %d "
  16998. + "message_use_count=%d "
  16999. + "(header %x, msgid %x, "
  17000. + "header->msgid %x, "
  17001. + "header->size %x)",
  17002. + port,
  17003. + service_quota->
  17004. + message_use_count,
  17005. + (unsigned int)header, msgid,
  17006. + header->msgid,
  17007. + header->size);
  17008. + WARN(1, "invalid message use count\n");
  17009. + }
  17010. + if (!BITSET_IS_SET(service_found, port)) {
  17011. + /* Set the found bit for this service */
  17012. + BITSET_SET(service_found, port);
  17013. +
  17014. + spin_lock(&quota_spinlock);
  17015. + count = service_quota->slot_use_count;
  17016. + if (count > 0)
  17017. + service_quota->slot_use_count =
  17018. + count - 1;
  17019. + spin_unlock(&quota_spinlock);
  17020. +
  17021. + if (count > 0) {
  17022. + /* Signal the service in case
  17023. + ** it has dropped below its
  17024. + ** quota */
  17025. + up(&service_quota->quota_event);
  17026. + vchiq_log_trace(
  17027. + vchiq_core_log_level,
  17028. + "%d: pfq:%d %x@%x - "
  17029. + "slot_use->%d",
  17030. + state->id, port,
  17031. + header->size,
  17032. + (unsigned int)header,
  17033. + count - 1);
  17034. + } else {
  17035. + vchiq_log_error(
  17036. + vchiq_core_log_level,
  17037. + "service %d "
  17038. + "slot_use_count"
  17039. + "=%d (header %x"
  17040. + ", msgid %x, "
  17041. + "header->msgid"
  17042. + " %x, header->"
  17043. + "size %x)",
  17044. + port, count,
  17045. + (unsigned int)header,
  17046. + msgid,
  17047. + header->msgid,
  17048. + header->size);
  17049. + WARN(1, "bad slot use count\n");
  17050. + }
  17051. + }
  17052. +
  17053. + data_found = 1;
  17054. + }
  17055. +
  17056. + pos += calc_stride(header->size);
  17057. + if (pos > VCHIQ_SLOT_SIZE) {
  17058. + vchiq_log_error(vchiq_core_log_level,
  17059. + "pfq - pos %x: header %x, msgid %x, "
  17060. + "header->msgid %x, header->size %x",
  17061. + pos, (unsigned int)header, msgid,
  17062. + header->msgid, header->size);
  17063. + WARN(1, "invalid slot position\n");
  17064. + }
  17065. + }
  17066. +
  17067. + if (data_found) {
  17068. + int count;
  17069. + spin_lock(&quota_spinlock);
  17070. + count = state->data_use_count;
  17071. + if (count > 0)
  17072. + state->data_use_count =
  17073. + count - 1;
  17074. + spin_unlock(&quota_spinlock);
  17075. + if (count == state->data_quota)
  17076. + up(&state->data_quota_event);
  17077. + }
  17078. +
  17079. + state->slot_queue_available = slot_queue_available;
  17080. + up(&state->slot_available_event);
  17081. + }
  17082. +}
  17083. +
  17084. +/* Called by the slot handler and application threads */
  17085. +static VCHIQ_STATUS_T
  17086. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  17087. + int msgid, const VCHIQ_ELEMENT_T *elements,
  17088. + int count, int size, int is_blocking)
  17089. +{
  17090. + VCHIQ_SHARED_STATE_T *local;
  17091. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  17092. + VCHIQ_HEADER_T *header;
  17093. + int type = VCHIQ_MSG_TYPE(msgid);
  17094. +
  17095. + unsigned int stride;
  17096. +
  17097. + local = state->local;
  17098. +
  17099. + stride = calc_stride(size);
  17100. +
  17101. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  17102. +
  17103. + if ((type != VCHIQ_MSG_RESUME) &&
  17104. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  17105. + return VCHIQ_RETRY;
  17106. +
  17107. + if (type == VCHIQ_MSG_DATA) {
  17108. + int tx_end_index;
  17109. +
  17110. + BUG_ON(!service);
  17111. +
  17112. + if (service->closing) {
  17113. + /* The service has been closed */
  17114. + mutex_unlock(&state->slot_mutex);
  17115. + return VCHIQ_ERROR;
  17116. + }
  17117. +
  17118. + service_quota = &state->service_quotas[service->localport];
  17119. +
  17120. + spin_lock(&quota_spinlock);
  17121. +
  17122. + /* Ensure this service doesn't use more than its quota of
  17123. + ** messages or slots */
  17124. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  17125. + state->local_tx_pos + stride - 1);
  17126. +
  17127. + /* Ensure data messages don't use more than their quota of
  17128. + ** slots */
  17129. + while ((tx_end_index != state->previous_data_index) &&
  17130. + (state->data_use_count == state->data_quota)) {
  17131. + VCHIQ_STATS_INC(state, data_stalls);
  17132. + spin_unlock(&quota_spinlock);
  17133. + mutex_unlock(&state->slot_mutex);
  17134. +
  17135. + if (down_interruptible(&state->data_quota_event)
  17136. + != 0)
  17137. + return VCHIQ_RETRY;
  17138. +
  17139. + mutex_lock(&state->slot_mutex);
  17140. + spin_lock(&quota_spinlock);
  17141. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  17142. + state->local_tx_pos + stride - 1);
  17143. + if ((tx_end_index == state->previous_data_index) ||
  17144. + (state->data_use_count < state->data_quota)) {
  17145. + /* Pass the signal on to other waiters */
  17146. + up(&state->data_quota_event);
  17147. + break;
  17148. + }
  17149. + }
  17150. +
  17151. + while ((service_quota->message_use_count ==
  17152. + service_quota->message_quota) ||
  17153. + ((tx_end_index != service_quota->previous_tx_index) &&
  17154. + (service_quota->slot_use_count ==
  17155. + service_quota->slot_quota))) {
  17156. + spin_unlock(&quota_spinlock);
  17157. + vchiq_log_trace(vchiq_core_log_level,
  17158. + "%d: qm:%d %s,%x - quota stall "
  17159. + "(msg %d, slot %d)",
  17160. + state->id, service->localport,
  17161. + msg_type_str(type), size,
  17162. + service_quota->message_use_count,
  17163. + service_quota->slot_use_count);
  17164. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  17165. + mutex_unlock(&state->slot_mutex);
  17166. + if (down_interruptible(&service_quota->quota_event)
  17167. + != 0)
  17168. + return VCHIQ_RETRY;
  17169. + if (service->closing)
  17170. + return VCHIQ_ERROR;
  17171. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  17172. + return VCHIQ_RETRY;
  17173. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  17174. + /* The service has been closed */
  17175. + mutex_unlock(&state->slot_mutex);
  17176. + return VCHIQ_ERROR;
  17177. + }
  17178. + spin_lock(&quota_spinlock);
  17179. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  17180. + state->local_tx_pos + stride - 1);
  17181. + }
  17182. +
  17183. + spin_unlock(&quota_spinlock);
  17184. + }
  17185. +
  17186. + header = reserve_space(state, stride, is_blocking);
  17187. +
  17188. + if (!header) {
  17189. + if (service)
  17190. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  17191. + mutex_unlock(&state->slot_mutex);
  17192. + return VCHIQ_RETRY;
  17193. + }
  17194. +
  17195. + if (type == VCHIQ_MSG_DATA) {
  17196. + int i, pos;
  17197. + int tx_end_index;
  17198. + int slot_use_count;
  17199. +
  17200. + vchiq_log_info(vchiq_core_log_level,
  17201. + "%d: qm %s@%x,%x (%d->%d)",
  17202. + state->id,
  17203. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17204. + (unsigned int)header, size,
  17205. + VCHIQ_MSG_SRCPORT(msgid),
  17206. + VCHIQ_MSG_DSTPORT(msgid));
  17207. +
  17208. + BUG_ON(!service);
  17209. +
  17210. + for (i = 0, pos = 0; i < (unsigned int)count;
  17211. + pos += elements[i++].size)
  17212. + if (elements[i].size) {
  17213. + if (vchiq_copy_from_user
  17214. + (header->data + pos, elements[i].data,
  17215. + (size_t) elements[i].size) !=
  17216. + VCHIQ_SUCCESS) {
  17217. + mutex_unlock(&state->slot_mutex);
  17218. + VCHIQ_SERVICE_STATS_INC(service,
  17219. + error_count);
  17220. + return VCHIQ_ERROR;
  17221. + }
  17222. + if (i == 0) {
  17223. + if (vchiq_core_msg_log_level >=
  17224. + VCHIQ_LOG_INFO)
  17225. + vchiq_log_dump_mem("Sent", 0,
  17226. + header->data + pos,
  17227. + min(64u,
  17228. + elements[0].size));
  17229. + }
  17230. + }
  17231. +
  17232. + spin_lock(&quota_spinlock);
  17233. + service_quota->message_use_count++;
  17234. +
  17235. + tx_end_index =
  17236. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  17237. +
  17238. + /* If this transmission can't fit in the last slot used by any
  17239. + ** service, the data_use_count must be increased. */
  17240. + if (tx_end_index != state->previous_data_index) {
  17241. + state->previous_data_index = tx_end_index;
  17242. + state->data_use_count++;
  17243. + }
  17244. +
  17245. + /* If this isn't the same slot last used by this service,
  17246. + ** the service's slot_use_count must be increased. */
  17247. + if (tx_end_index != service_quota->previous_tx_index) {
  17248. + service_quota->previous_tx_index = tx_end_index;
  17249. + slot_use_count = ++service_quota->slot_use_count;
  17250. + } else {
  17251. + slot_use_count = 0;
  17252. + }
  17253. +
  17254. + spin_unlock(&quota_spinlock);
  17255. +
  17256. + if (slot_use_count)
  17257. + vchiq_log_trace(vchiq_core_log_level,
  17258. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  17259. + state->id, service->localport,
  17260. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  17261. + slot_use_count, header);
  17262. +
  17263. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  17264. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  17265. + } else {
  17266. + vchiq_log_info(vchiq_core_log_level,
  17267. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  17268. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17269. + (unsigned int)header, size,
  17270. + VCHIQ_MSG_SRCPORT(msgid),
  17271. + VCHIQ_MSG_DSTPORT(msgid));
  17272. + if (size != 0) {
  17273. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  17274. + memcpy(header->data, elements[0].data,
  17275. + elements[0].size);
  17276. + }
  17277. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  17278. + }
  17279. +
  17280. + header->msgid = msgid;
  17281. + header->size = size;
  17282. +
  17283. + {
  17284. + int svc_fourcc;
  17285. +
  17286. + svc_fourcc = service
  17287. + ? service->base.fourcc
  17288. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  17289. +
  17290. + vchiq_log_info(vchiq_core_msg_log_level,
  17291. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  17292. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17293. + VCHIQ_MSG_TYPE(msgid),
  17294. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  17295. + VCHIQ_MSG_SRCPORT(msgid),
  17296. + VCHIQ_MSG_DSTPORT(msgid),
  17297. + size);
  17298. + }
  17299. +
  17300. + /* Make sure the new header is visible to the peer. */
  17301. + wmb();
  17302. +
  17303. + /* Make the new tx_pos visible to the peer. */
  17304. + local->tx_pos = state->local_tx_pos;
  17305. + wmb();
  17306. +
  17307. + if (service && (type == VCHIQ_MSG_CLOSE))
  17308. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  17309. +
  17310. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  17311. + mutex_unlock(&state->slot_mutex);
  17312. +
  17313. + remote_event_signal(&state->remote->trigger);
  17314. +
  17315. + return VCHIQ_SUCCESS;
  17316. +}
  17317. +
  17318. +/* Called by the slot handler and application threads */
  17319. +static VCHIQ_STATUS_T
  17320. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  17321. + int msgid, const VCHIQ_ELEMENT_T *elements,
  17322. + int count, int size, int is_blocking)
  17323. +{
  17324. + VCHIQ_SHARED_STATE_T *local;
  17325. + VCHIQ_HEADER_T *header;
  17326. +
  17327. + local = state->local;
  17328. +
  17329. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  17330. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  17331. + return VCHIQ_RETRY;
  17332. +
  17333. + remote_event_wait(&local->sync_release);
  17334. +
  17335. + rmb();
  17336. +
  17337. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  17338. + local->slot_sync);
  17339. +
  17340. + {
  17341. + int oldmsgid = header->msgid;
  17342. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  17343. + vchiq_log_error(vchiq_core_log_level,
  17344. + "%d: qms - msgid %x, not PADDING",
  17345. + state->id, oldmsgid);
  17346. + }
  17347. +
  17348. + if (service) {
  17349. + int i, pos;
  17350. +
  17351. + vchiq_log_info(vchiq_sync_log_level,
  17352. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  17353. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17354. + (unsigned int)header, size,
  17355. + VCHIQ_MSG_SRCPORT(msgid),
  17356. + VCHIQ_MSG_DSTPORT(msgid));
  17357. +
  17358. + for (i = 0, pos = 0; i < (unsigned int)count;
  17359. + pos += elements[i++].size)
  17360. + if (elements[i].size) {
  17361. + if (vchiq_copy_from_user
  17362. + (header->data + pos, elements[i].data,
  17363. + (size_t) elements[i].size) !=
  17364. + VCHIQ_SUCCESS) {
  17365. + mutex_unlock(&state->sync_mutex);
  17366. + VCHIQ_SERVICE_STATS_INC(service,
  17367. + error_count);
  17368. + return VCHIQ_ERROR;
  17369. + }
  17370. + if (i == 0) {
  17371. + if (vchiq_sync_log_level >=
  17372. + VCHIQ_LOG_TRACE)
  17373. + vchiq_log_dump_mem("Sent Sync",
  17374. + 0, header->data + pos,
  17375. + min(64u,
  17376. + elements[0].size));
  17377. + }
  17378. + }
  17379. +
  17380. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  17381. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  17382. + } else {
  17383. + vchiq_log_info(vchiq_sync_log_level,
  17384. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  17385. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17386. + (unsigned int)header, size,
  17387. + VCHIQ_MSG_SRCPORT(msgid),
  17388. + VCHIQ_MSG_DSTPORT(msgid));
  17389. + if (size != 0) {
  17390. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  17391. + memcpy(header->data, elements[0].data,
  17392. + elements[0].size);
  17393. + }
  17394. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  17395. + }
  17396. +
  17397. + header->size = size;
  17398. + header->msgid = msgid;
  17399. +
  17400. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  17401. + int svc_fourcc;
  17402. +
  17403. + svc_fourcc = service
  17404. + ? service->base.fourcc
  17405. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  17406. +
  17407. + vchiq_log_trace(vchiq_sync_log_level,
  17408. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  17409. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  17410. + VCHIQ_MSG_TYPE(msgid),
  17411. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  17412. + VCHIQ_MSG_SRCPORT(msgid),
  17413. + VCHIQ_MSG_DSTPORT(msgid),
  17414. + size);
  17415. + }
  17416. +
  17417. + /* Make sure the new header is visible to the peer. */
  17418. + wmb();
  17419. +
  17420. + remote_event_signal(&state->remote->sync_trigger);
  17421. +
  17422. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  17423. + mutex_unlock(&state->sync_mutex);
  17424. +
  17425. + return VCHIQ_SUCCESS;
  17426. +}
  17427. +
  17428. +static inline void
  17429. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  17430. +{
  17431. + slot->use_count++;
  17432. +}
  17433. +
  17434. +static void
  17435. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  17436. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  17437. +{
  17438. + int release_count;
  17439. +
  17440. + mutex_lock(&state->recycle_mutex);
  17441. +
  17442. + if (header) {
  17443. + int msgid = header->msgid;
  17444. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  17445. + (service && service->closing)) {
  17446. + mutex_unlock(&state->recycle_mutex);
  17447. + return;
  17448. + }
  17449. +
  17450. + /* Rewrite the message header to prevent a double
  17451. + ** release */
  17452. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  17453. + }
  17454. +
  17455. + release_count = slot_info->release_count;
  17456. + slot_info->release_count = ++release_count;
  17457. +
  17458. + if (release_count == slot_info->use_count) {
  17459. + int slot_queue_recycle;
  17460. + /* Add to the freed queue */
  17461. +
  17462. + /* A read barrier is necessary here to prevent speculative
  17463. + ** fetches of remote->slot_queue_recycle from overtaking the
  17464. + ** mutex. */
  17465. + rmb();
  17466. +
  17467. + slot_queue_recycle = state->remote->slot_queue_recycle;
  17468. + state->remote->slot_queue[slot_queue_recycle &
  17469. + VCHIQ_SLOT_QUEUE_MASK] =
  17470. + SLOT_INDEX_FROM_INFO(state, slot_info);
  17471. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  17472. + vchiq_log_info(vchiq_core_log_level,
  17473. + "%d: release_slot %d - recycle->%x",
  17474. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  17475. + state->remote->slot_queue_recycle);
  17476. +
  17477. + /* A write barrier is necessary, but remote_event_signal
  17478. + ** contains one. */
  17479. + remote_event_signal(&state->remote->recycle);
  17480. + }
  17481. +
  17482. + mutex_unlock(&state->recycle_mutex);
  17483. +}
  17484. +
  17485. +/* Called by the slot handler - don't hold the bulk mutex */
  17486. +static VCHIQ_STATUS_T
  17487. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  17488. + int retry_poll)
  17489. +{
  17490. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  17491. +
  17492. + vchiq_log_trace(vchiq_core_log_level,
  17493. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  17494. + service->state->id, service->localport,
  17495. + (queue == &service->bulk_tx) ? 't' : 'r',
  17496. + queue->process, queue->remote_notify, queue->remove);
  17497. +
  17498. + if (service->state->is_master) {
  17499. + while (queue->remote_notify != queue->process) {
  17500. + VCHIQ_BULK_T *bulk =
  17501. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  17502. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  17503. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  17504. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  17505. + service->remoteport);
  17506. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  17507. + /* Only reply to non-dummy bulk requests */
  17508. + if (bulk->remote_data) {
  17509. + status = queue_message(service->state, NULL,
  17510. + msgid, &element, 1, 4, 0);
  17511. + if (status != VCHIQ_SUCCESS)
  17512. + break;
  17513. + }
  17514. + queue->remote_notify++;
  17515. + }
  17516. + } else {
  17517. + queue->remote_notify = queue->process;
  17518. + }
  17519. +
  17520. + if (status == VCHIQ_SUCCESS) {
  17521. + while (queue->remove != queue->remote_notify) {
  17522. + VCHIQ_BULK_T *bulk =
  17523. + &queue->bulks[BULK_INDEX(queue->remove)];
  17524. +
  17525. + /* Only generate callbacks for non-dummy bulk
  17526. + ** requests, and non-terminated services */
  17527. + if (bulk->data && service->instance) {
  17528. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  17529. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  17530. + VCHIQ_SERVICE_STATS_INC(service,
  17531. + bulk_tx_count);
  17532. + VCHIQ_SERVICE_STATS_ADD(service,
  17533. + bulk_tx_bytes,
  17534. + bulk->actual);
  17535. + } else {
  17536. + VCHIQ_SERVICE_STATS_INC(service,
  17537. + bulk_rx_count);
  17538. + VCHIQ_SERVICE_STATS_ADD(service,
  17539. + bulk_rx_bytes,
  17540. + bulk->actual);
  17541. + }
  17542. + } else {
  17543. + VCHIQ_SERVICE_STATS_INC(service,
  17544. + bulk_aborted_count);
  17545. + }
  17546. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  17547. + struct bulk_waiter *waiter;
  17548. + spin_lock(&bulk_waiter_spinlock);
  17549. + waiter = bulk->userdata;
  17550. + if (waiter) {
  17551. + waiter->actual = bulk->actual;
  17552. + up(&waiter->event);
  17553. + }
  17554. + spin_unlock(&bulk_waiter_spinlock);
  17555. + } else if (bulk->mode ==
  17556. + VCHIQ_BULK_MODE_CALLBACK) {
  17557. + VCHIQ_REASON_T reason = (bulk->dir ==
  17558. + VCHIQ_BULK_TRANSMIT) ?
  17559. + ((bulk->actual ==
  17560. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  17561. + VCHIQ_BULK_TRANSMIT_ABORTED :
  17562. + VCHIQ_BULK_TRANSMIT_DONE) :
  17563. + ((bulk->actual ==
  17564. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  17565. + VCHIQ_BULK_RECEIVE_ABORTED :
  17566. + VCHIQ_BULK_RECEIVE_DONE);
  17567. + status = make_service_callback(service,
  17568. + reason, NULL, bulk->userdata);
  17569. + if (status == VCHIQ_RETRY)
  17570. + break;
  17571. + }
  17572. + }
  17573. +
  17574. + queue->remove++;
  17575. + up(&service->bulk_remove_event);
  17576. + }
  17577. + if (!retry_poll)
  17578. + status = VCHIQ_SUCCESS;
  17579. + }
  17580. +
  17581. + if (status == VCHIQ_RETRY)
  17582. + request_poll(service->state, service,
  17583. + (queue == &service->bulk_tx) ?
  17584. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  17585. +
  17586. + return status;
  17587. +}
  17588. +
  17589. +/* Called by the slot handler thread */
  17590. +static void
  17591. +poll_services(VCHIQ_STATE_T *state)
  17592. +{
  17593. + int group, i;
  17594. +
  17595. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  17596. + uint32_t flags;
  17597. + flags = atomic_xchg(&state->poll_services[group], 0);
  17598. + for (i = 0; flags; i++) {
  17599. + if (flags & (1 << i)) {
  17600. + VCHIQ_SERVICE_T *service =
  17601. + find_service_by_port(state,
  17602. + (group<<5) + i);
  17603. + uint32_t service_flags;
  17604. + flags &= ~(1 << i);
  17605. + if (!service)
  17606. + continue;
  17607. + service_flags =
  17608. + atomic_xchg(&service->poll_flags, 0);
  17609. + if (service_flags &
  17610. + (1 << VCHIQ_POLL_REMOVE)) {
  17611. + vchiq_log_info(vchiq_core_log_level,
  17612. + "%d: ps - remove %d<->%d",
  17613. + state->id, service->localport,
  17614. + service->remoteport);
  17615. +
  17616. + /* Make it look like a client, because
  17617. + it must be removed and not left in
  17618. + the LISTENING state. */
  17619. + service->public_fourcc =
  17620. + VCHIQ_FOURCC_INVALID;
  17621. +
  17622. + if (vchiq_close_service_internal(
  17623. + service, 0/*!close_recvd*/) !=
  17624. + VCHIQ_SUCCESS)
  17625. + request_poll(state, service,
  17626. + VCHIQ_POLL_REMOVE);
  17627. + } else if (service_flags &
  17628. + (1 << VCHIQ_POLL_TERMINATE)) {
  17629. + vchiq_log_info(vchiq_core_log_level,
  17630. + "%d: ps - terminate %d<->%d",
  17631. + state->id, service->localport,
  17632. + service->remoteport);
  17633. + if (vchiq_close_service_internal(
  17634. + service, 0/*!close_recvd*/) !=
  17635. + VCHIQ_SUCCESS)
  17636. + request_poll(state, service,
  17637. + VCHIQ_POLL_TERMINATE);
  17638. + }
  17639. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  17640. + notify_bulks(service,
  17641. + &service->bulk_tx,
  17642. + 1/*retry_poll*/);
  17643. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  17644. + notify_bulks(service,
  17645. + &service->bulk_rx,
  17646. + 1/*retry_poll*/);
  17647. + unlock_service(service);
  17648. + }
  17649. + }
  17650. + }
  17651. +}
  17652. +
  17653. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  17654. +static int
  17655. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  17656. +{
  17657. + VCHIQ_STATE_T *state = service->state;
  17658. + int resolved = 0;
  17659. + int rc;
  17660. +
  17661. + while ((queue->process != queue->local_insert) &&
  17662. + (queue->process != queue->remote_insert)) {
  17663. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  17664. +
  17665. + vchiq_log_trace(vchiq_core_log_level,
  17666. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  17667. + state->id, service->localport,
  17668. + (queue == &service->bulk_tx) ? 't' : 'r',
  17669. + queue->local_insert, queue->remote_insert,
  17670. + queue->process);
  17671. +
  17672. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  17673. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  17674. +
  17675. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  17676. + if (rc != 0)
  17677. + break;
  17678. +
  17679. + vchiq_transfer_bulk(bulk);
  17680. + mutex_unlock(&state->bulk_transfer_mutex);
  17681. +
  17682. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  17683. + const char *header = (queue == &service->bulk_tx) ?
  17684. + "Send Bulk to" : "Recv Bulk from";
  17685. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  17686. + vchiq_log_info(vchiq_core_msg_log_level,
  17687. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  17688. + header,
  17689. + VCHIQ_FOURCC_AS_4CHARS(
  17690. + service->base.fourcc),
  17691. + service->remoteport,
  17692. + bulk->size,
  17693. + (unsigned int)bulk->data,
  17694. + (unsigned int)bulk->remote_data);
  17695. + else
  17696. + vchiq_log_info(vchiq_core_msg_log_level,
  17697. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  17698. + " rx len:%d %x<->%x",
  17699. + header,
  17700. + VCHIQ_FOURCC_AS_4CHARS(
  17701. + service->base.fourcc),
  17702. + service->remoteport,
  17703. + bulk->size,
  17704. + bulk->remote_size,
  17705. + (unsigned int)bulk->data,
  17706. + (unsigned int)bulk->remote_data);
  17707. + }
  17708. +
  17709. + vchiq_complete_bulk(bulk);
  17710. + queue->process++;
  17711. + resolved++;
  17712. + }
  17713. + return resolved;
  17714. +}
  17715. +
  17716. +/* Called with the bulk_mutex held */
  17717. +static void
  17718. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  17719. +{
  17720. + int is_tx = (queue == &service->bulk_tx);
  17721. + vchiq_log_trace(vchiq_core_log_level,
  17722. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  17723. + service->state->id, service->localport, is_tx ? 't' : 'r',
  17724. + queue->local_insert, queue->remote_insert, queue->process);
  17725. +
  17726. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  17727. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  17728. +
  17729. + while ((queue->process != queue->local_insert) ||
  17730. + (queue->process != queue->remote_insert)) {
  17731. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  17732. +
  17733. + if (queue->process == queue->remote_insert) {
  17734. + /* fabricate a matching dummy bulk */
  17735. + bulk->remote_data = NULL;
  17736. + bulk->remote_size = 0;
  17737. + queue->remote_insert++;
  17738. + }
  17739. +
  17740. + if (queue->process != queue->local_insert) {
  17741. + vchiq_complete_bulk(bulk);
  17742. +
  17743. + vchiq_log_info(vchiq_core_msg_log_level,
  17744. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  17745. + "rx len:%d",
  17746. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  17747. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  17748. + service->remoteport,
  17749. + bulk->size,
  17750. + bulk->remote_size);
  17751. + } else {
  17752. + /* fabricate a matching dummy bulk */
  17753. + bulk->data = NULL;
  17754. + bulk->size = 0;
  17755. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  17756. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  17757. + VCHIQ_BULK_RECEIVE;
  17758. + queue->local_insert++;
  17759. + }
  17760. +
  17761. + queue->process++;
  17762. + }
  17763. +}
  17764. +
  17765. +/* Called from the slot handler thread */
  17766. +static void
  17767. +pause_bulks(VCHIQ_STATE_T *state)
  17768. +{
  17769. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  17770. + WARN_ON_ONCE(1);
  17771. + atomic_set(&pause_bulks_count, 1);
  17772. + return;
  17773. + }
  17774. +
  17775. + /* Block bulk transfers from all services */
  17776. + mutex_lock(&state->bulk_transfer_mutex);
  17777. +}
  17778. +
  17779. +/* Called from the slot handler thread */
  17780. +static void
  17781. +resume_bulks(VCHIQ_STATE_T *state)
  17782. +{
  17783. + int i;
  17784. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  17785. + WARN_ON_ONCE(1);
  17786. + atomic_set(&pause_bulks_count, 0);
  17787. + return;
  17788. + }
  17789. +
  17790. + /* Allow bulk transfers from all services */
  17791. + mutex_unlock(&state->bulk_transfer_mutex);
  17792. +
  17793. + if (state->deferred_bulks == 0)
  17794. + return;
  17795. +
  17796. + /* Deal with any bulks which had to be deferred due to being in
  17797. + * paused state. Don't try to match up to number of deferred bulks
  17798. + * in case we've had something come and close the service in the
  17799. + * interim - just process all bulk queues for all services */
  17800. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  17801. + __func__, state->deferred_bulks);
  17802. +
  17803. + for (i = 0; i < state->unused_service; i++) {
  17804. + VCHIQ_SERVICE_T *service = state->services[i];
  17805. + int resolved_rx = 0;
  17806. + int resolved_tx = 0;
  17807. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  17808. + continue;
  17809. +
  17810. + mutex_lock(&service->bulk_mutex);
  17811. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  17812. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  17813. + mutex_unlock(&service->bulk_mutex);
  17814. + if (resolved_rx)
  17815. + notify_bulks(service, &service->bulk_rx, 1);
  17816. + if (resolved_tx)
  17817. + notify_bulks(service, &service->bulk_tx, 1);
  17818. + }
  17819. + state->deferred_bulks = 0;
  17820. +}
  17821. +
  17822. +static int
  17823. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  17824. +{
  17825. + VCHIQ_SERVICE_T *service = NULL;
  17826. + int msgid, size;
  17827. + int type;
  17828. + unsigned int localport, remoteport;
  17829. +
  17830. + msgid = header->msgid;
  17831. + size = header->size;
  17832. + type = VCHIQ_MSG_TYPE(msgid);
  17833. + localport = VCHIQ_MSG_DSTPORT(msgid);
  17834. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  17835. + if (size >= sizeof(struct vchiq_open_payload)) {
  17836. + const struct vchiq_open_payload *payload =
  17837. + (struct vchiq_open_payload *)header->data;
  17838. + unsigned int fourcc;
  17839. +
  17840. + fourcc = payload->fourcc;
  17841. + vchiq_log_info(vchiq_core_log_level,
  17842. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  17843. + state->id, (unsigned int)header,
  17844. + localport,
  17845. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  17846. +
  17847. + service = get_listening_service(state, fourcc);
  17848. +
  17849. + if (service) {
  17850. + /* A matching service exists */
  17851. + short version = payload->version;
  17852. + short version_min = payload->version_min;
  17853. + if ((service->version < version_min) ||
  17854. + (version < service->version_min)) {
  17855. + /* Version mismatch */
  17856. + vchiq_loud_error_header();
  17857. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  17858. + "version mismatch - local (%d, min %d)"
  17859. + " vs. remote (%d, min %d)",
  17860. + state->id, service->localport,
  17861. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  17862. + service->version, service->version_min,
  17863. + version, version_min);
  17864. + vchiq_loud_error_footer();
  17865. + unlock_service(service);
  17866. + service = NULL;
  17867. + goto fail_open;
  17868. + }
  17869. + service->peer_version = version;
  17870. +
  17871. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  17872. + struct vchiq_openack_payload ack_payload = {
  17873. + service->version
  17874. + };
  17875. + VCHIQ_ELEMENT_T body = {
  17876. + &ack_payload,
  17877. + sizeof(ack_payload)
  17878. + };
  17879. +
  17880. + /* Acknowledge the OPEN */
  17881. + if (service->sync) {
  17882. + if (queue_message_sync(state, NULL,
  17883. + VCHIQ_MAKE_MSG(
  17884. + VCHIQ_MSG_OPENACK,
  17885. + service->localport,
  17886. + remoteport),
  17887. + &body, 1, sizeof(ack_payload),
  17888. + 0) == VCHIQ_RETRY)
  17889. + goto bail_not_ready;
  17890. + } else {
  17891. + if (queue_message(state, NULL,
  17892. + VCHIQ_MAKE_MSG(
  17893. + VCHIQ_MSG_OPENACK,
  17894. + service->localport,
  17895. + remoteport),
  17896. + &body, 1, sizeof(ack_payload),
  17897. + 0) == VCHIQ_RETRY)
  17898. + goto bail_not_ready;
  17899. + }
  17900. +
  17901. + /* The service is now open */
  17902. + vchiq_set_service_state(service,
  17903. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  17904. + : VCHIQ_SRVSTATE_OPEN);
  17905. + }
  17906. +
  17907. + service->remoteport = remoteport;
  17908. + service->client_id = ((int *)header->data)[1];
  17909. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  17910. + NULL, NULL) == VCHIQ_RETRY) {
  17911. + /* Bail out if not ready */
  17912. + service->remoteport = VCHIQ_PORT_FREE;
  17913. + goto bail_not_ready;
  17914. + }
  17915. +
  17916. + /* Success - the message has been dealt with */
  17917. + unlock_service(service);
  17918. + return 1;
  17919. + }
  17920. + }
  17921. +
  17922. +fail_open:
  17923. + /* No available service, or an invalid request - send a CLOSE */
  17924. + if (queue_message(state, NULL,
  17925. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  17926. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  17927. + goto bail_not_ready;
  17928. +
  17929. + return 1;
  17930. +
  17931. +bail_not_ready:
  17932. + if (service)
  17933. + unlock_service(service);
  17934. +
  17935. + return 0;
  17936. +}
  17937. +
  17938. +/* Called by the slot handler thread */
  17939. +static void
  17940. +parse_rx_slots(VCHIQ_STATE_T *state)
  17941. +{
  17942. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  17943. + VCHIQ_SERVICE_T *service = NULL;
  17944. + int tx_pos;
  17945. + DEBUG_INITIALISE(state->local)
  17946. +
  17947. + tx_pos = remote->tx_pos;
  17948. +
  17949. + while (state->rx_pos != tx_pos) {
  17950. + VCHIQ_HEADER_T *header;
  17951. + int msgid, size;
  17952. + int type;
  17953. + unsigned int localport, remoteport;
  17954. +
  17955. + DEBUG_TRACE(PARSE_LINE);
  17956. + if (!state->rx_data) {
  17957. + int rx_index;
  17958. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  17959. + rx_index = remote->slot_queue[
  17960. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  17961. + VCHIQ_SLOT_QUEUE_MASK];
  17962. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  17963. + rx_index);
  17964. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  17965. +
  17966. + /* Initialise use_count to one, and increment
  17967. + ** release_count at the end of the slot to avoid
  17968. + ** releasing the slot prematurely. */
  17969. + state->rx_info->use_count = 1;
  17970. + state->rx_info->release_count = 0;
  17971. + }
  17972. +
  17973. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  17974. + (state->rx_pos & VCHIQ_SLOT_MASK));
  17975. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  17976. + msgid = header->msgid;
  17977. + DEBUG_VALUE(PARSE_MSGID, msgid);
  17978. + size = header->size;
  17979. + type = VCHIQ_MSG_TYPE(msgid);
  17980. + localport = VCHIQ_MSG_DSTPORT(msgid);
  17981. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  17982. +
  17983. + if (type != VCHIQ_MSG_DATA)
  17984. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  17985. +
  17986. + switch (type) {
  17987. + case VCHIQ_MSG_OPENACK:
  17988. + case VCHIQ_MSG_CLOSE:
  17989. + case VCHIQ_MSG_DATA:
  17990. + case VCHIQ_MSG_BULK_RX:
  17991. + case VCHIQ_MSG_BULK_TX:
  17992. + case VCHIQ_MSG_BULK_RX_DONE:
  17993. + case VCHIQ_MSG_BULK_TX_DONE:
  17994. + service = find_service_by_port(state, localport);
  17995. + if ((!service || service->remoteport != remoteport) &&
  17996. + (localport == 0) &&
  17997. + (type == VCHIQ_MSG_CLOSE)) {
  17998. + /* This could be a CLOSE from a client which
  17999. + hadn't yet received the OPENACK - look for
  18000. + the connected service */
  18001. + if (service)
  18002. + unlock_service(service);
  18003. + service = get_connected_service(state,
  18004. + remoteport);
  18005. + if (service)
  18006. + vchiq_log_warning(vchiq_core_log_level,
  18007. + "%d: prs %s@%x (%d->%d) - "
  18008. + "found connected service %d",
  18009. + state->id, msg_type_str(type),
  18010. + (unsigned int)header,
  18011. + remoteport, localport,
  18012. + service->localport);
  18013. + }
  18014. +
  18015. + if (!service) {
  18016. + vchiq_log_error(vchiq_core_log_level,
  18017. + "%d: prs %s@%x (%d->%d) - "
  18018. + "invalid/closed service %d",
  18019. + state->id, msg_type_str(type),
  18020. + (unsigned int)header,
  18021. + remoteport, localport, localport);
  18022. + goto skip_message;
  18023. + }
  18024. + break;
  18025. + default:
  18026. + break;
  18027. + }
  18028. +
  18029. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  18030. + int svc_fourcc;
  18031. +
  18032. + svc_fourcc = service
  18033. + ? service->base.fourcc
  18034. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  18035. + vchiq_log_info(vchiq_core_msg_log_level,
  18036. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  18037. + "len:%d",
  18038. + msg_type_str(type), type,
  18039. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  18040. + remoteport, localport, size);
  18041. + if (size > 0)
  18042. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  18043. + min(64, size));
  18044. + }
  18045. +
  18046. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  18047. + > VCHIQ_SLOT_SIZE) {
  18048. + vchiq_log_error(vchiq_core_log_level,
  18049. + "header %x (msgid %x) - size %x too big for "
  18050. + "slot",
  18051. + (unsigned int)header, (unsigned int)msgid,
  18052. + (unsigned int)size);
  18053. + WARN(1, "oversized for slot\n");
  18054. + }
  18055. +
  18056. + switch (type) {
  18057. + case VCHIQ_MSG_OPEN:
  18058. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  18059. + if (!parse_open(state, header))
  18060. + goto bail_not_ready;
  18061. + break;
  18062. + case VCHIQ_MSG_OPENACK:
  18063. + if (size >= sizeof(struct vchiq_openack_payload)) {
  18064. + const struct vchiq_openack_payload *payload =
  18065. + (struct vchiq_openack_payload *)
  18066. + header->data;
  18067. + service->peer_version = payload->version;
  18068. + }
  18069. + vchiq_log_info(vchiq_core_log_level,
  18070. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  18071. + state->id, (unsigned int)header, size,
  18072. + remoteport, localport, service->peer_version);
  18073. + if (service->srvstate ==
  18074. + VCHIQ_SRVSTATE_OPENING) {
  18075. + service->remoteport = remoteport;
  18076. + vchiq_set_service_state(service,
  18077. + VCHIQ_SRVSTATE_OPEN);
  18078. + up(&service->remove_event);
  18079. + } else
  18080. + vchiq_log_error(vchiq_core_log_level,
  18081. + "OPENACK received in state %s",
  18082. + srvstate_names[service->srvstate]);
  18083. + break;
  18084. + case VCHIQ_MSG_CLOSE:
  18085. + WARN_ON(size != 0); /* There should be no data */
  18086. +
  18087. + vchiq_log_info(vchiq_core_log_level,
  18088. + "%d: prs CLOSE@%x (%d->%d)",
  18089. + state->id, (unsigned int)header,
  18090. + remoteport, localport);
  18091. +
  18092. + mark_service_closing_internal(service, 1);
  18093. +
  18094. + if (vchiq_close_service_internal(service,
  18095. + 1/*close_recvd*/) == VCHIQ_RETRY)
  18096. + goto bail_not_ready;
  18097. +
  18098. + vchiq_log_info(vchiq_core_log_level,
  18099. + "Close Service %c%c%c%c s:%u d:%d",
  18100. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  18101. + service->localport,
  18102. + service->remoteport);
  18103. + break;
  18104. + case VCHIQ_MSG_DATA:
  18105. + vchiq_log_trace(vchiq_core_log_level,
  18106. + "%d: prs DATA@%x,%x (%d->%d)",
  18107. + state->id, (unsigned int)header, size,
  18108. + remoteport, localport);
  18109. +
  18110. + if ((service->remoteport == remoteport)
  18111. + && (service->srvstate ==
  18112. + VCHIQ_SRVSTATE_OPEN)) {
  18113. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  18114. + claim_slot(state->rx_info);
  18115. + DEBUG_TRACE(PARSE_LINE);
  18116. + if (make_service_callback(service,
  18117. + VCHIQ_MESSAGE_AVAILABLE, header,
  18118. + NULL) == VCHIQ_RETRY) {
  18119. + DEBUG_TRACE(PARSE_LINE);
  18120. + goto bail_not_ready;
  18121. + }
  18122. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  18123. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  18124. + size);
  18125. + } else {
  18126. + VCHIQ_STATS_INC(state, error_count);
  18127. + }
  18128. + break;
  18129. + case VCHIQ_MSG_CONNECT:
  18130. + vchiq_log_info(vchiq_core_log_level,
  18131. + "%d: prs CONNECT@%x",
  18132. + state->id, (unsigned int)header);
  18133. + up(&state->connect);
  18134. + break;
  18135. + case VCHIQ_MSG_BULK_RX:
  18136. + case VCHIQ_MSG_BULK_TX: {
  18137. + VCHIQ_BULK_QUEUE_T *queue;
  18138. + WARN_ON(!state->is_master);
  18139. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  18140. + &service->bulk_tx : &service->bulk_rx;
  18141. + if ((service->remoteport == remoteport)
  18142. + && (service->srvstate ==
  18143. + VCHIQ_SRVSTATE_OPEN)) {
  18144. + VCHIQ_BULK_T *bulk;
  18145. + int resolved = 0;
  18146. +
  18147. + DEBUG_TRACE(PARSE_LINE);
  18148. + if (mutex_lock_interruptible(
  18149. + &service->bulk_mutex) != 0) {
  18150. + DEBUG_TRACE(PARSE_LINE);
  18151. + goto bail_not_ready;
  18152. + }
  18153. +
  18154. + WARN_ON(!(queue->remote_insert < queue->remove +
  18155. + VCHIQ_NUM_SERVICE_BULKS));
  18156. + bulk = &queue->bulks[
  18157. + BULK_INDEX(queue->remote_insert)];
  18158. + bulk->remote_data =
  18159. + (void *)((int *)header->data)[0];
  18160. + bulk->remote_size = ((int *)header->data)[1];
  18161. + wmb();
  18162. +
  18163. + vchiq_log_info(vchiq_core_log_level,
  18164. + "%d: prs %s@%x (%d->%d) %x@%x",
  18165. + state->id, msg_type_str(type),
  18166. + (unsigned int)header,
  18167. + remoteport, localport,
  18168. + bulk->remote_size,
  18169. + (unsigned int)bulk->remote_data);
  18170. +
  18171. + queue->remote_insert++;
  18172. +
  18173. + if (atomic_read(&pause_bulks_count)) {
  18174. + state->deferred_bulks++;
  18175. + vchiq_log_info(vchiq_core_log_level,
  18176. + "%s: deferring bulk (%d)",
  18177. + __func__,
  18178. + state->deferred_bulks);
  18179. + if (state->conn_state !=
  18180. + VCHIQ_CONNSTATE_PAUSE_SENT)
  18181. + vchiq_log_error(
  18182. + vchiq_core_log_level,
  18183. + "%s: bulks paused in "
  18184. + "unexpected state %s",
  18185. + __func__,
  18186. + conn_state_names[
  18187. + state->conn_state]);
  18188. + } else if (state->conn_state ==
  18189. + VCHIQ_CONNSTATE_CONNECTED) {
  18190. + DEBUG_TRACE(PARSE_LINE);
  18191. + resolved = resolve_bulks(service,
  18192. + queue);
  18193. + }
  18194. +
  18195. + mutex_unlock(&service->bulk_mutex);
  18196. + if (resolved)
  18197. + notify_bulks(service, queue,
  18198. + 1/*retry_poll*/);
  18199. + }
  18200. + } break;
  18201. + case VCHIQ_MSG_BULK_RX_DONE:
  18202. + case VCHIQ_MSG_BULK_TX_DONE:
  18203. + WARN_ON(state->is_master);
  18204. + if ((service->remoteport == remoteport)
  18205. + && (service->srvstate !=
  18206. + VCHIQ_SRVSTATE_FREE)) {
  18207. + VCHIQ_BULK_QUEUE_T *queue;
  18208. + VCHIQ_BULK_T *bulk;
  18209. +
  18210. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  18211. + &service->bulk_rx : &service->bulk_tx;
  18212. +
  18213. + DEBUG_TRACE(PARSE_LINE);
  18214. + if (mutex_lock_interruptible(
  18215. + &service->bulk_mutex) != 0) {
  18216. + DEBUG_TRACE(PARSE_LINE);
  18217. + goto bail_not_ready;
  18218. + }
  18219. + if ((int)(queue->remote_insert -
  18220. + queue->local_insert) >= 0) {
  18221. + vchiq_log_error(vchiq_core_log_level,
  18222. + "%d: prs %s@%x (%d->%d) "
  18223. + "unexpected (ri=%d,li=%d)",
  18224. + state->id, msg_type_str(type),
  18225. + (unsigned int)header,
  18226. + remoteport, localport,
  18227. + queue->remote_insert,
  18228. + queue->local_insert);
  18229. + mutex_unlock(&service->bulk_mutex);
  18230. + break;
  18231. + }
  18232. +
  18233. + BUG_ON(queue->process == queue->local_insert);
  18234. + BUG_ON(queue->process != queue->remote_insert);
  18235. +
  18236. + bulk = &queue->bulks[
  18237. + BULK_INDEX(queue->remote_insert)];
  18238. + bulk->actual = *(int *)header->data;
  18239. + queue->remote_insert++;
  18240. +
  18241. + vchiq_log_info(vchiq_core_log_level,
  18242. + "%d: prs %s@%x (%d->%d) %x@%x",
  18243. + state->id, msg_type_str(type),
  18244. + (unsigned int)header,
  18245. + remoteport, localport,
  18246. + bulk->actual, (unsigned int)bulk->data);
  18247. +
  18248. + vchiq_log_trace(vchiq_core_log_level,
  18249. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  18250. + state->id, localport,
  18251. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  18252. + 'r' : 't',
  18253. + queue->local_insert,
  18254. + queue->remote_insert, queue->process);
  18255. +
  18256. + DEBUG_TRACE(PARSE_LINE);
  18257. + WARN_ON(queue->process == queue->local_insert);
  18258. + vchiq_complete_bulk(bulk);
  18259. + queue->process++;
  18260. + mutex_unlock(&service->bulk_mutex);
  18261. + DEBUG_TRACE(PARSE_LINE);
  18262. + notify_bulks(service, queue, 1/*retry_poll*/);
  18263. + DEBUG_TRACE(PARSE_LINE);
  18264. + }
  18265. + break;
  18266. + case VCHIQ_MSG_PADDING:
  18267. + vchiq_log_trace(vchiq_core_log_level,
  18268. + "%d: prs PADDING@%x,%x",
  18269. + state->id, (unsigned int)header, size);
  18270. + break;
  18271. + case VCHIQ_MSG_PAUSE:
  18272. + /* If initiated, signal the application thread */
  18273. + vchiq_log_trace(vchiq_core_log_level,
  18274. + "%d: prs PAUSE@%x,%x",
  18275. + state->id, (unsigned int)header, size);
  18276. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  18277. + vchiq_log_error(vchiq_core_log_level,
  18278. + "%d: PAUSE received in state PAUSED",
  18279. + state->id);
  18280. + break;
  18281. + }
  18282. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  18283. + /* Send a PAUSE in response */
  18284. + if (queue_message(state, NULL,
  18285. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  18286. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  18287. + goto bail_not_ready;
  18288. + if (state->is_master)
  18289. + pause_bulks(state);
  18290. + }
  18291. + /* At this point slot_mutex is held */
  18292. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  18293. + vchiq_platform_paused(state);
  18294. + break;
  18295. + case VCHIQ_MSG_RESUME:
  18296. + vchiq_log_trace(vchiq_core_log_level,
  18297. + "%d: prs RESUME@%x,%x",
  18298. + state->id, (unsigned int)header, size);
  18299. + /* Release the slot mutex */
  18300. + mutex_unlock(&state->slot_mutex);
  18301. + if (state->is_master)
  18302. + resume_bulks(state);
  18303. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  18304. + vchiq_platform_resumed(state);
  18305. + break;
  18306. +
  18307. + case VCHIQ_MSG_REMOTE_USE:
  18308. + vchiq_on_remote_use(state);
  18309. + break;
  18310. + case VCHIQ_MSG_REMOTE_RELEASE:
  18311. + vchiq_on_remote_release(state);
  18312. + break;
  18313. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  18314. + vchiq_on_remote_use_active(state);
  18315. + break;
  18316. +
  18317. + default:
  18318. + vchiq_log_error(vchiq_core_log_level,
  18319. + "%d: prs invalid msgid %x@%x,%x",
  18320. + state->id, msgid, (unsigned int)header, size);
  18321. + WARN(1, "invalid message\n");
  18322. + break;
  18323. + }
  18324. +
  18325. +skip_message:
  18326. + if (service) {
  18327. + unlock_service(service);
  18328. + service = NULL;
  18329. + }
  18330. +
  18331. + state->rx_pos += calc_stride(size);
  18332. +
  18333. + DEBUG_TRACE(PARSE_LINE);
  18334. + /* Perform some housekeeping when the end of the slot is
  18335. + ** reached. */
  18336. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  18337. + /* Remove the extra reference count. */
  18338. + release_slot(state, state->rx_info, NULL, NULL);
  18339. + state->rx_data = NULL;
  18340. + }
  18341. + }
  18342. +
  18343. +bail_not_ready:
  18344. + if (service)
  18345. + unlock_service(service);
  18346. +}
  18347. +
  18348. +/* Called by the slot handler thread */
  18349. +static int
  18350. +slot_handler_func(void *v)
  18351. +{
  18352. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  18353. + VCHIQ_SHARED_STATE_T *local = state->local;
  18354. + DEBUG_INITIALISE(local)
  18355. +
  18356. + while (1) {
  18357. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  18358. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  18359. + remote_event_wait(&local->trigger);
  18360. +
  18361. + rmb();
  18362. +
  18363. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  18364. + if (state->poll_needed) {
  18365. + /* Check if we need to suspend - may change our
  18366. + * conn_state */
  18367. + vchiq_platform_check_suspend(state);
  18368. +
  18369. + state->poll_needed = 0;
  18370. +
  18371. + /* Handle service polling and other rare conditions here
  18372. + ** out of the mainline code */
  18373. + switch (state->conn_state) {
  18374. + case VCHIQ_CONNSTATE_CONNECTED:
  18375. + /* Poll the services as requested */
  18376. + poll_services(state);
  18377. + break;
  18378. +
  18379. + case VCHIQ_CONNSTATE_PAUSING:
  18380. + if (state->is_master)
  18381. + pause_bulks(state);
  18382. + if (queue_message(state, NULL,
  18383. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  18384. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  18385. + vchiq_set_conn_state(state,
  18386. + VCHIQ_CONNSTATE_PAUSE_SENT);
  18387. + } else {
  18388. + if (state->is_master)
  18389. + resume_bulks(state);
  18390. + /* Retry later */
  18391. + state->poll_needed = 1;
  18392. + }
  18393. + break;
  18394. +
  18395. + case VCHIQ_CONNSTATE_PAUSED:
  18396. + vchiq_platform_resume(state);
  18397. + break;
  18398. +
  18399. + case VCHIQ_CONNSTATE_RESUMING:
  18400. + if (queue_message(state, NULL,
  18401. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  18402. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  18403. + if (state->is_master)
  18404. + resume_bulks(state);
  18405. + vchiq_set_conn_state(state,
  18406. + VCHIQ_CONNSTATE_CONNECTED);
  18407. + vchiq_platform_resumed(state);
  18408. + } else {
  18409. + /* This should really be impossible,
  18410. + ** since the PAUSE should have flushed
  18411. + ** through outstanding messages. */
  18412. + vchiq_log_error(vchiq_core_log_level,
  18413. + "Failed to send RESUME "
  18414. + "message");
  18415. + BUG();
  18416. + }
  18417. + break;
  18418. +
  18419. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  18420. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  18421. + vchiq_platform_handle_timeout(state);
  18422. + break;
  18423. + default:
  18424. + break;
  18425. + }
  18426. +
  18427. +
  18428. + }
  18429. +
  18430. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  18431. + parse_rx_slots(state);
  18432. + }
  18433. + return 0;
  18434. +}
  18435. +
  18436. +
  18437. +/* Called by the recycle thread */
  18438. +static int
  18439. +recycle_func(void *v)
  18440. +{
  18441. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  18442. + VCHIQ_SHARED_STATE_T *local = state->local;
  18443. +
  18444. + while (1) {
  18445. + remote_event_wait(&local->recycle);
  18446. +
  18447. + process_free_queue(state);
  18448. + }
  18449. + return 0;
  18450. +}
  18451. +
  18452. +
  18453. +/* Called by the sync thread */
  18454. +static int
  18455. +sync_func(void *v)
  18456. +{
  18457. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  18458. + VCHIQ_SHARED_STATE_T *local = state->local;
  18459. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  18460. + state->remote->slot_sync);
  18461. +
  18462. + while (1) {
  18463. + VCHIQ_SERVICE_T *service;
  18464. + int msgid, size;
  18465. + int type;
  18466. + unsigned int localport, remoteport;
  18467. +
  18468. + remote_event_wait(&local->sync_trigger);
  18469. +
  18470. + rmb();
  18471. +
  18472. + msgid = header->msgid;
  18473. + size = header->size;
  18474. + type = VCHIQ_MSG_TYPE(msgid);
  18475. + localport = VCHIQ_MSG_DSTPORT(msgid);
  18476. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  18477. +
  18478. + service = find_service_by_port(state, localport);
  18479. +
  18480. + if (!service) {
  18481. + vchiq_log_error(vchiq_sync_log_level,
  18482. + "%d: sf %s@%x (%d->%d) - "
  18483. + "invalid/closed service %d",
  18484. + state->id, msg_type_str(type),
  18485. + (unsigned int)header,
  18486. + remoteport, localport, localport);
  18487. + release_message_sync(state, header);
  18488. + continue;
  18489. + }
  18490. +
  18491. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  18492. + int svc_fourcc;
  18493. +
  18494. + svc_fourcc = service
  18495. + ? service->base.fourcc
  18496. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  18497. + vchiq_log_trace(vchiq_sync_log_level,
  18498. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  18499. + msg_type_str(type),
  18500. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  18501. + remoteport, localport, size);
  18502. + if (size > 0)
  18503. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  18504. + min(64, size));
  18505. + }
  18506. +
  18507. + switch (type) {
  18508. + case VCHIQ_MSG_OPENACK:
  18509. + if (size >= sizeof(struct vchiq_openack_payload)) {
  18510. + const struct vchiq_openack_payload *payload =
  18511. + (struct vchiq_openack_payload *)
  18512. + header->data;
  18513. + service->peer_version = payload->version;
  18514. + }
  18515. + vchiq_log_info(vchiq_sync_log_level,
  18516. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  18517. + state->id, (unsigned int)header, size,
  18518. + remoteport, localport, service->peer_version);
  18519. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  18520. + service->remoteport = remoteport;
  18521. + vchiq_set_service_state(service,
  18522. + VCHIQ_SRVSTATE_OPENSYNC);
  18523. + up(&service->remove_event);
  18524. + }
  18525. + release_message_sync(state, header);
  18526. + break;
  18527. +
  18528. + case VCHIQ_MSG_DATA:
  18529. + vchiq_log_trace(vchiq_sync_log_level,
  18530. + "%d: sf DATA@%x,%x (%d->%d)",
  18531. + state->id, (unsigned int)header, size,
  18532. + remoteport, localport);
  18533. +
  18534. + if ((service->remoteport == remoteport) &&
  18535. + (service->srvstate ==
  18536. + VCHIQ_SRVSTATE_OPENSYNC)) {
  18537. + if (make_service_callback(service,
  18538. + VCHIQ_MESSAGE_AVAILABLE, header,
  18539. + NULL) == VCHIQ_RETRY)
  18540. + vchiq_log_error(vchiq_sync_log_level,
  18541. + "synchronous callback to "
  18542. + "service %d returns "
  18543. + "VCHIQ_RETRY",
  18544. + localport);
  18545. + }
  18546. + break;
  18547. +
  18548. + default:
  18549. + vchiq_log_error(vchiq_sync_log_level,
  18550. + "%d: sf unexpected msgid %x@%x,%x",
  18551. + state->id, msgid, (unsigned int)header, size);
  18552. + release_message_sync(state, header);
  18553. + break;
  18554. + }
  18555. +
  18556. + unlock_service(service);
  18557. + }
  18558. +
  18559. + return 0;
  18560. +}
  18561. +
  18562. +
  18563. +static void
  18564. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  18565. +{
  18566. + queue->local_insert = 0;
  18567. + queue->remote_insert = 0;
  18568. + queue->process = 0;
  18569. + queue->remote_notify = 0;
  18570. + queue->remove = 0;
  18571. +}
  18572. +
  18573. +
  18574. +inline const char *
  18575. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  18576. +{
  18577. + return conn_state_names[conn_state];
  18578. +}
  18579. +
  18580. +
  18581. +VCHIQ_SLOT_ZERO_T *
  18582. +vchiq_init_slots(void *mem_base, int mem_size)
  18583. +{
  18584. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  18585. + VCHIQ_SLOT_ZERO_T *slot_zero =
  18586. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  18587. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  18588. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  18589. +
  18590. + /* Ensure there is enough memory to run an absolutely minimum system */
  18591. + num_slots -= first_data_slot;
  18592. +
  18593. + if (num_slots < 4) {
  18594. + vchiq_log_error(vchiq_core_log_level,
  18595. + "vchiq_init_slots - insufficient memory %x bytes",
  18596. + mem_size);
  18597. + return NULL;
  18598. + }
  18599. +
  18600. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  18601. +
  18602. + slot_zero->magic = VCHIQ_MAGIC;
  18603. + slot_zero->version = VCHIQ_VERSION;
  18604. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  18605. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  18606. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  18607. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  18608. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  18609. +
  18610. + slot_zero->master.slot_sync = first_data_slot;
  18611. + slot_zero->master.slot_first = first_data_slot + 1;
  18612. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  18613. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  18614. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  18615. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  18616. +
  18617. + return slot_zero;
  18618. +}
  18619. +
  18620. +VCHIQ_STATUS_T
  18621. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  18622. + int is_master)
  18623. +{
  18624. + VCHIQ_SHARED_STATE_T *local;
  18625. + VCHIQ_SHARED_STATE_T *remote;
  18626. + VCHIQ_STATUS_T status;
  18627. + char threadname[10];
  18628. + static int id;
  18629. + int i;
  18630. +
  18631. + vchiq_log_warning(vchiq_core_log_level,
  18632. + "%s: slot_zero = 0x%08lx, is_master = %d",
  18633. + __func__, (unsigned long)slot_zero, is_master);
  18634. +
  18635. + /* Check the input configuration */
  18636. +
  18637. + if (slot_zero->magic != VCHIQ_MAGIC) {
  18638. + vchiq_loud_error_header();
  18639. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  18640. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  18641. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  18642. + vchiq_loud_error_footer();
  18643. + return VCHIQ_ERROR;
  18644. + }
  18645. +
  18646. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  18647. + vchiq_loud_error_header();
  18648. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  18649. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  18650. + "(minimum %d)",
  18651. + (unsigned int)slot_zero, slot_zero->version,
  18652. + VCHIQ_VERSION_MIN);
  18653. + vchiq_loud_error("Restart with a newer VideoCore image.");
  18654. + vchiq_loud_error_footer();
  18655. + return VCHIQ_ERROR;
  18656. + }
  18657. +
  18658. + if (VCHIQ_VERSION < slot_zero->version_min) {
  18659. + vchiq_loud_error_header();
  18660. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  18661. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  18662. + "minimum %d)",
  18663. + (unsigned int)slot_zero, VCHIQ_VERSION,
  18664. + slot_zero->version_min);
  18665. + vchiq_loud_error("Restart with a newer kernel.");
  18666. + vchiq_loud_error_footer();
  18667. + return VCHIQ_ERROR;
  18668. + }
  18669. +
  18670. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  18671. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  18672. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  18673. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  18674. + vchiq_loud_error_header();
  18675. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  18676. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  18677. + "(expected %x)",
  18678. + (unsigned int)slot_zero,
  18679. + slot_zero->slot_zero_size,
  18680. + sizeof(VCHIQ_SLOT_ZERO_T));
  18681. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  18682. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  18683. + "(expected %d",
  18684. + (unsigned int)slot_zero, slot_zero->slot_size,
  18685. + VCHIQ_SLOT_SIZE);
  18686. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  18687. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  18688. + "(expected %d)",
  18689. + (unsigned int)slot_zero, slot_zero->max_slots,
  18690. + VCHIQ_MAX_SLOTS);
  18691. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  18692. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  18693. + "(expected %d)",
  18694. + (unsigned int)slot_zero,
  18695. + slot_zero->max_slots_per_side,
  18696. + VCHIQ_MAX_SLOTS_PER_SIDE);
  18697. + vchiq_loud_error_footer();
  18698. + return VCHIQ_ERROR;
  18699. + }
  18700. +
  18701. + if (is_master) {
  18702. + local = &slot_zero->master;
  18703. + remote = &slot_zero->slave;
  18704. + } else {
  18705. + local = &slot_zero->slave;
  18706. + remote = &slot_zero->master;
  18707. + }
  18708. +
  18709. + if (local->initialised) {
  18710. + vchiq_loud_error_header();
  18711. + if (remote->initialised)
  18712. + vchiq_loud_error("local state has already been "
  18713. + "initialised");
  18714. + else
  18715. + vchiq_loud_error("master/slave mismatch - two %ss",
  18716. + is_master ? "master" : "slave");
  18717. + vchiq_loud_error_footer();
  18718. + return VCHIQ_ERROR;
  18719. + }
  18720. +
  18721. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  18722. +
  18723. + state->id = id++;
  18724. + state->is_master = is_master;
  18725. +
  18726. + /*
  18727. + initialize shared state pointers
  18728. + */
  18729. +
  18730. + state->local = local;
  18731. + state->remote = remote;
  18732. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  18733. +
  18734. + /*
  18735. + initialize events and mutexes
  18736. + */
  18737. +
  18738. + sema_init(&state->connect, 0);
  18739. + mutex_init(&state->mutex);
  18740. + sema_init(&state->trigger_event, 0);
  18741. + sema_init(&state->recycle_event, 0);
  18742. + sema_init(&state->sync_trigger_event, 0);
  18743. + sema_init(&state->sync_release_event, 0);
  18744. +
  18745. + mutex_init(&state->slot_mutex);
  18746. + mutex_init(&state->recycle_mutex);
  18747. + mutex_init(&state->sync_mutex);
  18748. + mutex_init(&state->bulk_transfer_mutex);
  18749. +
  18750. + sema_init(&state->slot_available_event, 0);
  18751. + sema_init(&state->slot_remove_event, 0);
  18752. + sema_init(&state->data_quota_event, 0);
  18753. +
  18754. + state->slot_queue_available = 0;
  18755. +
  18756. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  18757. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  18758. + &state->service_quotas[i];
  18759. + sema_init(&service_quota->quota_event, 0);
  18760. + }
  18761. +
  18762. + for (i = local->slot_first; i <= local->slot_last; i++) {
  18763. + local->slot_queue[state->slot_queue_available++] = i;
  18764. + up(&state->slot_available_event);
  18765. + }
  18766. +
  18767. + state->default_slot_quota = state->slot_queue_available/2;
  18768. + state->default_message_quota =
  18769. + min((unsigned short)(state->default_slot_quota * 256),
  18770. + (unsigned short)~0);
  18771. +
  18772. + state->previous_data_index = -1;
  18773. + state->data_use_count = 0;
  18774. + state->data_quota = state->slot_queue_available - 1;
  18775. +
  18776. + local->trigger.event = &state->trigger_event;
  18777. + remote_event_create(&local->trigger);
  18778. + local->tx_pos = 0;
  18779. +
  18780. + local->recycle.event = &state->recycle_event;
  18781. + remote_event_create(&local->recycle);
  18782. + local->slot_queue_recycle = state->slot_queue_available;
  18783. +
  18784. + local->sync_trigger.event = &state->sync_trigger_event;
  18785. + remote_event_create(&local->sync_trigger);
  18786. +
  18787. + local->sync_release.event = &state->sync_release_event;
  18788. + remote_event_create(&local->sync_release);
  18789. +
  18790. + /* At start-of-day, the slot is empty and available */
  18791. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  18792. + = VCHIQ_MSGID_PADDING;
  18793. + remote_event_signal_local(&local->sync_release);
  18794. +
  18795. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  18796. +
  18797. + status = vchiq_platform_init_state(state);
  18798. +
  18799. + /*
  18800. + bring up slot handler thread
  18801. + */
  18802. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  18803. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  18804. + (void *)state,
  18805. + threadname);
  18806. +
  18807. + if (state->slot_handler_thread == NULL) {
  18808. + vchiq_loud_error_header();
  18809. + vchiq_loud_error("couldn't create thread %s", threadname);
  18810. + vchiq_loud_error_footer();
  18811. + return VCHIQ_ERROR;
  18812. + }
  18813. + set_user_nice(state->slot_handler_thread, -19);
  18814. + wake_up_process(state->slot_handler_thread);
  18815. +
  18816. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  18817. + state->recycle_thread = kthread_create(&recycle_func,
  18818. + (void *)state,
  18819. + threadname);
  18820. + if (state->recycle_thread == NULL) {
  18821. + vchiq_loud_error_header();
  18822. + vchiq_loud_error("couldn't create thread %s", threadname);
  18823. + vchiq_loud_error_footer();
  18824. + return VCHIQ_ERROR;
  18825. + }
  18826. + set_user_nice(state->recycle_thread, -19);
  18827. + wake_up_process(state->recycle_thread);
  18828. +
  18829. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  18830. + state->sync_thread = kthread_create(&sync_func,
  18831. + (void *)state,
  18832. + threadname);
  18833. + if (state->sync_thread == NULL) {
  18834. + vchiq_loud_error_header();
  18835. + vchiq_loud_error("couldn't create thread %s", threadname);
  18836. + vchiq_loud_error_footer();
  18837. + return VCHIQ_ERROR;
  18838. + }
  18839. + set_user_nice(state->sync_thread, -20);
  18840. + wake_up_process(state->sync_thread);
  18841. +
  18842. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  18843. + vchiq_states[state->id] = state;
  18844. +
  18845. + /* Indicate readiness to the other side */
  18846. + local->initialised = 1;
  18847. +
  18848. + return status;
  18849. +}
  18850. +
  18851. +/* Called from application thread when a client or server service is created. */
  18852. +VCHIQ_SERVICE_T *
  18853. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  18854. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  18855. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  18856. +{
  18857. + VCHIQ_SERVICE_T *service;
  18858. +
  18859. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  18860. + if (service) {
  18861. + service->base.fourcc = params->fourcc;
  18862. + service->base.callback = params->callback;
  18863. + service->base.userdata = params->userdata;
  18864. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  18865. + service->ref_count = 1;
  18866. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  18867. + service->userdata_term = userdata_term;
  18868. + service->localport = VCHIQ_PORT_FREE;
  18869. + service->remoteport = VCHIQ_PORT_FREE;
  18870. +
  18871. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  18872. + VCHIQ_FOURCC_INVALID : params->fourcc;
  18873. + service->client_id = 0;
  18874. + service->auto_close = 1;
  18875. + service->sync = 0;
  18876. + service->closing = 0;
  18877. + atomic_set(&service->poll_flags, 0);
  18878. + service->version = params->version;
  18879. + service->version_min = params->version_min;
  18880. + service->state = state;
  18881. + service->instance = instance;
  18882. + service->service_use_count = 0;
  18883. + init_bulk_queue(&service->bulk_tx);
  18884. + init_bulk_queue(&service->bulk_rx);
  18885. + sema_init(&service->remove_event, 0);
  18886. + sema_init(&service->bulk_remove_event, 0);
  18887. + mutex_init(&service->bulk_mutex);
  18888. + memset(&service->stats, 0, sizeof(service->stats));
  18889. + } else {
  18890. + vchiq_log_error(vchiq_core_log_level,
  18891. + "Out of memory");
  18892. + }
  18893. +
  18894. + if (service) {
  18895. + VCHIQ_SERVICE_T **pservice = NULL;
  18896. + int i;
  18897. +
  18898. + /* Although it is perfectly possible to use service_spinlock
  18899. + ** to protect the creation of services, it is overkill as it
  18900. + ** disables interrupts while the array is searched.
  18901. + ** The only danger is of another thread trying to create a
  18902. + ** service - service deletion is safe.
  18903. + ** Therefore it is preferable to use state->mutex which,
  18904. + ** although slower to claim, doesn't block interrupts while
  18905. + ** it is held.
  18906. + */
  18907. +
  18908. + mutex_lock(&state->mutex);
  18909. +
  18910. + /* Prepare to use a previously unused service */
  18911. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  18912. + pservice = &state->services[state->unused_service];
  18913. +
  18914. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  18915. + for (i = 0; i < state->unused_service; i++) {
  18916. + VCHIQ_SERVICE_T *srv = state->services[i];
  18917. + if (!srv) {
  18918. + pservice = &state->services[i];
  18919. + break;
  18920. + }
  18921. + }
  18922. + } else {
  18923. + for (i = (state->unused_service - 1); i >= 0; i--) {
  18924. + VCHIQ_SERVICE_T *srv = state->services[i];
  18925. + if (!srv)
  18926. + pservice = &state->services[i];
  18927. + else if ((srv->public_fourcc == params->fourcc)
  18928. + && ((srv->instance != instance) ||
  18929. + (srv->base.callback !=
  18930. + params->callback))) {
  18931. + /* There is another server using this
  18932. + ** fourcc which doesn't match. */
  18933. + pservice = NULL;
  18934. + break;
  18935. + }
  18936. + }
  18937. + }
  18938. +
  18939. + if (pservice) {
  18940. + service->localport = (pservice - state->services);
  18941. + if (!handle_seq)
  18942. + handle_seq = VCHIQ_MAX_STATES *
  18943. + VCHIQ_MAX_SERVICES;
  18944. + service->handle = handle_seq |
  18945. + (state->id * VCHIQ_MAX_SERVICES) |
  18946. + service->localport;
  18947. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  18948. + *pservice = service;
  18949. + if (pservice == &state->services[state->unused_service])
  18950. + state->unused_service++;
  18951. + }
  18952. +
  18953. + mutex_unlock(&state->mutex);
  18954. +
  18955. + if (!pservice) {
  18956. + kfree(service);
  18957. + service = NULL;
  18958. + }
  18959. + }
  18960. +
  18961. + if (service) {
  18962. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  18963. + &state->service_quotas[service->localport];
  18964. + service_quota->slot_quota = state->default_slot_quota;
  18965. + service_quota->message_quota = state->default_message_quota;
  18966. + if (service_quota->slot_use_count == 0)
  18967. + service_quota->previous_tx_index =
  18968. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  18969. + - 1;
  18970. +
  18971. + /* Bring this service online */
  18972. + vchiq_set_service_state(service, srvstate);
  18973. +
  18974. + vchiq_log_info(vchiq_core_msg_log_level,
  18975. + "%s Service %c%c%c%c SrcPort:%d",
  18976. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  18977. + ? "Open" : "Add",
  18978. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  18979. + service->localport);
  18980. + }
  18981. +
  18982. + /* Don't unlock the service - leave it with a ref_count of 1. */
  18983. +
  18984. + return service;
  18985. +}
  18986. +
  18987. +VCHIQ_STATUS_T
  18988. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  18989. +{
  18990. + struct vchiq_open_payload payload = {
  18991. + service->base.fourcc,
  18992. + client_id,
  18993. + service->version,
  18994. + service->version_min
  18995. + };
  18996. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  18997. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  18998. +
  18999. + service->client_id = client_id;
  19000. + vchiq_use_service_internal(service);
  19001. + status = queue_message(service->state, NULL,
  19002. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  19003. + &body, 1, sizeof(payload), 1);
  19004. + if (status == VCHIQ_SUCCESS) {
  19005. + if (down_interruptible(&service->remove_event) != 0) {
  19006. + status = VCHIQ_RETRY;
  19007. + vchiq_release_service_internal(service);
  19008. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  19009. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  19010. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  19011. + vchiq_log_error(vchiq_core_log_level,
  19012. + "%d: osi - srvstate = %s (ref %d)",
  19013. + service->state->id,
  19014. + srvstate_names[service->srvstate],
  19015. + service->ref_count);
  19016. + status = VCHIQ_ERROR;
  19017. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  19018. + vchiq_release_service_internal(service);
  19019. + }
  19020. + }
  19021. + return status;
  19022. +}
  19023. +
  19024. +static void
  19025. +release_service_messages(VCHIQ_SERVICE_T *service)
  19026. +{
  19027. + VCHIQ_STATE_T *state = service->state;
  19028. + int slot_last = state->remote->slot_last;
  19029. + int i;
  19030. +
  19031. + /* Release any claimed messages */
  19032. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  19033. + VCHIQ_SLOT_INFO_T *slot_info =
  19034. + SLOT_INFO_FROM_INDEX(state, i);
  19035. + if (slot_info->release_count != slot_info->use_count) {
  19036. + char *data =
  19037. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  19038. + unsigned int pos, end;
  19039. +
  19040. + end = VCHIQ_SLOT_SIZE;
  19041. + if (data == state->rx_data)
  19042. + /* This buffer is still being read from - stop
  19043. + ** at the current read position */
  19044. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  19045. +
  19046. + pos = 0;
  19047. +
  19048. + while (pos < end) {
  19049. + VCHIQ_HEADER_T *header =
  19050. + (VCHIQ_HEADER_T *)(data + pos);
  19051. + int msgid = header->msgid;
  19052. + int port = VCHIQ_MSG_DSTPORT(msgid);
  19053. + if ((port == service->localport) &&
  19054. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  19055. + vchiq_log_info(vchiq_core_log_level,
  19056. + " fsi - hdr %x",
  19057. + (unsigned int)header);
  19058. + release_slot(state, slot_info, header,
  19059. + NULL);
  19060. + }
  19061. + pos += calc_stride(header->size);
  19062. + if (pos > VCHIQ_SLOT_SIZE) {
  19063. + vchiq_log_error(vchiq_core_log_level,
  19064. + "fsi - pos %x: header %x, "
  19065. + "msgid %x, header->msgid %x, "
  19066. + "header->size %x",
  19067. + pos, (unsigned int)header,
  19068. + msgid, header->msgid,
  19069. + header->size);
  19070. + WARN(1, "invalid slot position\n");
  19071. + }
  19072. + }
  19073. + }
  19074. + }
  19075. +}
  19076. +
  19077. +static int
  19078. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  19079. +{
  19080. + VCHIQ_STATUS_T status;
  19081. +
  19082. + /* Abort any outstanding bulk transfers */
  19083. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  19084. + return 0;
  19085. + abort_outstanding_bulks(service, &service->bulk_tx);
  19086. + abort_outstanding_bulks(service, &service->bulk_rx);
  19087. + mutex_unlock(&service->bulk_mutex);
  19088. +
  19089. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  19090. + if (status == VCHIQ_SUCCESS)
  19091. + status = notify_bulks(service, &service->bulk_rx,
  19092. + 0/*!retry_poll*/);
  19093. + return (status == VCHIQ_SUCCESS);
  19094. +}
  19095. +
  19096. +static VCHIQ_STATUS_T
  19097. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  19098. +{
  19099. + VCHIQ_STATUS_T status;
  19100. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  19101. + int newstate;
  19102. +
  19103. + switch (service->srvstate) {
  19104. + case VCHIQ_SRVSTATE_OPEN:
  19105. + case VCHIQ_SRVSTATE_CLOSESENT:
  19106. + case VCHIQ_SRVSTATE_CLOSERECVD:
  19107. + if (is_server) {
  19108. + if (service->auto_close) {
  19109. + service->client_id = 0;
  19110. + service->remoteport = VCHIQ_PORT_FREE;
  19111. + newstate = VCHIQ_SRVSTATE_LISTENING;
  19112. + } else
  19113. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  19114. + } else
  19115. + newstate = VCHIQ_SRVSTATE_CLOSED;
  19116. + vchiq_set_service_state(service, newstate);
  19117. + break;
  19118. + case VCHIQ_SRVSTATE_LISTENING:
  19119. + break;
  19120. + default:
  19121. + vchiq_log_error(vchiq_core_log_level,
  19122. + "close_service_complete(%x) called in state %s",
  19123. + service->handle, srvstate_names[service->srvstate]);
  19124. + WARN(1, "close_service_complete in unexpected state\n");
  19125. + return VCHIQ_ERROR;
  19126. + }
  19127. +
  19128. + status = make_service_callback(service,
  19129. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  19130. +
  19131. + if (status != VCHIQ_RETRY) {
  19132. + int uc = service->service_use_count;
  19133. + int i;
  19134. + /* Complete the close process */
  19135. + for (i = 0; i < uc; i++)
  19136. + /* cater for cases where close is forced and the
  19137. + ** client may not close all it's handles */
  19138. + vchiq_release_service_internal(service);
  19139. +
  19140. + service->client_id = 0;
  19141. + service->remoteport = VCHIQ_PORT_FREE;
  19142. +
  19143. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  19144. + vchiq_free_service_internal(service);
  19145. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  19146. + if (is_server)
  19147. + service->closing = 0;
  19148. +
  19149. + up(&service->remove_event);
  19150. + }
  19151. + } else
  19152. + vchiq_set_service_state(service, failstate);
  19153. +
  19154. + return status;
  19155. +}
  19156. +
  19157. +/* Called by the slot handler */
  19158. +VCHIQ_STATUS_T
  19159. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  19160. +{
  19161. + VCHIQ_STATE_T *state = service->state;
  19162. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19163. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  19164. +
  19165. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  19166. + service->state->id, service->localport, close_recvd,
  19167. + srvstate_names[service->srvstate]);
  19168. +
  19169. + switch (service->srvstate) {
  19170. + case VCHIQ_SRVSTATE_CLOSED:
  19171. + case VCHIQ_SRVSTATE_HIDDEN:
  19172. + case VCHIQ_SRVSTATE_LISTENING:
  19173. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  19174. + if (close_recvd)
  19175. + vchiq_log_error(vchiq_core_log_level,
  19176. + "vchiq_close_service_internal(1) called "
  19177. + "in state %s",
  19178. + srvstate_names[service->srvstate]);
  19179. + else if (is_server) {
  19180. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  19181. + status = VCHIQ_ERROR;
  19182. + } else {
  19183. + service->client_id = 0;
  19184. + service->remoteport = VCHIQ_PORT_FREE;
  19185. + if (service->srvstate ==
  19186. + VCHIQ_SRVSTATE_CLOSEWAIT)
  19187. + vchiq_set_service_state(service,
  19188. + VCHIQ_SRVSTATE_LISTENING);
  19189. + }
  19190. + up(&service->remove_event);
  19191. + } else
  19192. + vchiq_free_service_internal(service);
  19193. + break;
  19194. + case VCHIQ_SRVSTATE_OPENING:
  19195. + if (close_recvd) {
  19196. + /* The open was rejected - tell the user */
  19197. + vchiq_set_service_state(service,
  19198. + VCHIQ_SRVSTATE_CLOSEWAIT);
  19199. + up(&service->remove_event);
  19200. + } else {
  19201. + /* Shutdown mid-open - let the other side know */
  19202. + status = queue_message(state, service,
  19203. + VCHIQ_MAKE_MSG
  19204. + (VCHIQ_MSG_CLOSE,
  19205. + service->localport,
  19206. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  19207. + NULL, 0, 0, 0);
  19208. + }
  19209. + break;
  19210. +
  19211. + case VCHIQ_SRVSTATE_OPENSYNC:
  19212. + mutex_lock(&state->sync_mutex);
  19213. + /* Drop through */
  19214. +
  19215. + case VCHIQ_SRVSTATE_OPEN:
  19216. + if (state->is_master || close_recvd) {
  19217. + if (!do_abort_bulks(service))
  19218. + status = VCHIQ_RETRY;
  19219. + }
  19220. +
  19221. + release_service_messages(service);
  19222. +
  19223. + if (status == VCHIQ_SUCCESS)
  19224. + status = queue_message(state, service,
  19225. + VCHIQ_MAKE_MSG
  19226. + (VCHIQ_MSG_CLOSE,
  19227. + service->localport,
  19228. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  19229. + NULL, 0, 0, 0);
  19230. +
  19231. + if (status == VCHIQ_SUCCESS) {
  19232. + if (!close_recvd)
  19233. + break;
  19234. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  19235. + mutex_unlock(&state->sync_mutex);
  19236. + break;
  19237. + } else
  19238. + break;
  19239. +
  19240. + status = close_service_complete(service,
  19241. + VCHIQ_SRVSTATE_CLOSERECVD);
  19242. + break;
  19243. +
  19244. + case VCHIQ_SRVSTATE_CLOSESENT:
  19245. + if (!close_recvd)
  19246. + /* This happens when a process is killed mid-close */
  19247. + break;
  19248. +
  19249. + if (!state->is_master) {
  19250. + if (!do_abort_bulks(service)) {
  19251. + status = VCHIQ_RETRY;
  19252. + break;
  19253. + }
  19254. + }
  19255. +
  19256. + if (status == VCHIQ_SUCCESS)
  19257. + status = close_service_complete(service,
  19258. + VCHIQ_SRVSTATE_CLOSERECVD);
  19259. + break;
  19260. +
  19261. + case VCHIQ_SRVSTATE_CLOSERECVD:
  19262. + if (!close_recvd && is_server)
  19263. + /* Force into LISTENING mode */
  19264. + vchiq_set_service_state(service,
  19265. + VCHIQ_SRVSTATE_LISTENING);
  19266. + status = close_service_complete(service,
  19267. + VCHIQ_SRVSTATE_CLOSERECVD);
  19268. + break;
  19269. +
  19270. + default:
  19271. + vchiq_log_error(vchiq_core_log_level,
  19272. + "vchiq_close_service_internal(%d) called in state %s",
  19273. + close_recvd, srvstate_names[service->srvstate]);
  19274. + break;
  19275. + }
  19276. +
  19277. + return status;
  19278. +}
  19279. +
  19280. +/* Called from the application process upon process death */
  19281. +void
  19282. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  19283. +{
  19284. + VCHIQ_STATE_T *state = service->state;
  19285. +
  19286. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  19287. + state->id, service->localport, service->remoteport);
  19288. +
  19289. + mark_service_closing(service);
  19290. +
  19291. + /* Mark the service for removal by the slot handler */
  19292. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  19293. +}
  19294. +
  19295. +/* Called from the slot handler */
  19296. +void
  19297. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  19298. +{
  19299. + VCHIQ_STATE_T *state = service->state;
  19300. +
  19301. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  19302. + state->id, service->localport);
  19303. +
  19304. + switch (service->srvstate) {
  19305. + case VCHIQ_SRVSTATE_OPENING:
  19306. + case VCHIQ_SRVSTATE_CLOSED:
  19307. + case VCHIQ_SRVSTATE_HIDDEN:
  19308. + case VCHIQ_SRVSTATE_LISTENING:
  19309. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  19310. + break;
  19311. + default:
  19312. + vchiq_log_error(vchiq_core_log_level,
  19313. + "%d: fsi - (%d) in state %s",
  19314. + state->id, service->localport,
  19315. + srvstate_names[service->srvstate]);
  19316. + return;
  19317. + }
  19318. +
  19319. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  19320. +
  19321. + up(&service->remove_event);
  19322. +
  19323. + /* Release the initial lock */
  19324. + unlock_service(service);
  19325. +}
  19326. +
  19327. +VCHIQ_STATUS_T
  19328. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  19329. +{
  19330. + VCHIQ_SERVICE_T *service;
  19331. + int i;
  19332. +
  19333. + /* Find all services registered to this client and enable them. */
  19334. + i = 0;
  19335. + while ((service = next_service_by_instance(state, instance,
  19336. + &i)) != NULL) {
  19337. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  19338. + vchiq_set_service_state(service,
  19339. + VCHIQ_SRVSTATE_LISTENING);
  19340. + unlock_service(service);
  19341. + }
  19342. +
  19343. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  19344. + if (queue_message(state, NULL,
  19345. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  19346. + 0, 1) == VCHIQ_RETRY)
  19347. + return VCHIQ_RETRY;
  19348. +
  19349. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  19350. + }
  19351. +
  19352. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  19353. + if (down_interruptible(&state->connect) != 0)
  19354. + return VCHIQ_RETRY;
  19355. +
  19356. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  19357. + up(&state->connect);
  19358. + }
  19359. +
  19360. + return VCHIQ_SUCCESS;
  19361. +}
  19362. +
  19363. +VCHIQ_STATUS_T
  19364. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  19365. +{
  19366. + VCHIQ_SERVICE_T *service;
  19367. + int i;
  19368. +
  19369. + /* Find all services registered to this client and enable them. */
  19370. + i = 0;
  19371. + while ((service = next_service_by_instance(state, instance,
  19372. + &i)) != NULL) {
  19373. + (void)vchiq_remove_service(service->handle);
  19374. + unlock_service(service);
  19375. + }
  19376. +
  19377. + return VCHIQ_SUCCESS;
  19378. +}
  19379. +
  19380. +VCHIQ_STATUS_T
  19381. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  19382. +{
  19383. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19384. +
  19385. + switch (state->conn_state) {
  19386. + case VCHIQ_CONNSTATE_CONNECTED:
  19387. + /* Request a pause */
  19388. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  19389. + request_poll(state, NULL, 0);
  19390. + break;
  19391. + default:
  19392. + vchiq_log_error(vchiq_core_log_level,
  19393. + "vchiq_pause_internal in state %s\n",
  19394. + conn_state_names[state->conn_state]);
  19395. + status = VCHIQ_ERROR;
  19396. + VCHIQ_STATS_INC(state, error_count);
  19397. + break;
  19398. + }
  19399. +
  19400. + return status;
  19401. +}
  19402. +
  19403. +VCHIQ_STATUS_T
  19404. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  19405. +{
  19406. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19407. +
  19408. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  19409. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  19410. + request_poll(state, NULL, 0);
  19411. + } else {
  19412. + status = VCHIQ_ERROR;
  19413. + VCHIQ_STATS_INC(state, error_count);
  19414. + }
  19415. +
  19416. + return status;
  19417. +}
  19418. +
  19419. +VCHIQ_STATUS_T
  19420. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  19421. +{
  19422. + /* Unregister the service */
  19423. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19424. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19425. +
  19426. + if (!service)
  19427. + return VCHIQ_ERROR;
  19428. +
  19429. + vchiq_log_info(vchiq_core_log_level,
  19430. + "%d: close_service:%d",
  19431. + service->state->id, service->localport);
  19432. +
  19433. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  19434. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  19435. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  19436. + unlock_service(service);
  19437. + return VCHIQ_ERROR;
  19438. + }
  19439. +
  19440. + mark_service_closing(service);
  19441. +
  19442. + if (current == service->state->slot_handler_thread) {
  19443. + status = vchiq_close_service_internal(service,
  19444. + 0/*!close_recvd*/);
  19445. + BUG_ON(status == VCHIQ_RETRY);
  19446. + } else {
  19447. + /* Mark the service for termination by the slot handler */
  19448. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  19449. + }
  19450. +
  19451. + while (1) {
  19452. + if (down_interruptible(&service->remove_event) != 0) {
  19453. + status = VCHIQ_RETRY;
  19454. + break;
  19455. + }
  19456. +
  19457. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  19458. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  19459. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  19460. + break;
  19461. +
  19462. + vchiq_log_warning(vchiq_core_log_level,
  19463. + "%d: close_service:%d - waiting in state %s",
  19464. + service->state->id, service->localport,
  19465. + srvstate_names[service->srvstate]);
  19466. + }
  19467. +
  19468. + if ((status == VCHIQ_SUCCESS) &&
  19469. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  19470. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  19471. + status = VCHIQ_ERROR;
  19472. +
  19473. + unlock_service(service);
  19474. +
  19475. + return status;
  19476. +}
  19477. +
  19478. +VCHIQ_STATUS_T
  19479. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  19480. +{
  19481. + /* Unregister the service */
  19482. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19483. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19484. +
  19485. + if (!service)
  19486. + return VCHIQ_ERROR;
  19487. +
  19488. + vchiq_log_info(vchiq_core_log_level,
  19489. + "%d: remove_service:%d",
  19490. + service->state->id, service->localport);
  19491. +
  19492. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  19493. + unlock_service(service);
  19494. + return VCHIQ_ERROR;
  19495. + }
  19496. +
  19497. + mark_service_closing(service);
  19498. +
  19499. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  19500. + (current == service->state->slot_handler_thread)) {
  19501. + /* Make it look like a client, because it must be removed and
  19502. + not left in the LISTENING state. */
  19503. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  19504. +
  19505. + status = vchiq_close_service_internal(service,
  19506. + 0/*!close_recvd*/);
  19507. + BUG_ON(status == VCHIQ_RETRY);
  19508. + } else {
  19509. + /* Mark the service for removal by the slot handler */
  19510. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  19511. + }
  19512. + while (1) {
  19513. + if (down_interruptible(&service->remove_event) != 0) {
  19514. + status = VCHIQ_RETRY;
  19515. + break;
  19516. + }
  19517. +
  19518. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  19519. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  19520. + break;
  19521. +
  19522. + vchiq_log_warning(vchiq_core_log_level,
  19523. + "%d: remove_service:%d - waiting in state %s",
  19524. + service->state->id, service->localport,
  19525. + srvstate_names[service->srvstate]);
  19526. + }
  19527. +
  19528. + if ((status == VCHIQ_SUCCESS) &&
  19529. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  19530. + status = VCHIQ_ERROR;
  19531. +
  19532. + unlock_service(service);
  19533. +
  19534. + return status;
  19535. +}
  19536. +
  19537. +
  19538. +/* This function may be called by kernel threads or user threads.
  19539. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  19540. + * received and the call should be retried after being returned to user
  19541. + * context.
  19542. + * When called in blocking mode, the userdata field points to a bulk_waiter
  19543. + * structure.
  19544. + */
  19545. +VCHIQ_STATUS_T
  19546. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  19547. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  19548. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  19549. +{
  19550. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19551. + VCHIQ_BULK_QUEUE_T *queue;
  19552. + VCHIQ_BULK_T *bulk;
  19553. + VCHIQ_STATE_T *state;
  19554. + struct bulk_waiter *bulk_waiter = NULL;
  19555. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  19556. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  19557. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  19558. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  19559. +
  19560. + if (!service ||
  19561. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  19562. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  19563. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  19564. + goto error_exit;
  19565. +
  19566. + switch (mode) {
  19567. + case VCHIQ_BULK_MODE_NOCALLBACK:
  19568. + case VCHIQ_BULK_MODE_CALLBACK:
  19569. + break;
  19570. + case VCHIQ_BULK_MODE_BLOCKING:
  19571. + bulk_waiter = (struct bulk_waiter *)userdata;
  19572. + sema_init(&bulk_waiter->event, 0);
  19573. + bulk_waiter->actual = 0;
  19574. + bulk_waiter->bulk = NULL;
  19575. + break;
  19576. + case VCHIQ_BULK_MODE_WAITING:
  19577. + bulk_waiter = (struct bulk_waiter *)userdata;
  19578. + bulk = bulk_waiter->bulk;
  19579. + goto waiting;
  19580. + default:
  19581. + goto error_exit;
  19582. + }
  19583. +
  19584. + state = service->state;
  19585. +
  19586. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  19587. + &service->bulk_tx : &service->bulk_rx;
  19588. +
  19589. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  19590. + status = VCHIQ_RETRY;
  19591. + goto error_exit;
  19592. + }
  19593. +
  19594. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  19595. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  19596. + do {
  19597. + mutex_unlock(&service->bulk_mutex);
  19598. + if (down_interruptible(&service->bulk_remove_event)
  19599. + != 0) {
  19600. + status = VCHIQ_RETRY;
  19601. + goto error_exit;
  19602. + }
  19603. + if (mutex_lock_interruptible(&service->bulk_mutex)
  19604. + != 0) {
  19605. + status = VCHIQ_RETRY;
  19606. + goto error_exit;
  19607. + }
  19608. + } while (queue->local_insert == queue->remove +
  19609. + VCHIQ_NUM_SERVICE_BULKS);
  19610. + }
  19611. +
  19612. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  19613. +
  19614. + bulk->mode = mode;
  19615. + bulk->dir = dir;
  19616. + bulk->userdata = userdata;
  19617. + bulk->size = size;
  19618. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  19619. +
  19620. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  19621. + VCHIQ_SUCCESS)
  19622. + goto unlock_error_exit;
  19623. +
  19624. + wmb();
  19625. +
  19626. + vchiq_log_info(vchiq_core_log_level,
  19627. + "%d: bt (%d->%d) %cx %x@%x %x",
  19628. + state->id,
  19629. + service->localport, service->remoteport, dir_char,
  19630. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  19631. +
  19632. + if (state->is_master) {
  19633. + queue->local_insert++;
  19634. + if (resolve_bulks(service, queue))
  19635. + request_poll(state, service,
  19636. + (dir == VCHIQ_BULK_TRANSMIT) ?
  19637. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  19638. + } else {
  19639. + int payload[2] = { (int)bulk->data, bulk->size };
  19640. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  19641. +
  19642. + status = queue_message(state, NULL,
  19643. + VCHIQ_MAKE_MSG(dir_msgtype,
  19644. + service->localport, service->remoteport),
  19645. + &element, 1, sizeof(payload), 1);
  19646. + if (status != VCHIQ_SUCCESS) {
  19647. + vchiq_complete_bulk(bulk);
  19648. + goto unlock_error_exit;
  19649. + }
  19650. + queue->local_insert++;
  19651. + }
  19652. +
  19653. + mutex_unlock(&service->bulk_mutex);
  19654. +
  19655. + vchiq_log_trace(vchiq_core_log_level,
  19656. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  19657. + state->id,
  19658. + service->localport, dir_char,
  19659. + queue->local_insert, queue->remote_insert, queue->process);
  19660. +
  19661. +waiting:
  19662. + unlock_service(service);
  19663. +
  19664. + status = VCHIQ_SUCCESS;
  19665. +
  19666. + if (bulk_waiter) {
  19667. + bulk_waiter->bulk = bulk;
  19668. + if (down_interruptible(&bulk_waiter->event) != 0)
  19669. + status = VCHIQ_RETRY;
  19670. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  19671. + status = VCHIQ_ERROR;
  19672. + }
  19673. +
  19674. + return status;
  19675. +
  19676. +unlock_error_exit:
  19677. + mutex_unlock(&service->bulk_mutex);
  19678. +
  19679. +error_exit:
  19680. + if (service)
  19681. + unlock_service(service);
  19682. + return status;
  19683. +}
  19684. +
  19685. +VCHIQ_STATUS_T
  19686. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  19687. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  19688. +{
  19689. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19690. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  19691. +
  19692. + unsigned int size = 0;
  19693. + unsigned int i;
  19694. +
  19695. + if (!service ||
  19696. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  19697. + goto error_exit;
  19698. +
  19699. + for (i = 0; i < (unsigned int)count; i++) {
  19700. + if (elements[i].size) {
  19701. + if (elements[i].data == NULL) {
  19702. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  19703. + goto error_exit;
  19704. + }
  19705. + size += elements[i].size;
  19706. + }
  19707. + }
  19708. +
  19709. + if (size > VCHIQ_MAX_MSG_SIZE) {
  19710. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  19711. + goto error_exit;
  19712. + }
  19713. +
  19714. + switch (service->srvstate) {
  19715. + case VCHIQ_SRVSTATE_OPEN:
  19716. + status = queue_message(service->state, service,
  19717. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  19718. + service->localport,
  19719. + service->remoteport),
  19720. + elements, count, size, 1);
  19721. + break;
  19722. + case VCHIQ_SRVSTATE_OPENSYNC:
  19723. + status = queue_message_sync(service->state, service,
  19724. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  19725. + service->localport,
  19726. + service->remoteport),
  19727. + elements, count, size, 1);
  19728. + break;
  19729. + default:
  19730. + status = VCHIQ_ERROR;
  19731. + break;
  19732. + }
  19733. +
  19734. +error_exit:
  19735. + if (service)
  19736. + unlock_service(service);
  19737. +
  19738. + return status;
  19739. +}
  19740. +
  19741. +void
  19742. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  19743. +{
  19744. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19745. + VCHIQ_SHARED_STATE_T *remote;
  19746. + VCHIQ_STATE_T *state;
  19747. + int slot_index;
  19748. +
  19749. + if (!service)
  19750. + return;
  19751. +
  19752. + state = service->state;
  19753. + remote = state->remote;
  19754. +
  19755. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  19756. +
  19757. + if ((slot_index >= remote->slot_first) &&
  19758. + (slot_index <= remote->slot_last)) {
  19759. + int msgid = header->msgid;
  19760. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  19761. + VCHIQ_SLOT_INFO_T *slot_info =
  19762. + SLOT_INFO_FROM_INDEX(state, slot_index);
  19763. +
  19764. + release_slot(state, slot_info, header, service);
  19765. + }
  19766. + } else if (slot_index == remote->slot_sync)
  19767. + release_message_sync(state, header);
  19768. +
  19769. + unlock_service(service);
  19770. +}
  19771. +
  19772. +static void
  19773. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  19774. +{
  19775. + header->msgid = VCHIQ_MSGID_PADDING;
  19776. + wmb();
  19777. + remote_event_signal(&state->remote->sync_release);
  19778. +}
  19779. +
  19780. +VCHIQ_STATUS_T
  19781. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  19782. +{
  19783. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  19784. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19785. +
  19786. + if (!service ||
  19787. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  19788. + !peer_version)
  19789. + goto exit;
  19790. + *peer_version = service->peer_version;
  19791. + status = VCHIQ_SUCCESS;
  19792. +
  19793. +exit:
  19794. + if (service)
  19795. + unlock_service(service);
  19796. + return status;
  19797. +}
  19798. +
  19799. +VCHIQ_STATUS_T
  19800. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  19801. + int config_size, VCHIQ_CONFIG_T *pconfig)
  19802. +{
  19803. + VCHIQ_CONFIG_T config;
  19804. +
  19805. + (void)instance;
  19806. +
  19807. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  19808. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  19809. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  19810. + config.max_services = VCHIQ_MAX_SERVICES;
  19811. + config.version = VCHIQ_VERSION;
  19812. + config.version_min = VCHIQ_VERSION_MIN;
  19813. +
  19814. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  19815. + return VCHIQ_ERROR;
  19816. +
  19817. + memcpy(pconfig, &config,
  19818. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  19819. +
  19820. + return VCHIQ_SUCCESS;
  19821. +}
  19822. +
  19823. +VCHIQ_STATUS_T
  19824. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  19825. + VCHIQ_SERVICE_OPTION_T option, int value)
  19826. +{
  19827. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  19828. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  19829. +
  19830. + if (service) {
  19831. + switch (option) {
  19832. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  19833. + service->auto_close = value;
  19834. + status = VCHIQ_SUCCESS;
  19835. + break;
  19836. +
  19837. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  19838. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  19839. + &service->state->service_quotas[
  19840. + service->localport];
  19841. + if (value == 0)
  19842. + value = service->state->default_slot_quota;
  19843. + if ((value >= service_quota->slot_use_count) &&
  19844. + (value < (unsigned short)~0)) {
  19845. + service_quota->slot_quota = value;
  19846. + if ((value >= service_quota->slot_use_count) &&
  19847. + (service_quota->message_quota >=
  19848. + service_quota->message_use_count)) {
  19849. + /* Signal the service that it may have
  19850. + ** dropped below its quota */
  19851. + up(&service_quota->quota_event);
  19852. + }
  19853. + status = VCHIQ_SUCCESS;
  19854. + }
  19855. + } break;
  19856. +
  19857. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  19858. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  19859. + &service->state->service_quotas[
  19860. + service->localport];
  19861. + if (value == 0)
  19862. + value = service->state->default_message_quota;
  19863. + if ((value >= service_quota->message_use_count) &&
  19864. + (value < (unsigned short)~0)) {
  19865. + service_quota->message_quota = value;
  19866. + if ((value >=
  19867. + service_quota->message_use_count) &&
  19868. + (service_quota->slot_quota >=
  19869. + service_quota->slot_use_count))
  19870. + /* Signal the service that it may have
  19871. + ** dropped below its quota */
  19872. + up(&service_quota->quota_event);
  19873. + status = VCHIQ_SUCCESS;
  19874. + }
  19875. + } break;
  19876. +
  19877. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  19878. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  19879. + (service->srvstate ==
  19880. + VCHIQ_SRVSTATE_LISTENING)) {
  19881. + service->sync = value;
  19882. + status = VCHIQ_SUCCESS;
  19883. + }
  19884. + break;
  19885. +
  19886. + default:
  19887. + break;
  19888. + }
  19889. + unlock_service(service);
  19890. + }
  19891. +
  19892. + return status;
  19893. +}
  19894. +
  19895. +void
  19896. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  19897. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  19898. +{
  19899. + static const char *const debug_names[] = {
  19900. + "<entries>",
  19901. + "SLOT_HANDLER_COUNT",
  19902. + "SLOT_HANDLER_LINE",
  19903. + "PARSE_LINE",
  19904. + "PARSE_HEADER",
  19905. + "PARSE_MSGID",
  19906. + "AWAIT_COMPLETION_LINE",
  19907. + "DEQUEUE_MESSAGE_LINE",
  19908. + "SERVICE_CALLBACK_LINE",
  19909. + "MSG_QUEUE_FULL_COUNT",
  19910. + "COMPLETION_QUEUE_FULL_COUNT"
  19911. + };
  19912. + int i;
  19913. +
  19914. + char buf[80];
  19915. + int len;
  19916. + len = snprintf(buf, sizeof(buf),
  19917. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  19918. + label, shared->slot_first, shared->slot_last,
  19919. + shared->tx_pos, shared->slot_queue_recycle);
  19920. + vchiq_dump(dump_context, buf, len + 1);
  19921. +
  19922. + len = snprintf(buf, sizeof(buf),
  19923. + " Slots claimed:");
  19924. + vchiq_dump(dump_context, buf, len + 1);
  19925. +
  19926. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  19927. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  19928. + if (slot_info.use_count != slot_info.release_count) {
  19929. + len = snprintf(buf, sizeof(buf),
  19930. + " %d: %d/%d", i, slot_info.use_count,
  19931. + slot_info.release_count);
  19932. + vchiq_dump(dump_context, buf, len + 1);
  19933. + }
  19934. + }
  19935. +
  19936. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  19937. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  19938. + debug_names[i], shared->debug[i], shared->debug[i]);
  19939. + vchiq_dump(dump_context, buf, len + 1);
  19940. + }
  19941. +}
  19942. +
  19943. +void
  19944. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  19945. +{
  19946. + char buf[80];
  19947. + int len;
  19948. + int i;
  19949. +
  19950. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  19951. + conn_state_names[state->conn_state]);
  19952. + vchiq_dump(dump_context, buf, len + 1);
  19953. +
  19954. + len = snprintf(buf, sizeof(buf),
  19955. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  19956. + state->local->tx_pos,
  19957. + (uint32_t)state->tx_data +
  19958. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  19959. + state->rx_pos,
  19960. + (uint32_t)state->rx_data +
  19961. + (state->rx_pos & VCHIQ_SLOT_MASK));
  19962. + vchiq_dump(dump_context, buf, len + 1);
  19963. +
  19964. + len = snprintf(buf, sizeof(buf),
  19965. + " Version: %d (min %d)",
  19966. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  19967. + vchiq_dump(dump_context, buf, len + 1);
  19968. +
  19969. + if (VCHIQ_ENABLE_STATS) {
  19970. + len = snprintf(buf, sizeof(buf),
  19971. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  19972. + "error_count=%d",
  19973. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  19974. + state->stats.error_count);
  19975. + vchiq_dump(dump_context, buf, len + 1);
  19976. + }
  19977. +
  19978. + len = snprintf(buf, sizeof(buf),
  19979. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  19980. + "(%d data)",
  19981. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  19982. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  19983. + state->data_quota - state->data_use_count,
  19984. + state->local->slot_queue_recycle - state->slot_queue_available,
  19985. + state->stats.slot_stalls, state->stats.data_stalls);
  19986. + vchiq_dump(dump_context, buf, len + 1);
  19987. +
  19988. + vchiq_dump_platform_state(dump_context);
  19989. +
  19990. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  19991. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  19992. +
  19993. + vchiq_dump_platform_instances(dump_context);
  19994. +
  19995. + for (i = 0; i < state->unused_service; i++) {
  19996. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  19997. +
  19998. + if (service) {
  19999. + vchiq_dump_service_state(dump_context, service);
  20000. + unlock_service(service);
  20001. + }
  20002. + }
  20003. +}
  20004. +
  20005. +void
  20006. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  20007. +{
  20008. + char buf[80];
  20009. + int len;
  20010. +
  20011. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  20012. + service->localport, srvstate_names[service->srvstate],
  20013. + service->ref_count - 1); /*Don't include the lock just taken*/
  20014. +
  20015. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  20016. + char remoteport[30];
  20017. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  20018. + &service->state->service_quotas[service->localport];
  20019. + int fourcc = service->base.fourcc;
  20020. + int tx_pending, rx_pending;
  20021. + if (service->remoteport != VCHIQ_PORT_FREE) {
  20022. + int len2 = snprintf(remoteport, sizeof(remoteport),
  20023. + "%d", service->remoteport);
  20024. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  20025. + snprintf(remoteport + len2,
  20026. + sizeof(remoteport) - len2,
  20027. + " (client %x)", service->client_id);
  20028. + } else
  20029. + strcpy(remoteport, "n/a");
  20030. +
  20031. + len += snprintf(buf + len, sizeof(buf) - len,
  20032. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  20033. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  20034. + remoteport,
  20035. + service_quota->message_use_count,
  20036. + service_quota->message_quota,
  20037. + service_quota->slot_use_count,
  20038. + service_quota->slot_quota);
  20039. +
  20040. + vchiq_dump(dump_context, buf, len + 1);
  20041. +
  20042. + tx_pending = service->bulk_tx.local_insert -
  20043. + service->bulk_tx.remote_insert;
  20044. +
  20045. + rx_pending = service->bulk_rx.local_insert -
  20046. + service->bulk_rx.remote_insert;
  20047. +
  20048. + len = snprintf(buf, sizeof(buf),
  20049. + " Bulk: tx_pending=%d (size %d),"
  20050. + " rx_pending=%d (size %d)",
  20051. + tx_pending,
  20052. + tx_pending ? service->bulk_tx.bulks[
  20053. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  20054. + rx_pending,
  20055. + rx_pending ? service->bulk_rx.bulks[
  20056. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  20057. +
  20058. + if (VCHIQ_ENABLE_STATS) {
  20059. + vchiq_dump(dump_context, buf, len + 1);
  20060. +
  20061. + len = snprintf(buf, sizeof(buf),
  20062. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  20063. + "rx_count=%d, rx_bytes=%llu",
  20064. + service->stats.ctrl_tx_count,
  20065. + service->stats.ctrl_tx_bytes,
  20066. + service->stats.ctrl_rx_count,
  20067. + service->stats.ctrl_rx_bytes);
  20068. + vchiq_dump(dump_context, buf, len + 1);
  20069. +
  20070. + len = snprintf(buf, sizeof(buf),
  20071. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  20072. + "rx_count=%d, rx_bytes=%llu",
  20073. + service->stats.bulk_tx_count,
  20074. + service->stats.bulk_tx_bytes,
  20075. + service->stats.bulk_rx_count,
  20076. + service->stats.bulk_rx_bytes);
  20077. + vchiq_dump(dump_context, buf, len + 1);
  20078. +
  20079. + len = snprintf(buf, sizeof(buf),
  20080. + " %d quota stalls, %d slot stalls, "
  20081. + "%d bulk stalls, %d aborted, %d errors",
  20082. + service->stats.quota_stalls,
  20083. + service->stats.slot_stalls,
  20084. + service->stats.bulk_stalls,
  20085. + service->stats.bulk_aborted_count,
  20086. + service->stats.error_count);
  20087. + }
  20088. + }
  20089. +
  20090. + vchiq_dump(dump_context, buf, len + 1);
  20091. +
  20092. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  20093. + vchiq_dump_platform_service_state(dump_context, service);
  20094. +}
  20095. +
  20096. +
  20097. +void
  20098. +vchiq_loud_error_header(void)
  20099. +{
  20100. + vchiq_log_error(vchiq_core_log_level,
  20101. + "============================================================"
  20102. + "================");
  20103. + vchiq_log_error(vchiq_core_log_level,
  20104. + "============================================================"
  20105. + "================");
  20106. + vchiq_log_error(vchiq_core_log_level, "=====");
  20107. +}
  20108. +
  20109. +void
  20110. +vchiq_loud_error_footer(void)
  20111. +{
  20112. + vchiq_log_error(vchiq_core_log_level, "=====");
  20113. + vchiq_log_error(vchiq_core_log_level,
  20114. + "============================================================"
  20115. + "================");
  20116. + vchiq_log_error(vchiq_core_log_level,
  20117. + "============================================================"
  20118. + "================");
  20119. +}
  20120. +
  20121. +
  20122. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  20123. +{
  20124. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  20125. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  20126. + status = queue_message(state, NULL,
  20127. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  20128. + NULL, 0, 0, 0);
  20129. + return status;
  20130. +}
  20131. +
  20132. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  20133. +{
  20134. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  20135. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  20136. + status = queue_message(state, NULL,
  20137. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  20138. + NULL, 0, 0, 0);
  20139. + return status;
  20140. +}
  20141. +
  20142. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  20143. +{
  20144. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  20145. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  20146. + status = queue_message(state, NULL,
  20147. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  20148. + NULL, 0, 0, 0);
  20149. + return status;
  20150. +}
  20151. +
  20152. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  20153. + size_t numBytes)
  20154. +{
  20155. + const uint8_t *mem = (const uint8_t *)voidMem;
  20156. + size_t offset;
  20157. + char lineBuf[100];
  20158. + char *s;
  20159. +
  20160. + while (numBytes > 0) {
  20161. + s = lineBuf;
  20162. +
  20163. + for (offset = 0; offset < 16; offset++) {
  20164. + if (offset < numBytes)
  20165. + s += snprintf(s, 4, "%02x ", mem[offset]);
  20166. + else
  20167. + s += snprintf(s, 4, " ");
  20168. + }
  20169. +
  20170. + for (offset = 0; offset < 16; offset++) {
  20171. + if (offset < numBytes) {
  20172. + uint8_t ch = mem[offset];
  20173. +
  20174. + if ((ch < ' ') || (ch > '~'))
  20175. + ch = '.';
  20176. + *s++ = (char)ch;
  20177. + }
  20178. + }
  20179. + *s++ = '\0';
  20180. +
  20181. + if ((label != NULL) && (*label != '\0'))
  20182. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  20183. + "%s: %08x: %s", label, addr, lineBuf);
  20184. + else
  20185. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  20186. + "%08x: %s", addr, lineBuf);
  20187. +
  20188. + addr += 16;
  20189. + mem += 16;
  20190. + if (numBytes > 16)
  20191. + numBytes -= 16;
  20192. + else
  20193. + numBytes = 0;
  20194. + }
  20195. +}
  20196. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  20197. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  20198. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-02-07 19:57:28.000000000 +0100
  20199. @@ -0,0 +1,706 @@
  20200. +/**
  20201. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  20202. + *
  20203. + * Redistribution and use in source and binary forms, with or without
  20204. + * modification, are permitted provided that the following conditions
  20205. + * are met:
  20206. + * 1. Redistributions of source code must retain the above copyright
  20207. + * notice, this list of conditions, and the following disclaimer,
  20208. + * without modification.
  20209. + * 2. Redistributions in binary form must reproduce the above copyright
  20210. + * notice, this list of conditions and the following disclaimer in the
  20211. + * documentation and/or other materials provided with the distribution.
  20212. + * 3. The names of the above-listed copyright holders may not be used
  20213. + * to endorse or promote products derived from this software without
  20214. + * specific prior written permission.
  20215. + *
  20216. + * ALTERNATIVELY, this software may be distributed under the terms of the
  20217. + * GNU General Public License ("GPL") version 2, as published by the Free
  20218. + * Software Foundation.
  20219. + *
  20220. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20221. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20222. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20223. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20224. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20225. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20226. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20227. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20228. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20229. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20230. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20231. + */
  20232. +
  20233. +#ifndef VCHIQ_CORE_H
  20234. +#define VCHIQ_CORE_H
  20235. +
  20236. +#include <linux/mutex.h>
  20237. +#include <linux/semaphore.h>
  20238. +#include <linux/kthread.h>
  20239. +
  20240. +#include "vchiq_cfg.h"
  20241. +
  20242. +#include "vchiq.h"
  20243. +
  20244. +/* Run time control of log level, based on KERN_XXX level. */
  20245. +#define VCHIQ_LOG_DEFAULT 4
  20246. +#define VCHIQ_LOG_ERROR 3
  20247. +#define VCHIQ_LOG_WARNING 4
  20248. +#define VCHIQ_LOG_INFO 6
  20249. +#define VCHIQ_LOG_TRACE 7
  20250. +
  20251. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  20252. +
  20253. +#ifndef vchiq_log_error
  20254. +#define vchiq_log_error(cat, fmt, ...) \
  20255. + do { if (cat >= VCHIQ_LOG_ERROR) \
  20256. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  20257. +#endif
  20258. +#ifndef vchiq_log_warning
  20259. +#define vchiq_log_warning(cat, fmt, ...) \
  20260. + do { if (cat >= VCHIQ_LOG_WARNING) \
  20261. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  20262. +#endif
  20263. +#ifndef vchiq_log_info
  20264. +#define vchiq_log_info(cat, fmt, ...) \
  20265. + do { if (cat >= VCHIQ_LOG_INFO) \
  20266. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  20267. +#endif
  20268. +#ifndef vchiq_log_trace
  20269. +#define vchiq_log_trace(cat, fmt, ...) \
  20270. + do { if (cat >= VCHIQ_LOG_TRACE) \
  20271. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  20272. +#endif
  20273. +
  20274. +#define vchiq_loud_error(...) \
  20275. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  20276. +
  20277. +#ifndef vchiq_static_assert
  20278. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  20279. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  20280. +#endif
  20281. +
  20282. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  20283. +
  20284. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  20285. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  20286. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  20287. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  20288. +
  20289. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  20290. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  20291. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  20292. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  20293. +
  20294. +#define VCHIQ_MSG_PADDING 0 /* - */
  20295. +#define VCHIQ_MSG_CONNECT 1 /* - */
  20296. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  20297. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  20298. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  20299. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  20300. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  20301. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  20302. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  20303. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  20304. +#define VCHIQ_MSG_PAUSE 10 /* - */
  20305. +#define VCHIQ_MSG_RESUME 11 /* - */
  20306. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  20307. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  20308. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  20309. +
  20310. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  20311. +#define VCHIQ_PORT_FREE 0x1000
  20312. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  20313. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  20314. + ((type<<24) | (srcport<<12) | (dstport<<0))
  20315. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  20316. +#define VCHIQ_MSG_SRCPORT(msgid) \
  20317. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  20318. +#define VCHIQ_MSG_DSTPORT(msgid) \
  20319. + ((unsigned short)msgid & 0xfff)
  20320. +
  20321. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  20322. + ((fourcc) >> 24) & 0xff, \
  20323. + ((fourcc) >> 16) & 0xff, \
  20324. + ((fourcc) >> 8) & 0xff, \
  20325. + (fourcc) & 0xff
  20326. +
  20327. +/* Ensure the fields are wide enough */
  20328. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  20329. + == 0);
  20330. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  20331. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  20332. + (unsigned int)VCHIQ_PORT_FREE);
  20333. +
  20334. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  20335. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  20336. +
  20337. +#define VCHIQ_FOURCC_INVALID 0x00000000
  20338. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  20339. +
  20340. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  20341. +
  20342. +typedef uint32_t BITSET_T;
  20343. +
  20344. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  20345. +
  20346. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  20347. +#define BITSET_WORD(b) (b >> 5)
  20348. +#define BITSET_BIT(b) (1 << (b & 31))
  20349. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  20350. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  20351. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  20352. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  20353. +
  20354. +#if VCHIQ_ENABLE_STATS
  20355. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  20356. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  20357. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  20358. + (service->stats. stat += addend)
  20359. +#else
  20360. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  20361. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  20362. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  20363. +#endif
  20364. +
  20365. +enum {
  20366. + DEBUG_ENTRIES,
  20367. +#if VCHIQ_ENABLE_DEBUG
  20368. + DEBUG_SLOT_HANDLER_COUNT,
  20369. + DEBUG_SLOT_HANDLER_LINE,
  20370. + DEBUG_PARSE_LINE,
  20371. + DEBUG_PARSE_HEADER,
  20372. + DEBUG_PARSE_MSGID,
  20373. + DEBUG_AWAIT_COMPLETION_LINE,
  20374. + DEBUG_DEQUEUE_MESSAGE_LINE,
  20375. + DEBUG_SERVICE_CALLBACK_LINE,
  20376. + DEBUG_MSG_QUEUE_FULL_COUNT,
  20377. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  20378. +#endif
  20379. + DEBUG_MAX
  20380. +};
  20381. +
  20382. +#if VCHIQ_ENABLE_DEBUG
  20383. +
  20384. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  20385. +#define DEBUG_TRACE(d) \
  20386. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  20387. +#define DEBUG_VALUE(d, v) \
  20388. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  20389. +#define DEBUG_COUNT(d) \
  20390. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  20391. +
  20392. +#else /* VCHIQ_ENABLE_DEBUG */
  20393. +
  20394. +#define DEBUG_INITIALISE(local)
  20395. +#define DEBUG_TRACE(d)
  20396. +#define DEBUG_VALUE(d, v)
  20397. +#define DEBUG_COUNT(d)
  20398. +
  20399. +#endif /* VCHIQ_ENABLE_DEBUG */
  20400. +
  20401. +typedef enum {
  20402. + VCHIQ_CONNSTATE_DISCONNECTED,
  20403. + VCHIQ_CONNSTATE_CONNECTING,
  20404. + VCHIQ_CONNSTATE_CONNECTED,
  20405. + VCHIQ_CONNSTATE_PAUSING,
  20406. + VCHIQ_CONNSTATE_PAUSE_SENT,
  20407. + VCHIQ_CONNSTATE_PAUSED,
  20408. + VCHIQ_CONNSTATE_RESUMING,
  20409. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  20410. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  20411. +} VCHIQ_CONNSTATE_T;
  20412. +
  20413. +enum {
  20414. + VCHIQ_SRVSTATE_FREE,
  20415. + VCHIQ_SRVSTATE_HIDDEN,
  20416. + VCHIQ_SRVSTATE_LISTENING,
  20417. + VCHIQ_SRVSTATE_OPENING,
  20418. + VCHIQ_SRVSTATE_OPEN,
  20419. + VCHIQ_SRVSTATE_OPENSYNC,
  20420. + VCHIQ_SRVSTATE_CLOSESENT,
  20421. + VCHIQ_SRVSTATE_CLOSERECVD,
  20422. + VCHIQ_SRVSTATE_CLOSEWAIT,
  20423. + VCHIQ_SRVSTATE_CLOSED
  20424. +};
  20425. +
  20426. +enum {
  20427. + VCHIQ_POLL_TERMINATE,
  20428. + VCHIQ_POLL_REMOVE,
  20429. + VCHIQ_POLL_TXNOTIFY,
  20430. + VCHIQ_POLL_RXNOTIFY,
  20431. + VCHIQ_POLL_COUNT
  20432. +};
  20433. +
  20434. +typedef enum {
  20435. + VCHIQ_BULK_TRANSMIT,
  20436. + VCHIQ_BULK_RECEIVE
  20437. +} VCHIQ_BULK_DIR_T;
  20438. +
  20439. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  20440. +
  20441. +typedef struct vchiq_bulk_struct {
  20442. + short mode;
  20443. + short dir;
  20444. + void *userdata;
  20445. + VCHI_MEM_HANDLE_T handle;
  20446. + void *data;
  20447. + int size;
  20448. + void *remote_data;
  20449. + int remote_size;
  20450. + int actual;
  20451. +} VCHIQ_BULK_T;
  20452. +
  20453. +typedef struct vchiq_bulk_queue_struct {
  20454. + int local_insert; /* Where to insert the next local bulk */
  20455. + int remote_insert; /* Where to insert the next remote bulk (master) */
  20456. + int process; /* Bulk to transfer next */
  20457. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  20458. + int remove; /* Bulk to notify the local client of, and remove,
  20459. + ** next */
  20460. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  20461. +} VCHIQ_BULK_QUEUE_T;
  20462. +
  20463. +typedef struct remote_event_struct {
  20464. + int armed;
  20465. + int fired;
  20466. + struct semaphore *event;
  20467. +} REMOTE_EVENT_T;
  20468. +
  20469. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  20470. +
  20471. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  20472. +
  20473. +typedef struct vchiq_slot_struct {
  20474. + char data[VCHIQ_SLOT_SIZE];
  20475. +} VCHIQ_SLOT_T;
  20476. +
  20477. +typedef struct vchiq_slot_info_struct {
  20478. + /* Use two counters rather than one to avoid the need for a mutex. */
  20479. + short use_count;
  20480. + short release_count;
  20481. +} VCHIQ_SLOT_INFO_T;
  20482. +
  20483. +typedef struct vchiq_service_struct {
  20484. + VCHIQ_SERVICE_BASE_T base;
  20485. + VCHIQ_SERVICE_HANDLE_T handle;
  20486. + unsigned int ref_count;
  20487. + int srvstate;
  20488. + VCHIQ_USERDATA_TERM_T userdata_term;
  20489. + unsigned int localport;
  20490. + unsigned int remoteport;
  20491. + int public_fourcc;
  20492. + int client_id;
  20493. + char auto_close;
  20494. + char sync;
  20495. + char closing;
  20496. + atomic_t poll_flags;
  20497. + short version;
  20498. + short version_min;
  20499. + short peer_version;
  20500. +
  20501. + VCHIQ_STATE_T *state;
  20502. + VCHIQ_INSTANCE_T instance;
  20503. +
  20504. + int service_use_count;
  20505. +
  20506. + VCHIQ_BULK_QUEUE_T bulk_tx;
  20507. + VCHIQ_BULK_QUEUE_T bulk_rx;
  20508. +
  20509. + struct semaphore remove_event;
  20510. + struct semaphore bulk_remove_event;
  20511. + struct mutex bulk_mutex;
  20512. +
  20513. + struct service_stats_struct {
  20514. + int quota_stalls;
  20515. + int slot_stalls;
  20516. + int bulk_stalls;
  20517. + int error_count;
  20518. + int ctrl_tx_count;
  20519. + int ctrl_rx_count;
  20520. + int bulk_tx_count;
  20521. + int bulk_rx_count;
  20522. + int bulk_aborted_count;
  20523. + uint64_t ctrl_tx_bytes;
  20524. + uint64_t ctrl_rx_bytes;
  20525. + uint64_t bulk_tx_bytes;
  20526. + uint64_t bulk_rx_bytes;
  20527. + } stats;
  20528. +} VCHIQ_SERVICE_T;
  20529. +
  20530. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  20531. + statically allocated, since for accounting reasons a service's slot
  20532. + usage is carried over between users of the same port number.
  20533. + */
  20534. +typedef struct vchiq_service_quota_struct {
  20535. + unsigned short slot_quota;
  20536. + unsigned short slot_use_count;
  20537. + unsigned short message_quota;
  20538. + unsigned short message_use_count;
  20539. + struct semaphore quota_event;
  20540. + int previous_tx_index;
  20541. +} VCHIQ_SERVICE_QUOTA_T;
  20542. +
  20543. +typedef struct vchiq_shared_state_struct {
  20544. +
  20545. + /* A non-zero value here indicates that the content is valid. */
  20546. + int initialised;
  20547. +
  20548. + /* The first and last (inclusive) slots allocated to the owner. */
  20549. + int slot_first;
  20550. + int slot_last;
  20551. +
  20552. + /* The slot allocated to synchronous messages from the owner. */
  20553. + int slot_sync;
  20554. +
  20555. + /* Signalling this event indicates that owner's slot handler thread
  20556. + ** should run. */
  20557. + REMOTE_EVENT_T trigger;
  20558. +
  20559. + /* Indicates the byte position within the stream where the next message
  20560. + ** will be written. The least significant bits are an index into the
  20561. + ** slot. The next bits are the index of the slot in slot_queue. */
  20562. + int tx_pos;
  20563. +
  20564. + /* This event should be signalled when a slot is recycled. */
  20565. + REMOTE_EVENT_T recycle;
  20566. +
  20567. + /* The slot_queue index where the next recycled slot will be written. */
  20568. + int slot_queue_recycle;
  20569. +
  20570. + /* This event should be signalled when a synchronous message is sent. */
  20571. + REMOTE_EVENT_T sync_trigger;
  20572. +
  20573. + /* This event should be signalled when a synchronous message has been
  20574. + ** released. */
  20575. + REMOTE_EVENT_T sync_release;
  20576. +
  20577. + /* A circular buffer of slot indexes. */
  20578. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  20579. +
  20580. + /* Debugging state */
  20581. + int debug[DEBUG_MAX];
  20582. +} VCHIQ_SHARED_STATE_T;
  20583. +
  20584. +typedef struct vchiq_slot_zero_struct {
  20585. + int magic;
  20586. + short version;
  20587. + short version_min;
  20588. + int slot_zero_size;
  20589. + int slot_size;
  20590. + int max_slots;
  20591. + int max_slots_per_side;
  20592. + int platform_data[2];
  20593. + VCHIQ_SHARED_STATE_T master;
  20594. + VCHIQ_SHARED_STATE_T slave;
  20595. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  20596. +} VCHIQ_SLOT_ZERO_T;
  20597. +
  20598. +struct vchiq_state_struct {
  20599. + int id;
  20600. + int initialised;
  20601. + VCHIQ_CONNSTATE_T conn_state;
  20602. + int is_master;
  20603. +
  20604. + VCHIQ_SHARED_STATE_T *local;
  20605. + VCHIQ_SHARED_STATE_T *remote;
  20606. + VCHIQ_SLOT_T *slot_data;
  20607. +
  20608. + unsigned short default_slot_quota;
  20609. + unsigned short default_message_quota;
  20610. +
  20611. + /* Event indicating connect message received */
  20612. + struct semaphore connect;
  20613. +
  20614. + /* Mutex protecting services */
  20615. + struct mutex mutex;
  20616. + VCHIQ_INSTANCE_T *instance;
  20617. +
  20618. + /* Processes incoming messages */
  20619. + struct task_struct *slot_handler_thread;
  20620. +
  20621. + /* Processes recycled slots */
  20622. + struct task_struct *recycle_thread;
  20623. +
  20624. + /* Processes synchronous messages */
  20625. + struct task_struct *sync_thread;
  20626. +
  20627. + /* Local implementation of the trigger remote event */
  20628. + struct semaphore trigger_event;
  20629. +
  20630. + /* Local implementation of the recycle remote event */
  20631. + struct semaphore recycle_event;
  20632. +
  20633. + /* Local implementation of the sync trigger remote event */
  20634. + struct semaphore sync_trigger_event;
  20635. +
  20636. + /* Local implementation of the sync release remote event */
  20637. + struct semaphore sync_release_event;
  20638. +
  20639. + char *tx_data;
  20640. + char *rx_data;
  20641. + VCHIQ_SLOT_INFO_T *rx_info;
  20642. +
  20643. + struct mutex slot_mutex;
  20644. +
  20645. + struct mutex recycle_mutex;
  20646. +
  20647. + struct mutex sync_mutex;
  20648. +
  20649. + struct mutex bulk_transfer_mutex;
  20650. +
  20651. + /* Indicates the byte position within the stream from where the next
  20652. + ** message will be read. The least significant bits are an index into
  20653. + ** the slot.The next bits are the index of the slot in
  20654. + ** remote->slot_queue. */
  20655. + int rx_pos;
  20656. +
  20657. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  20658. + from remote->tx_pos. */
  20659. + int local_tx_pos;
  20660. +
  20661. + /* The slot_queue index of the slot to become available next. */
  20662. + int slot_queue_available;
  20663. +
  20664. + /* A flag to indicate if any poll has been requested */
  20665. + int poll_needed;
  20666. +
  20667. + /* Ths index of the previous slot used for data messages. */
  20668. + int previous_data_index;
  20669. +
  20670. + /* The number of slots occupied by data messages. */
  20671. + unsigned short data_use_count;
  20672. +
  20673. + /* The maximum number of slots to be occupied by data messages. */
  20674. + unsigned short data_quota;
  20675. +
  20676. + /* An array of bit sets indicating which services must be polled. */
  20677. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  20678. +
  20679. + /* The number of the first unused service */
  20680. + int unused_service;
  20681. +
  20682. + /* Signalled when a free slot becomes available. */
  20683. + struct semaphore slot_available_event;
  20684. +
  20685. + struct semaphore slot_remove_event;
  20686. +
  20687. + /* Signalled when a free data slot becomes available. */
  20688. + struct semaphore data_quota_event;
  20689. +
  20690. + /* Incremented when there are bulk transfers which cannot be processed
  20691. + * whilst paused and must be processed on resume */
  20692. + int deferred_bulks;
  20693. +
  20694. + struct state_stats_struct {
  20695. + int slot_stalls;
  20696. + int data_stalls;
  20697. + int ctrl_tx_count;
  20698. + int ctrl_rx_count;
  20699. + int error_count;
  20700. + } stats;
  20701. +
  20702. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  20703. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  20704. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  20705. +
  20706. + VCHIQ_PLATFORM_STATE_T platform_state;
  20707. +};
  20708. +
  20709. +struct bulk_waiter {
  20710. + VCHIQ_BULK_T *bulk;
  20711. + struct semaphore event;
  20712. + int actual;
  20713. +};
  20714. +
  20715. +extern spinlock_t bulk_waiter_spinlock;
  20716. +
  20717. +extern int vchiq_core_log_level;
  20718. +extern int vchiq_core_msg_log_level;
  20719. +extern int vchiq_sync_log_level;
  20720. +
  20721. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  20722. +
  20723. +extern const char *
  20724. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  20725. +
  20726. +extern VCHIQ_SLOT_ZERO_T *
  20727. +vchiq_init_slots(void *mem_base, int mem_size);
  20728. +
  20729. +extern VCHIQ_STATUS_T
  20730. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  20731. + int is_master);
  20732. +
  20733. +extern VCHIQ_STATUS_T
  20734. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  20735. +
  20736. +extern VCHIQ_SERVICE_T *
  20737. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  20738. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  20739. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  20740. +
  20741. +extern VCHIQ_STATUS_T
  20742. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  20743. +
  20744. +extern VCHIQ_STATUS_T
  20745. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  20746. +
  20747. +extern void
  20748. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  20749. +
  20750. +extern void
  20751. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  20752. +
  20753. +extern VCHIQ_STATUS_T
  20754. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  20755. +
  20756. +extern VCHIQ_STATUS_T
  20757. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  20758. +
  20759. +extern VCHIQ_STATUS_T
  20760. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  20761. +
  20762. +extern void
  20763. +remote_event_pollall(VCHIQ_STATE_T *state);
  20764. +
  20765. +extern VCHIQ_STATUS_T
  20766. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  20767. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  20768. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  20769. +
  20770. +extern void
  20771. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  20772. +
  20773. +extern void
  20774. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  20775. +
  20776. +extern void
  20777. +vchiq_loud_error_header(void);
  20778. +
  20779. +extern void
  20780. +vchiq_loud_error_footer(void);
  20781. +
  20782. +extern void
  20783. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  20784. +
  20785. +static inline VCHIQ_SERVICE_T *
  20786. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  20787. +{
  20788. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  20789. + (VCHIQ_MAX_STATES - 1)];
  20790. + if (!state)
  20791. + return NULL;
  20792. +
  20793. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  20794. +}
  20795. +
  20796. +extern VCHIQ_SERVICE_T *
  20797. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  20798. +
  20799. +extern VCHIQ_SERVICE_T *
  20800. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  20801. +
  20802. +extern VCHIQ_SERVICE_T *
  20803. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  20804. + VCHIQ_SERVICE_HANDLE_T handle);
  20805. +
  20806. +extern VCHIQ_SERVICE_T *
  20807. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  20808. + int *pidx);
  20809. +
  20810. +extern void
  20811. +lock_service(VCHIQ_SERVICE_T *service);
  20812. +
  20813. +extern void
  20814. +unlock_service(VCHIQ_SERVICE_T *service);
  20815. +
  20816. +/* The following functions are called from vchiq_core, and external
  20817. +** implementations must be provided. */
  20818. +
  20819. +extern VCHIQ_STATUS_T
  20820. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  20821. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  20822. +
  20823. +extern void
  20824. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  20825. +
  20826. +extern void
  20827. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  20828. +
  20829. +extern VCHIQ_STATUS_T
  20830. +vchiq_copy_from_user(void *dst, const void *src, int size);
  20831. +
  20832. +extern void
  20833. +remote_event_signal(REMOTE_EVENT_T *event);
  20834. +
  20835. +void
  20836. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  20837. +
  20838. +extern void
  20839. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  20840. +
  20841. +extern VCHIQ_STATUS_T
  20842. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  20843. +
  20844. +extern void
  20845. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  20846. +
  20847. +extern void
  20848. +vchiq_dump(void *dump_context, const char *str, int len);
  20849. +
  20850. +extern void
  20851. +vchiq_dump_platform_state(void *dump_context);
  20852. +
  20853. +extern void
  20854. +vchiq_dump_platform_instances(void *dump_context);
  20855. +
  20856. +extern void
  20857. +vchiq_dump_platform_service_state(void *dump_context,
  20858. + VCHIQ_SERVICE_T *service);
  20859. +
  20860. +extern VCHIQ_STATUS_T
  20861. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  20862. +
  20863. +extern VCHIQ_STATUS_T
  20864. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  20865. +
  20866. +extern void
  20867. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  20868. +
  20869. +extern void
  20870. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  20871. +
  20872. +extern VCHIQ_STATUS_T
  20873. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  20874. +
  20875. +extern VCHIQ_STATUS_T
  20876. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  20877. +
  20878. +extern void
  20879. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  20880. +
  20881. +extern VCHIQ_STATUS_T
  20882. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  20883. +
  20884. +extern VCHIQ_STATUS_T
  20885. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  20886. +
  20887. +extern VCHIQ_STATUS_T
  20888. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  20889. +
  20890. +extern void
  20891. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  20892. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  20893. +
  20894. +extern void
  20895. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  20896. +
  20897. +extern void
  20898. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  20899. +
  20900. +
  20901. +extern void
  20902. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  20903. + size_t numBytes);
  20904. +
  20905. +#endif
  20906. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  20907. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  20908. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-02-07 19:57:28.000000000 +0100
  20909. @@ -0,0 +1,87 @@
  20910. +#!/usr/bin/perl -w
  20911. +
  20912. +use strict;
  20913. +
  20914. +#
  20915. +# Generate a version from available information
  20916. +#
  20917. +
  20918. +my $prefix = shift @ARGV;
  20919. +my $root = shift @ARGV;
  20920. +
  20921. +
  20922. +if ( not defined $root ) {
  20923. + die "usage: $0 prefix root-dir\n";
  20924. +}
  20925. +
  20926. +if ( ! -d $root ) {
  20927. + die "root directory $root not found\n";
  20928. +}
  20929. +
  20930. +my $version = "unknown";
  20931. +my $tainted = "";
  20932. +
  20933. +if ( -d "$root/.git" ) {
  20934. + # attempt to work out git version. only do so
  20935. + # on a linux build host, as cygwin builds are
  20936. + # already slow enough
  20937. +
  20938. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  20939. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  20940. + $version = "no git version";
  20941. + }
  20942. + else {
  20943. + $version = <F>;
  20944. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  20945. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  20946. + }
  20947. +
  20948. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  20949. + $tainted = <G>;
  20950. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  20951. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  20952. + if (length $tainted) {
  20953. + $version = join ' ', $version, "(tainted)";
  20954. + }
  20955. + else {
  20956. + $version = join ' ', $version, "(clean)";
  20957. + }
  20958. + }
  20959. + }
  20960. +}
  20961. +
  20962. +my $hostname = `hostname`;
  20963. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  20964. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  20965. +
  20966. +
  20967. +print STDERR "Version $version\n";
  20968. +print <<EOF;
  20969. +#include "${prefix}_build_info.h"
  20970. +#include <linux/broadcom/vc_debug_sym.h>
  20971. +
  20972. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  20973. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  20974. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  20975. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  20976. +
  20977. +const char *vchiq_get_build_hostname( void )
  20978. +{
  20979. + return vchiq_build_hostname;
  20980. +}
  20981. +
  20982. +const char *vchiq_get_build_version( void )
  20983. +{
  20984. + return vchiq_build_version;
  20985. +}
  20986. +
  20987. +const char *vchiq_get_build_date( void )
  20988. +{
  20989. + return vchiq_build_date;
  20990. +}
  20991. +
  20992. +const char *vchiq_get_build_time( void )
  20993. +{
  20994. + return vchiq_build_time;
  20995. +}
  20996. +EOF
  20997. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  20998. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  20999. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-02-07 19:57:28.000000000 +0100
  21000. @@ -0,0 +1,40 @@
  21001. +/**
  21002. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21003. + *
  21004. + * Redistribution and use in source and binary forms, with or without
  21005. + * modification, are permitted provided that the following conditions
  21006. + * are met:
  21007. + * 1. Redistributions of source code must retain the above copyright
  21008. + * notice, this list of conditions, and the following disclaimer,
  21009. + * without modification.
  21010. + * 2. Redistributions in binary form must reproduce the above copyright
  21011. + * notice, this list of conditions and the following disclaimer in the
  21012. + * documentation and/or other materials provided with the distribution.
  21013. + * 3. The names of the above-listed copyright holders may not be used
  21014. + * to endorse or promote products derived from this software without
  21015. + * specific prior written permission.
  21016. + *
  21017. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21018. + * GNU General Public License ("GPL") version 2, as published by the Free
  21019. + * Software Foundation.
  21020. + *
  21021. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21022. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21023. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21024. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21025. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21026. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21027. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21028. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21029. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21030. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21031. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21032. + */
  21033. +
  21034. +#ifndef VCHIQ_VCHIQ_H
  21035. +#define VCHIQ_VCHIQ_H
  21036. +
  21037. +#include "vchiq_if.h"
  21038. +#include "vchiq_util.h"
  21039. +
  21040. +#endif
  21041. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  21042. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  21043. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-02-07 19:57:28.000000000 +0100
  21044. @@ -0,0 +1,188 @@
  21045. +/**
  21046. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21047. + *
  21048. + * Redistribution and use in source and binary forms, with or without
  21049. + * modification, are permitted provided that the following conditions
  21050. + * are met:
  21051. + * 1. Redistributions of source code must retain the above copyright
  21052. + * notice, this list of conditions, and the following disclaimer,
  21053. + * without modification.
  21054. + * 2. Redistributions in binary form must reproduce the above copyright
  21055. + * notice, this list of conditions and the following disclaimer in the
  21056. + * documentation and/or other materials provided with the distribution.
  21057. + * 3. The names of the above-listed copyright holders may not be used
  21058. + * to endorse or promote products derived from this software without
  21059. + * specific prior written permission.
  21060. + *
  21061. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21062. + * GNU General Public License ("GPL") version 2, as published by the Free
  21063. + * Software Foundation.
  21064. + *
  21065. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21066. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21067. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21068. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21069. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21070. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21071. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21072. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21073. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21074. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21075. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21076. + */
  21077. +
  21078. +#ifndef VCHIQ_IF_H
  21079. +#define VCHIQ_IF_H
  21080. +
  21081. +#include "interface/vchi/vchi_mh.h"
  21082. +
  21083. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  21084. +
  21085. +#define VCHIQ_SLOT_SIZE 4096
  21086. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  21087. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  21088. +
  21089. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  21090. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  21091. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  21092. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  21093. +
  21094. +typedef enum {
  21095. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  21096. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  21097. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  21098. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  21099. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  21100. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  21101. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  21102. +} VCHIQ_REASON_T;
  21103. +
  21104. +typedef enum {
  21105. + VCHIQ_ERROR = -1,
  21106. + VCHIQ_SUCCESS = 0,
  21107. + VCHIQ_RETRY = 1
  21108. +} VCHIQ_STATUS_T;
  21109. +
  21110. +typedef enum {
  21111. + VCHIQ_BULK_MODE_CALLBACK,
  21112. + VCHIQ_BULK_MODE_BLOCKING,
  21113. + VCHIQ_BULK_MODE_NOCALLBACK,
  21114. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  21115. +} VCHIQ_BULK_MODE_T;
  21116. +
  21117. +typedef enum {
  21118. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  21119. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  21120. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  21121. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  21122. +} VCHIQ_SERVICE_OPTION_T;
  21123. +
  21124. +typedef struct vchiq_header_struct {
  21125. + /* The message identifier - opaque to applications. */
  21126. + int msgid;
  21127. +
  21128. + /* Size of message data. */
  21129. + unsigned int size;
  21130. +
  21131. + char data[0]; /* message */
  21132. +} VCHIQ_HEADER_T;
  21133. +
  21134. +typedef struct {
  21135. + const void *data;
  21136. + unsigned int size;
  21137. +} VCHIQ_ELEMENT_T;
  21138. +
  21139. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  21140. +
  21141. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  21142. + VCHIQ_SERVICE_HANDLE_T, void *);
  21143. +
  21144. +typedef struct vchiq_service_base_struct {
  21145. + int fourcc;
  21146. + VCHIQ_CALLBACK_T callback;
  21147. + void *userdata;
  21148. +} VCHIQ_SERVICE_BASE_T;
  21149. +
  21150. +typedef struct vchiq_service_params_struct {
  21151. + int fourcc;
  21152. + VCHIQ_CALLBACK_T callback;
  21153. + void *userdata;
  21154. + short version; /* Increment for non-trivial changes */
  21155. + short version_min; /* Update for incompatible changes */
  21156. +} VCHIQ_SERVICE_PARAMS_T;
  21157. +
  21158. +typedef struct vchiq_config_struct {
  21159. + unsigned int max_msg_size;
  21160. + unsigned int bulk_threshold; /* The message size above which it
  21161. + is better to use a bulk transfer
  21162. + (<= max_msg_size) */
  21163. + unsigned int max_outstanding_bulks;
  21164. + unsigned int max_services;
  21165. + short version; /* The version of VCHIQ */
  21166. + short version_min; /* The minimum compatible version of VCHIQ */
  21167. +} VCHIQ_CONFIG_T;
  21168. +
  21169. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  21170. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  21171. +
  21172. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  21173. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  21174. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  21175. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  21176. + const VCHIQ_SERVICE_PARAMS_T *params,
  21177. + VCHIQ_SERVICE_HANDLE_T *pservice);
  21178. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  21179. + const VCHIQ_SERVICE_PARAMS_T *params,
  21180. + VCHIQ_SERVICE_HANDLE_T *pservice);
  21181. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  21182. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  21183. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  21184. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  21185. + VCHIQ_SERVICE_HANDLE_T service);
  21186. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  21187. +
  21188. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  21189. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  21190. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  21191. + VCHIQ_HEADER_T *header);
  21192. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  21193. + const void *data, unsigned int size, void *userdata);
  21194. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  21195. + void *data, unsigned int size, void *userdata);
  21196. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  21197. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  21198. + const void *offset, unsigned int size, void *userdata);
  21199. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  21200. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  21201. + void *offset, unsigned int size, void *userdata);
  21202. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  21203. + const void *data, unsigned int size, void *userdata,
  21204. + VCHIQ_BULK_MODE_T mode);
  21205. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  21206. + void *data, unsigned int size, void *userdata,
  21207. + VCHIQ_BULK_MODE_T mode);
  21208. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  21209. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  21210. + void *userdata, VCHIQ_BULK_MODE_T mode);
  21211. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  21212. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  21213. + void *userdata, VCHIQ_BULK_MODE_T mode);
  21214. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  21215. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  21216. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  21217. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  21218. + int config_size, VCHIQ_CONFIG_T *pconfig);
  21219. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  21220. + VCHIQ_SERVICE_OPTION_T option, int value);
  21221. +
  21222. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  21223. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  21224. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  21225. +
  21226. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  21227. + void *ptr, size_t num_bytes);
  21228. +
  21229. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  21230. + short *peer_version);
  21231. +
  21232. +#endif /* VCHIQ_IF_H */
  21233. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  21234. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  21235. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-02-07 19:57:28.000000000 +0100
  21236. @@ -0,0 +1,129 @@
  21237. +/**
  21238. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21239. + *
  21240. + * Redistribution and use in source and binary forms, with or without
  21241. + * modification, are permitted provided that the following conditions
  21242. + * are met:
  21243. + * 1. Redistributions of source code must retain the above copyright
  21244. + * notice, this list of conditions, and the following disclaimer,
  21245. + * without modification.
  21246. + * 2. Redistributions in binary form must reproduce the above copyright
  21247. + * notice, this list of conditions and the following disclaimer in the
  21248. + * documentation and/or other materials provided with the distribution.
  21249. + * 3. The names of the above-listed copyright holders may not be used
  21250. + * to endorse or promote products derived from this software without
  21251. + * specific prior written permission.
  21252. + *
  21253. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21254. + * GNU General Public License ("GPL") version 2, as published by the Free
  21255. + * Software Foundation.
  21256. + *
  21257. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21258. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21259. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21260. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21261. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21262. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21263. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21264. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21265. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21266. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21267. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21268. + */
  21269. +
  21270. +#ifndef VCHIQ_IOCTLS_H
  21271. +#define VCHIQ_IOCTLS_H
  21272. +
  21273. +#include <linux/ioctl.h>
  21274. +#include "vchiq_if.h"
  21275. +
  21276. +#define VCHIQ_IOC_MAGIC 0xc4
  21277. +#define VCHIQ_INVALID_HANDLE (~0)
  21278. +
  21279. +typedef struct {
  21280. + VCHIQ_SERVICE_PARAMS_T params;
  21281. + int is_open;
  21282. + int is_vchi;
  21283. + unsigned int handle; /* OUT */
  21284. +} VCHIQ_CREATE_SERVICE_T;
  21285. +
  21286. +typedef struct {
  21287. + unsigned int handle;
  21288. + unsigned int count;
  21289. + const VCHIQ_ELEMENT_T *elements;
  21290. +} VCHIQ_QUEUE_MESSAGE_T;
  21291. +
  21292. +typedef struct {
  21293. + unsigned int handle;
  21294. + void *data;
  21295. + unsigned int size;
  21296. + void *userdata;
  21297. + VCHIQ_BULK_MODE_T mode;
  21298. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  21299. +
  21300. +typedef struct {
  21301. + VCHIQ_REASON_T reason;
  21302. + VCHIQ_HEADER_T *header;
  21303. + void *service_userdata;
  21304. + void *bulk_userdata;
  21305. +} VCHIQ_COMPLETION_DATA_T;
  21306. +
  21307. +typedef struct {
  21308. + unsigned int count;
  21309. + VCHIQ_COMPLETION_DATA_T *buf;
  21310. + unsigned int msgbufsize;
  21311. + unsigned int msgbufcount; /* IN/OUT */
  21312. + void **msgbufs;
  21313. +} VCHIQ_AWAIT_COMPLETION_T;
  21314. +
  21315. +typedef struct {
  21316. + unsigned int handle;
  21317. + int blocking;
  21318. + unsigned int bufsize;
  21319. + void *buf;
  21320. +} VCHIQ_DEQUEUE_MESSAGE_T;
  21321. +
  21322. +typedef struct {
  21323. + unsigned int config_size;
  21324. + VCHIQ_CONFIG_T *pconfig;
  21325. +} VCHIQ_GET_CONFIG_T;
  21326. +
  21327. +typedef struct {
  21328. + unsigned int handle;
  21329. + VCHIQ_SERVICE_OPTION_T option;
  21330. + int value;
  21331. +} VCHIQ_SET_SERVICE_OPTION_T;
  21332. +
  21333. +typedef struct {
  21334. + void *virt_addr;
  21335. + size_t num_bytes;
  21336. +} VCHIQ_DUMP_MEM_T;
  21337. +
  21338. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  21339. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  21340. +#define VCHIQ_IOC_CREATE_SERVICE \
  21341. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  21342. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  21343. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  21344. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  21345. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  21346. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  21347. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  21348. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  21349. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  21350. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  21351. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  21352. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  21353. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  21354. +#define VCHIQ_IOC_GET_CONFIG \
  21355. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  21356. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  21357. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  21358. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  21359. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  21360. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  21361. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  21362. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  21363. +#define VCHIQ_IOC_MAX 15
  21364. +
  21365. +#endif
  21366. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  21367. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  21368. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-02-07 19:57:28.000000000 +0100
  21369. @@ -0,0 +1,456 @@
  21370. +/**
  21371. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21372. + *
  21373. + * Redistribution and use in source and binary forms, with or without
  21374. + * modification, are permitted provided that the following conditions
  21375. + * are met:
  21376. + * 1. Redistributions of source code must retain the above copyright
  21377. + * notice, this list of conditions, and the following disclaimer,
  21378. + * without modification.
  21379. + * 2. Redistributions in binary form must reproduce the above copyright
  21380. + * notice, this list of conditions and the following disclaimer in the
  21381. + * documentation and/or other materials provided with the distribution.
  21382. + * 3. The names of the above-listed copyright holders may not be used
  21383. + * to endorse or promote products derived from this software without
  21384. + * specific prior written permission.
  21385. + *
  21386. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21387. + * GNU General Public License ("GPL") version 2, as published by the Free
  21388. + * Software Foundation.
  21389. + *
  21390. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21391. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21392. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21393. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21394. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21395. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21396. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21397. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21398. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21399. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21400. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21401. + */
  21402. +
  21403. +/* ---- Include Files ---------------------------------------------------- */
  21404. +
  21405. +#include <linux/kernel.h>
  21406. +#include <linux/module.h>
  21407. +#include <linux/mutex.h>
  21408. +
  21409. +#include "vchiq_core.h"
  21410. +#include "vchiq_arm.h"
  21411. +
  21412. +/* ---- Public Variables ------------------------------------------------- */
  21413. +
  21414. +/* ---- Private Constants and Types -------------------------------------- */
  21415. +
  21416. +struct bulk_waiter_node {
  21417. + struct bulk_waiter bulk_waiter;
  21418. + int pid;
  21419. + struct list_head list;
  21420. +};
  21421. +
  21422. +struct vchiq_instance_struct {
  21423. + VCHIQ_STATE_T *state;
  21424. +
  21425. + int connected;
  21426. +
  21427. + struct list_head bulk_waiter_list;
  21428. + struct mutex bulk_waiter_list_mutex;
  21429. +};
  21430. +
  21431. +static VCHIQ_STATUS_T
  21432. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  21433. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  21434. +
  21435. +/****************************************************************************
  21436. +*
  21437. +* vchiq_initialise
  21438. +*
  21439. +***************************************************************************/
  21440. +#define VCHIQ_INIT_RETRIES 10
  21441. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  21442. +{
  21443. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21444. + VCHIQ_STATE_T *state;
  21445. + VCHIQ_INSTANCE_T instance = NULL;
  21446. + int i;
  21447. +
  21448. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  21449. +
  21450. + /* VideoCore may not be ready due to boot up timing.
  21451. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  21452. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  21453. + state = vchiq_get_state();
  21454. + if (state)
  21455. + break;
  21456. + udelay(500);
  21457. + }
  21458. + if (i==VCHIQ_INIT_RETRIES) {
  21459. + vchiq_log_error(vchiq_core_log_level,
  21460. + "%s: videocore not initialized\n", __func__);
  21461. + goto failed;
  21462. + } else if (i>0) {
  21463. + vchiq_log_warning(vchiq_core_log_level,
  21464. + "%s: videocore initialized after %d retries\n", __func__, i);
  21465. + }
  21466. +
  21467. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  21468. + if (!instance) {
  21469. + vchiq_log_error(vchiq_core_log_level,
  21470. + "%s: error allocating vchiq instance\n", __func__);
  21471. + goto failed;
  21472. + }
  21473. +
  21474. + instance->connected = 0;
  21475. + instance->state = state;
  21476. + mutex_init(&instance->bulk_waiter_list_mutex);
  21477. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  21478. +
  21479. + *instanceOut = instance;
  21480. +
  21481. + status = VCHIQ_SUCCESS;
  21482. +
  21483. +failed:
  21484. + vchiq_log_trace(vchiq_core_log_level,
  21485. + "%s(%p): returning %d", __func__, instance, status);
  21486. +
  21487. + return status;
  21488. +}
  21489. +EXPORT_SYMBOL(vchiq_initialise);
  21490. +
  21491. +/****************************************************************************
  21492. +*
  21493. +* vchiq_shutdown
  21494. +*
  21495. +***************************************************************************/
  21496. +
  21497. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  21498. +{
  21499. + VCHIQ_STATUS_T status;
  21500. + VCHIQ_STATE_T *state = instance->state;
  21501. +
  21502. + vchiq_log_trace(vchiq_core_log_level,
  21503. + "%s(%p) called", __func__, instance);
  21504. +
  21505. + if (mutex_lock_interruptible(&state->mutex) != 0)
  21506. + return VCHIQ_RETRY;
  21507. +
  21508. + /* Remove all services */
  21509. + status = vchiq_shutdown_internal(state, instance);
  21510. +
  21511. + mutex_unlock(&state->mutex);
  21512. +
  21513. + vchiq_log_trace(vchiq_core_log_level,
  21514. + "%s(%p): returning %d", __func__, instance, status);
  21515. +
  21516. + if (status == VCHIQ_SUCCESS) {
  21517. + struct list_head *pos, *next;
  21518. + list_for_each_safe(pos, next,
  21519. + &instance->bulk_waiter_list) {
  21520. + struct bulk_waiter_node *waiter;
  21521. + waiter = list_entry(pos,
  21522. + struct bulk_waiter_node,
  21523. + list);
  21524. + list_del(pos);
  21525. + vchiq_log_info(vchiq_arm_log_level,
  21526. + "bulk_waiter - cleaned up %x "
  21527. + "for pid %d",
  21528. + (unsigned int)waiter, waiter->pid);
  21529. + kfree(waiter);
  21530. + }
  21531. + kfree(instance);
  21532. + }
  21533. +
  21534. + return status;
  21535. +}
  21536. +EXPORT_SYMBOL(vchiq_shutdown);
  21537. +
  21538. +/****************************************************************************
  21539. +*
  21540. +* vchiq_is_connected
  21541. +*
  21542. +***************************************************************************/
  21543. +
  21544. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  21545. +{
  21546. + return instance->connected;
  21547. +}
  21548. +
  21549. +/****************************************************************************
  21550. +*
  21551. +* vchiq_connect
  21552. +*
  21553. +***************************************************************************/
  21554. +
  21555. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  21556. +{
  21557. + VCHIQ_STATUS_T status;
  21558. + VCHIQ_STATE_T *state = instance->state;
  21559. +
  21560. + vchiq_log_trace(vchiq_core_log_level,
  21561. + "%s(%p) called", __func__, instance);
  21562. +
  21563. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  21564. + vchiq_log_trace(vchiq_core_log_level,
  21565. + "%s: call to mutex_lock failed", __func__);
  21566. + status = VCHIQ_RETRY;
  21567. + goto failed;
  21568. + }
  21569. + status = vchiq_connect_internal(state, instance);
  21570. +
  21571. + if (status == VCHIQ_SUCCESS)
  21572. + instance->connected = 1;
  21573. +
  21574. + mutex_unlock(&state->mutex);
  21575. +
  21576. +failed:
  21577. + vchiq_log_trace(vchiq_core_log_level,
  21578. + "%s(%p): returning %d", __func__, instance, status);
  21579. +
  21580. + return status;
  21581. +}
  21582. +EXPORT_SYMBOL(vchiq_connect);
  21583. +
  21584. +/****************************************************************************
  21585. +*
  21586. +* vchiq_add_service
  21587. +*
  21588. +***************************************************************************/
  21589. +
  21590. +VCHIQ_STATUS_T vchiq_add_service(
  21591. + VCHIQ_INSTANCE_T instance,
  21592. + const VCHIQ_SERVICE_PARAMS_T *params,
  21593. + VCHIQ_SERVICE_HANDLE_T *phandle)
  21594. +{
  21595. + VCHIQ_STATUS_T status;
  21596. + VCHIQ_STATE_T *state = instance->state;
  21597. + VCHIQ_SERVICE_T *service = NULL;
  21598. + int srvstate;
  21599. +
  21600. + vchiq_log_trace(vchiq_core_log_level,
  21601. + "%s(%p) called", __func__, instance);
  21602. +
  21603. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  21604. +
  21605. + srvstate = vchiq_is_connected(instance)
  21606. + ? VCHIQ_SRVSTATE_LISTENING
  21607. + : VCHIQ_SRVSTATE_HIDDEN;
  21608. +
  21609. + service = vchiq_add_service_internal(
  21610. + state,
  21611. + params,
  21612. + srvstate,
  21613. + instance,
  21614. + NULL);
  21615. +
  21616. + if (service) {
  21617. + *phandle = service->handle;
  21618. + status = VCHIQ_SUCCESS;
  21619. + } else
  21620. + status = VCHIQ_ERROR;
  21621. +
  21622. + vchiq_log_trace(vchiq_core_log_level,
  21623. + "%s(%p): returning %d", __func__, instance, status);
  21624. +
  21625. + return status;
  21626. +}
  21627. +EXPORT_SYMBOL(vchiq_add_service);
  21628. +
  21629. +/****************************************************************************
  21630. +*
  21631. +* vchiq_open_service
  21632. +*
  21633. +***************************************************************************/
  21634. +
  21635. +VCHIQ_STATUS_T vchiq_open_service(
  21636. + VCHIQ_INSTANCE_T instance,
  21637. + const VCHIQ_SERVICE_PARAMS_T *params,
  21638. + VCHIQ_SERVICE_HANDLE_T *phandle)
  21639. +{
  21640. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21641. + VCHIQ_STATE_T *state = instance->state;
  21642. + VCHIQ_SERVICE_T *service = NULL;
  21643. +
  21644. + vchiq_log_trace(vchiq_core_log_level,
  21645. + "%s(%p) called", __func__, instance);
  21646. +
  21647. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  21648. +
  21649. + if (!vchiq_is_connected(instance))
  21650. + goto failed;
  21651. +
  21652. + service = vchiq_add_service_internal(state,
  21653. + params,
  21654. + VCHIQ_SRVSTATE_OPENING,
  21655. + instance,
  21656. + NULL);
  21657. +
  21658. + if (service) {
  21659. + status = vchiq_open_service_internal(service, current->pid);
  21660. + if (status == VCHIQ_SUCCESS)
  21661. + *phandle = service->handle;
  21662. + else
  21663. + vchiq_remove_service(service->handle);
  21664. + }
  21665. +
  21666. +failed:
  21667. + vchiq_log_trace(vchiq_core_log_level,
  21668. + "%s(%p): returning %d", __func__, instance, status);
  21669. +
  21670. + return status;
  21671. +}
  21672. +EXPORT_SYMBOL(vchiq_open_service);
  21673. +
  21674. +VCHIQ_STATUS_T
  21675. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  21676. + const void *data, unsigned int size, void *userdata)
  21677. +{
  21678. + return vchiq_bulk_transfer(handle,
  21679. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  21680. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  21681. +}
  21682. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  21683. +
  21684. +VCHIQ_STATUS_T
  21685. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  21686. + unsigned int size, void *userdata)
  21687. +{
  21688. + return vchiq_bulk_transfer(handle,
  21689. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  21690. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  21691. +}
  21692. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  21693. +
  21694. +VCHIQ_STATUS_T
  21695. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  21696. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  21697. +{
  21698. + VCHIQ_STATUS_T status;
  21699. +
  21700. + switch (mode) {
  21701. + case VCHIQ_BULK_MODE_NOCALLBACK:
  21702. + case VCHIQ_BULK_MODE_CALLBACK:
  21703. + status = vchiq_bulk_transfer(handle,
  21704. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  21705. + mode, VCHIQ_BULK_TRANSMIT);
  21706. + break;
  21707. + case VCHIQ_BULK_MODE_BLOCKING:
  21708. + status = vchiq_blocking_bulk_transfer(handle,
  21709. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  21710. + break;
  21711. + default:
  21712. + return VCHIQ_ERROR;
  21713. + }
  21714. +
  21715. + return status;
  21716. +}
  21717. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  21718. +
  21719. +VCHIQ_STATUS_T
  21720. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  21721. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  21722. +{
  21723. + VCHIQ_STATUS_T status;
  21724. +
  21725. + switch (mode) {
  21726. + case VCHIQ_BULK_MODE_NOCALLBACK:
  21727. + case VCHIQ_BULK_MODE_CALLBACK:
  21728. + status = vchiq_bulk_transfer(handle,
  21729. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  21730. + mode, VCHIQ_BULK_RECEIVE);
  21731. + break;
  21732. + case VCHIQ_BULK_MODE_BLOCKING:
  21733. + status = vchiq_blocking_bulk_transfer(handle,
  21734. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  21735. + break;
  21736. + default:
  21737. + return VCHIQ_ERROR;
  21738. + }
  21739. +
  21740. + return status;
  21741. +}
  21742. +EXPORT_SYMBOL(vchiq_bulk_receive);
  21743. +
  21744. +static VCHIQ_STATUS_T
  21745. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  21746. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  21747. +{
  21748. + VCHIQ_INSTANCE_T instance;
  21749. + VCHIQ_SERVICE_T *service;
  21750. + VCHIQ_STATUS_T status;
  21751. + struct bulk_waiter_node *waiter = NULL;
  21752. + struct list_head *pos;
  21753. +
  21754. + service = find_service_by_handle(handle);
  21755. + if (!service)
  21756. + return VCHIQ_ERROR;
  21757. +
  21758. + instance = service->instance;
  21759. +
  21760. + unlock_service(service);
  21761. +
  21762. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21763. + list_for_each(pos, &instance->bulk_waiter_list) {
  21764. + if (list_entry(pos, struct bulk_waiter_node,
  21765. + list)->pid == current->pid) {
  21766. + waiter = list_entry(pos,
  21767. + struct bulk_waiter_node,
  21768. + list);
  21769. + list_del(pos);
  21770. + break;
  21771. + }
  21772. + }
  21773. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21774. +
  21775. + if (waiter) {
  21776. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  21777. + if (bulk) {
  21778. + /* This thread has an outstanding bulk transfer. */
  21779. + if ((bulk->data != data) ||
  21780. + (bulk->size != size)) {
  21781. + /* This is not a retry of the previous one.
  21782. + ** Cancel the signal when the transfer
  21783. + ** completes. */
  21784. + spin_lock(&bulk_waiter_spinlock);
  21785. + bulk->userdata = NULL;
  21786. + spin_unlock(&bulk_waiter_spinlock);
  21787. + }
  21788. + }
  21789. + }
  21790. +
  21791. + if (!waiter) {
  21792. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  21793. + if (!waiter) {
  21794. + vchiq_log_error(vchiq_core_log_level,
  21795. + "%s - out of memory", __func__);
  21796. + return VCHIQ_ERROR;
  21797. + }
  21798. + }
  21799. +
  21800. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  21801. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  21802. + dir);
  21803. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  21804. + !waiter->bulk_waiter.bulk) {
  21805. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  21806. + if (bulk) {
  21807. + /* Cancel the signal when the transfer
  21808. + ** completes. */
  21809. + spin_lock(&bulk_waiter_spinlock);
  21810. + bulk->userdata = NULL;
  21811. + spin_unlock(&bulk_waiter_spinlock);
  21812. + }
  21813. + kfree(waiter);
  21814. + } else {
  21815. + waiter->pid = current->pid;
  21816. + mutex_lock(&instance->bulk_waiter_list_mutex);
  21817. + list_add(&waiter->list, &instance->bulk_waiter_list);
  21818. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  21819. + vchiq_log_info(vchiq_arm_log_level,
  21820. + "saved bulk_waiter %x for pid %d",
  21821. + (unsigned int)waiter, current->pid);
  21822. + }
  21823. +
  21824. + return status;
  21825. +}
  21826. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  21827. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  21828. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-02-07 19:57:28.000000000 +0100
  21829. @@ -0,0 +1,71 @@
  21830. +/**
  21831. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21832. + *
  21833. + * Redistribution and use in source and binary forms, with or without
  21834. + * modification, are permitted provided that the following conditions
  21835. + * are met:
  21836. + * 1. Redistributions of source code must retain the above copyright
  21837. + * notice, this list of conditions, and the following disclaimer,
  21838. + * without modification.
  21839. + * 2. Redistributions in binary form must reproduce the above copyright
  21840. + * notice, this list of conditions and the following disclaimer in the
  21841. + * documentation and/or other materials provided with the distribution.
  21842. + * 3. The names of the above-listed copyright holders may not be used
  21843. + * to endorse or promote products derived from this software without
  21844. + * specific prior written permission.
  21845. + *
  21846. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21847. + * GNU General Public License ("GPL") version 2, as published by the Free
  21848. + * Software Foundation.
  21849. + *
  21850. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21851. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21852. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21853. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21854. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21855. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21856. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21857. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21858. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21859. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21860. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21861. + */
  21862. +
  21863. +#ifndef VCHIQ_MEMDRV_H
  21864. +#define VCHIQ_MEMDRV_H
  21865. +
  21866. +/* ---- Include Files ----------------------------------------------------- */
  21867. +
  21868. +#include <linux/kernel.h>
  21869. +#include "vchiq_if.h"
  21870. +
  21871. +/* ---- Constants and Types ---------------------------------------------- */
  21872. +
  21873. +typedef struct {
  21874. + void *armSharedMemVirt;
  21875. + dma_addr_t armSharedMemPhys;
  21876. + size_t armSharedMemSize;
  21877. +
  21878. + void *vcSharedMemVirt;
  21879. + dma_addr_t vcSharedMemPhys;
  21880. + size_t vcSharedMemSize;
  21881. +} VCHIQ_SHARED_MEM_INFO_T;
  21882. +
  21883. +/* ---- Variable Externs ------------------------------------------------- */
  21884. +
  21885. +/* ---- Function Prototypes ---------------------------------------------- */
  21886. +
  21887. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  21888. +
  21889. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  21890. +
  21891. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  21892. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  21893. +
  21894. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  21895. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  21896. +
  21897. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  21898. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  21899. +
  21900. +#endif
  21901. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  21902. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  21903. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-02-07 19:57:28.000000000 +0100
  21904. @@ -0,0 +1,58 @@
  21905. +/**
  21906. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21907. + *
  21908. + * Redistribution and use in source and binary forms, with or without
  21909. + * modification, are permitted provided that the following conditions
  21910. + * are met:
  21911. + * 1. Redistributions of source code must retain the above copyright
  21912. + * notice, this list of conditions, and the following disclaimer,
  21913. + * without modification.
  21914. + * 2. Redistributions in binary form must reproduce the above copyright
  21915. + * notice, this list of conditions and the following disclaimer in the
  21916. + * documentation and/or other materials provided with the distribution.
  21917. + * 3. The names of the above-listed copyright holders may not be used
  21918. + * to endorse or promote products derived from this software without
  21919. + * specific prior written permission.
  21920. + *
  21921. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21922. + * GNU General Public License ("GPL") version 2, as published by the Free
  21923. + * Software Foundation.
  21924. + *
  21925. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21926. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21927. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21928. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21929. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21930. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21931. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21932. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21933. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21934. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21935. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21936. + */
  21937. +
  21938. +#ifndef VCHIQ_PAGELIST_H
  21939. +#define VCHIQ_PAGELIST_H
  21940. +
  21941. +#ifndef PAGE_SIZE
  21942. +#define PAGE_SIZE 4096
  21943. +#endif
  21944. +#define CACHE_LINE_SIZE 32
  21945. +#define PAGELIST_WRITE 0
  21946. +#define PAGELIST_READ 1
  21947. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  21948. +
  21949. +typedef struct pagelist_struct {
  21950. + unsigned long length;
  21951. + unsigned short type;
  21952. + unsigned short offset;
  21953. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  21954. + pages at consecutive addresses. */
  21955. +} PAGELIST_T;
  21956. +
  21957. +typedef struct fragments_struct {
  21958. + char headbuf[CACHE_LINE_SIZE];
  21959. + char tailbuf[CACHE_LINE_SIZE];
  21960. +} FRAGMENTS_T;
  21961. +
  21962. +#endif /* VCHIQ_PAGELIST_H */
  21963. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  21964. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  21965. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-02-07 19:57:28.000000000 +0100
  21966. @@ -0,0 +1,253 @@
  21967. +/**
  21968. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  21969. + *
  21970. + * Redistribution and use in source and binary forms, with or without
  21971. + * modification, are permitted provided that the following conditions
  21972. + * are met:
  21973. + * 1. Redistributions of source code must retain the above copyright
  21974. + * notice, this list of conditions, and the following disclaimer,
  21975. + * without modification.
  21976. + * 2. Redistributions in binary form must reproduce the above copyright
  21977. + * notice, this list of conditions and the following disclaimer in the
  21978. + * documentation and/or other materials provided with the distribution.
  21979. + * 3. The names of the above-listed copyright holders may not be used
  21980. + * to endorse or promote products derived from this software without
  21981. + * specific prior written permission.
  21982. + *
  21983. + * ALTERNATIVELY, this software may be distributed under the terms of the
  21984. + * GNU General Public License ("GPL") version 2, as published by the Free
  21985. + * Software Foundation.
  21986. + *
  21987. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21988. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21989. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21990. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21991. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21992. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21993. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21994. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21995. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21996. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21997. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21998. + */
  21999. +
  22000. +
  22001. +#include <linux/proc_fs.h>
  22002. +#include "vchiq_core.h"
  22003. +#include "vchiq_arm.h"
  22004. +
  22005. +#if 1
  22006. +
  22007. +int vchiq_proc_init(void)
  22008. +{
  22009. + return 0;
  22010. +}
  22011. +
  22012. +void vchiq_proc_deinit(void)
  22013. +{
  22014. +}
  22015. +
  22016. +#else
  22017. +
  22018. +struct vchiq_proc_info {
  22019. + /* Global 'vc' proc entry used by all instances */
  22020. + struct proc_dir_entry *vc_cfg_dir;
  22021. +
  22022. + /* one entry per client process */
  22023. + struct proc_dir_entry *clients;
  22024. +
  22025. + /* log categories */
  22026. + struct proc_dir_entry *log_categories;
  22027. +};
  22028. +
  22029. +static struct vchiq_proc_info proc_info;
  22030. +
  22031. +struct proc_dir_entry *vchiq_proc_top(void)
  22032. +{
  22033. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  22034. + return proc_info.vc_cfg_dir;
  22035. +}
  22036. +
  22037. +/****************************************************************************
  22038. +*
  22039. +* log category entries
  22040. +*
  22041. +***************************************************************************/
  22042. +#define PROC_WRITE_BUF_SIZE 256
  22043. +
  22044. +#define VCHIQ_LOG_ERROR_STR "error"
  22045. +#define VCHIQ_LOG_WARNING_STR "warning"
  22046. +#define VCHIQ_LOG_INFO_STR "info"
  22047. +#define VCHIQ_LOG_TRACE_STR "trace"
  22048. +
  22049. +static int log_cfg_read(char *buffer,
  22050. + char **start,
  22051. + off_t off,
  22052. + int count,
  22053. + int *eof,
  22054. + void *data)
  22055. +{
  22056. + int len = 0;
  22057. + char *log_value = NULL;
  22058. +
  22059. + switch (*((int *)data)) {
  22060. + case VCHIQ_LOG_ERROR:
  22061. + log_value = VCHIQ_LOG_ERROR_STR;
  22062. + break;
  22063. + case VCHIQ_LOG_WARNING:
  22064. + log_value = VCHIQ_LOG_WARNING_STR;
  22065. + break;
  22066. + case VCHIQ_LOG_INFO:
  22067. + log_value = VCHIQ_LOG_INFO_STR;
  22068. + break;
  22069. + case VCHIQ_LOG_TRACE:
  22070. + log_value = VCHIQ_LOG_TRACE_STR;
  22071. + break;
  22072. + default:
  22073. + break;
  22074. + }
  22075. +
  22076. + len += sprintf(buffer + len,
  22077. + "%s\n",
  22078. + log_value ? log_value : "(null)");
  22079. +
  22080. + return len;
  22081. +}
  22082. +
  22083. +
  22084. +static int log_cfg_write(struct file *file,
  22085. + const char __user *buffer,
  22086. + unsigned long count,
  22087. + void *data)
  22088. +{
  22089. + int *log_module = data;
  22090. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  22091. +
  22092. + (void)file;
  22093. +
  22094. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  22095. + if (count >= PROC_WRITE_BUF_SIZE)
  22096. + count = PROC_WRITE_BUF_SIZE;
  22097. +
  22098. + if (copy_from_user(kbuf,
  22099. + buffer,
  22100. + count) != 0)
  22101. + return -EFAULT;
  22102. + kbuf[count - 1] = 0;
  22103. +
  22104. + if (strncmp("error", kbuf, strlen("error")) == 0)
  22105. + *log_module = VCHIQ_LOG_ERROR;
  22106. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  22107. + *log_module = VCHIQ_LOG_WARNING;
  22108. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  22109. + *log_module = VCHIQ_LOG_INFO;
  22110. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  22111. + *log_module = VCHIQ_LOG_TRACE;
  22112. + else
  22113. + *log_module = VCHIQ_LOG_DEFAULT;
  22114. +
  22115. + return count;
  22116. +}
  22117. +
  22118. +/* Log category proc entries */
  22119. +struct vchiq_proc_log_entry {
  22120. + const char *name;
  22121. + int *plevel;
  22122. + struct proc_dir_entry *dir;
  22123. +};
  22124. +
  22125. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  22126. + { "core", &vchiq_core_log_level },
  22127. + { "msg", &vchiq_core_msg_log_level },
  22128. + { "sync", &vchiq_sync_log_level },
  22129. + { "susp", &vchiq_susp_log_level },
  22130. + { "arm", &vchiq_arm_log_level },
  22131. +};
  22132. +static int n_log_entries =
  22133. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  22134. +
  22135. +/* create an entry under /proc/vc/log for each log category */
  22136. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  22137. +{
  22138. + struct proc_dir_entry *dir;
  22139. + size_t i;
  22140. + int ret = 0;
  22141. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  22142. + if (!dir)
  22143. + return -ENOMEM;
  22144. + proc_info.log_categories = dir;
  22145. +
  22146. + for (i = 0; i < n_log_entries; i++) {
  22147. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  22148. + 0644,
  22149. + proc_info.log_categories);
  22150. + if (!dir) {
  22151. + ret = -ENOMEM;
  22152. + break;
  22153. + }
  22154. +
  22155. + dir->read_proc = &log_cfg_read;
  22156. + dir->write_proc = &log_cfg_write;
  22157. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  22158. +
  22159. + vchiq_proc_log_entries[i].dir = dir;
  22160. + }
  22161. + return ret;
  22162. +}
  22163. +
  22164. +
  22165. +int vchiq_proc_init(void)
  22166. +{
  22167. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  22168. +
  22169. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  22170. + if (proc_info.vc_cfg_dir == NULL)
  22171. + goto fail;
  22172. +
  22173. + proc_info.clients = proc_mkdir("clients",
  22174. + proc_info.vc_cfg_dir);
  22175. + if (!proc_info.clients)
  22176. + goto fail;
  22177. +
  22178. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  22179. + goto fail;
  22180. +
  22181. + return 0;
  22182. +
  22183. +fail:
  22184. + vchiq_proc_deinit();
  22185. + vchiq_log_error(vchiq_arm_log_level,
  22186. + "%s: failed to create proc directory",
  22187. + __func__);
  22188. +
  22189. + return -ENOMEM;
  22190. +}
  22191. +
  22192. +/* remove all the proc entries */
  22193. +void vchiq_proc_deinit(void)
  22194. +{
  22195. + /* log category entries */
  22196. + if (proc_info.log_categories) {
  22197. + size_t i;
  22198. + for (i = 0; i < n_log_entries; i++)
  22199. + if (vchiq_proc_log_entries[i].dir)
  22200. + remove_proc_entry(
  22201. + vchiq_proc_log_entries[i].name,
  22202. + proc_info.log_categories);
  22203. +
  22204. + remove_proc_entry(proc_info.log_categories->name,
  22205. + proc_info.vc_cfg_dir);
  22206. + }
  22207. + if (proc_info.clients)
  22208. + remove_proc_entry(proc_info.clients->name,
  22209. + proc_info.vc_cfg_dir);
  22210. + if (proc_info.vc_cfg_dir)
  22211. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  22212. +}
  22213. +
  22214. +struct proc_dir_entry *vchiq_clients_top(void)
  22215. +{
  22216. + return proc_info.clients;
  22217. +}
  22218. +
  22219. +#endif
  22220. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  22221. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  22222. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-02-07 19:57:28.000000000 +0100
  22223. @@ -0,0 +1,815 @@
  22224. +/**
  22225. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22226. + *
  22227. + * Redistribution and use in source and binary forms, with or without
  22228. + * modification, are permitted provided that the following conditions
  22229. + * are met:
  22230. + * 1. Redistributions of source code must retain the above copyright
  22231. + * notice, this list of conditions, and the following disclaimer,
  22232. + * without modification.
  22233. + * 2. Redistributions in binary form must reproduce the above copyright
  22234. + * notice, this list of conditions and the following disclaimer in the
  22235. + * documentation and/or other materials provided with the distribution.
  22236. + * 3. The names of the above-listed copyright holders may not be used
  22237. + * to endorse or promote products derived from this software without
  22238. + * specific prior written permission.
  22239. + *
  22240. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22241. + * GNU General Public License ("GPL") version 2, as published by the Free
  22242. + * Software Foundation.
  22243. + *
  22244. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22245. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22246. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22247. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22248. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22249. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22250. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22251. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22252. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22253. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22254. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22255. + */
  22256. +#include <linux/module.h>
  22257. +#include <linux/types.h>
  22258. +
  22259. +#include "interface/vchi/vchi.h"
  22260. +#include "vchiq.h"
  22261. +#include "vchiq_core.h"
  22262. +
  22263. +#include "vchiq_util.h"
  22264. +
  22265. +#include <stddef.h>
  22266. +
  22267. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  22268. +
  22269. +typedef struct {
  22270. + VCHIQ_SERVICE_HANDLE_T handle;
  22271. +
  22272. + VCHIU_QUEUE_T queue;
  22273. +
  22274. + VCHI_CALLBACK_T callback;
  22275. + void *callback_param;
  22276. +} SHIM_SERVICE_T;
  22277. +
  22278. +/* ----------------------------------------------------------------------
  22279. + * return pointer to the mphi message driver function table
  22280. + * -------------------------------------------------------------------- */
  22281. +const VCHI_MESSAGE_DRIVER_T *
  22282. +vchi_mphi_message_driver_func_table(void)
  22283. +{
  22284. + return NULL;
  22285. +}
  22286. +
  22287. +/* ----------------------------------------------------------------------
  22288. + * return a pointer to the 'single' connection driver fops
  22289. + * -------------------------------------------------------------------- */
  22290. +const VCHI_CONNECTION_API_T *
  22291. +single_get_func_table(void)
  22292. +{
  22293. + return NULL;
  22294. +}
  22295. +
  22296. +VCHI_CONNECTION_T *vchi_create_connection(
  22297. + const VCHI_CONNECTION_API_T *function_table,
  22298. + const VCHI_MESSAGE_DRIVER_T *low_level)
  22299. +{
  22300. + (void)function_table;
  22301. + (void)low_level;
  22302. + return NULL;
  22303. +}
  22304. +
  22305. +/***********************************************************
  22306. + * Name: vchi_msg_peek
  22307. + *
  22308. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  22309. + * void **data,
  22310. + * uint32_t *msg_size,
  22311. +
  22312. +
  22313. + * VCHI_FLAGS_T flags
  22314. + *
  22315. + * Description: Routine to return a pointer to the current message (to allow in
  22316. + * place processing). The message can be removed using
  22317. + * vchi_msg_remove when you're finished
  22318. + *
  22319. + * Returns: int32_t - success == 0
  22320. + *
  22321. + ***********************************************************/
  22322. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  22323. + void **data,
  22324. + uint32_t *msg_size,
  22325. + VCHI_FLAGS_T flags)
  22326. +{
  22327. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22328. + VCHIQ_HEADER_T *header;
  22329. +
  22330. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  22331. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  22332. +
  22333. + if (flags == VCHI_FLAGS_NONE)
  22334. + if (vchiu_queue_is_empty(&service->queue))
  22335. + return -1;
  22336. +
  22337. + header = vchiu_queue_peek(&service->queue);
  22338. +
  22339. + *data = header->data;
  22340. + *msg_size = header->size;
  22341. +
  22342. + return 0;
  22343. +}
  22344. +EXPORT_SYMBOL(vchi_msg_peek);
  22345. +
  22346. +/***********************************************************
  22347. + * Name: vchi_msg_remove
  22348. + *
  22349. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  22350. + *
  22351. + * Description: Routine to remove a message (after it has been read with
  22352. + * vchi_msg_peek)
  22353. + *
  22354. + * Returns: int32_t - success == 0
  22355. + *
  22356. + ***********************************************************/
  22357. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  22358. +{
  22359. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22360. + VCHIQ_HEADER_T *header;
  22361. +
  22362. + header = vchiu_queue_pop(&service->queue);
  22363. +
  22364. + vchiq_release_message(service->handle, header);
  22365. +
  22366. + return 0;
  22367. +}
  22368. +EXPORT_SYMBOL(vchi_msg_remove);
  22369. +
  22370. +/***********************************************************
  22371. + * Name: vchi_msg_queue
  22372. + *
  22373. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  22374. + * const void *data,
  22375. + * uint32_t data_size,
  22376. + * VCHI_FLAGS_T flags,
  22377. + * void *msg_handle,
  22378. + *
  22379. + * Description: Thin wrapper to queue a message onto a connection
  22380. + *
  22381. + * Returns: int32_t - success == 0
  22382. + *
  22383. + ***********************************************************/
  22384. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  22385. + const void *data,
  22386. + uint32_t data_size,
  22387. + VCHI_FLAGS_T flags,
  22388. + void *msg_handle)
  22389. +{
  22390. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22391. + VCHIQ_ELEMENT_T element = {data, data_size};
  22392. + VCHIQ_STATUS_T status;
  22393. +
  22394. + (void)msg_handle;
  22395. +
  22396. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  22397. +
  22398. + status = vchiq_queue_message(service->handle, &element, 1);
  22399. +
  22400. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  22401. + ** implement a retry mechanism since this function is supposed
  22402. + ** to block until queued
  22403. + */
  22404. + while (status == VCHIQ_RETRY) {
  22405. + msleep(1);
  22406. + status = vchiq_queue_message(service->handle, &element, 1);
  22407. + }
  22408. +
  22409. + return vchiq_status_to_vchi(status);
  22410. +}
  22411. +EXPORT_SYMBOL(vchi_msg_queue);
  22412. +
  22413. +/***********************************************************
  22414. + * Name: vchi_bulk_queue_receive
  22415. + *
  22416. + * Arguments: VCHI_BULK_HANDLE_T handle,
  22417. + * void *data_dst,
  22418. + * const uint32_t data_size,
  22419. + * VCHI_FLAGS_T flags
  22420. + * void *bulk_handle
  22421. + *
  22422. + * Description: Routine to setup a rcv buffer
  22423. + *
  22424. + * Returns: int32_t - success == 0
  22425. + *
  22426. + ***********************************************************/
  22427. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  22428. + void *data_dst,
  22429. + uint32_t data_size,
  22430. + VCHI_FLAGS_T flags,
  22431. + void *bulk_handle)
  22432. +{
  22433. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22434. + VCHIQ_BULK_MODE_T mode;
  22435. + VCHIQ_STATUS_T status;
  22436. +
  22437. + switch ((int)flags) {
  22438. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  22439. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  22440. + WARN_ON(!service->callback);
  22441. + mode = VCHIQ_BULK_MODE_CALLBACK;
  22442. + break;
  22443. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  22444. + mode = VCHIQ_BULK_MODE_BLOCKING;
  22445. + break;
  22446. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  22447. + case VCHI_FLAGS_NONE:
  22448. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  22449. + break;
  22450. + default:
  22451. + WARN(1, "unsupported message\n");
  22452. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  22453. + }
  22454. +
  22455. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  22456. + bulk_handle, mode);
  22457. +
  22458. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  22459. + ** implement a retry mechanism since this function is supposed
  22460. + ** to block until queued
  22461. + */
  22462. + while (status == VCHIQ_RETRY) {
  22463. + msleep(1);
  22464. + status = vchiq_bulk_receive(service->handle, data_dst,
  22465. + data_size, bulk_handle, mode);
  22466. + }
  22467. +
  22468. + return vchiq_status_to_vchi(status);
  22469. +}
  22470. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  22471. +
  22472. +/***********************************************************
  22473. + * Name: vchi_bulk_queue_transmit
  22474. + *
  22475. + * Arguments: VCHI_BULK_HANDLE_T handle,
  22476. + * const void *data_src,
  22477. + * uint32_t data_size,
  22478. + * VCHI_FLAGS_T flags,
  22479. + * void *bulk_handle
  22480. + *
  22481. + * Description: Routine to transmit some data
  22482. + *
  22483. + * Returns: int32_t - success == 0
  22484. + *
  22485. + ***********************************************************/
  22486. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  22487. + const void *data_src,
  22488. + uint32_t data_size,
  22489. + VCHI_FLAGS_T flags,
  22490. + void *bulk_handle)
  22491. +{
  22492. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22493. + VCHIQ_BULK_MODE_T mode;
  22494. + VCHIQ_STATUS_T status;
  22495. +
  22496. + switch ((int)flags) {
  22497. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  22498. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  22499. + WARN_ON(!service->callback);
  22500. + mode = VCHIQ_BULK_MODE_CALLBACK;
  22501. + break;
  22502. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  22503. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  22504. + mode = VCHIQ_BULK_MODE_BLOCKING;
  22505. + break;
  22506. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  22507. + case VCHI_FLAGS_NONE:
  22508. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  22509. + break;
  22510. + default:
  22511. + WARN(1, "unsupported message\n");
  22512. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  22513. + }
  22514. +
  22515. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  22516. + bulk_handle, mode);
  22517. +
  22518. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  22519. + ** implement a retry mechanism since this function is supposed
  22520. + ** to block until queued
  22521. + */
  22522. + while (status == VCHIQ_RETRY) {
  22523. + msleep(1);
  22524. + status = vchiq_bulk_transmit(service->handle, data_src,
  22525. + data_size, bulk_handle, mode);
  22526. + }
  22527. +
  22528. + return vchiq_status_to_vchi(status);
  22529. +}
  22530. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  22531. +
  22532. +/***********************************************************
  22533. + * Name: vchi_msg_dequeue
  22534. + *
  22535. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  22536. + * void *data,
  22537. + * uint32_t max_data_size_to_read,
  22538. + * uint32_t *actual_msg_size
  22539. + * VCHI_FLAGS_T flags
  22540. + *
  22541. + * Description: Routine to dequeue a message into the supplied buffer
  22542. + *
  22543. + * Returns: int32_t - success == 0
  22544. + *
  22545. + ***********************************************************/
  22546. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  22547. + void *data,
  22548. + uint32_t max_data_size_to_read,
  22549. + uint32_t *actual_msg_size,
  22550. + VCHI_FLAGS_T flags)
  22551. +{
  22552. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22553. + VCHIQ_HEADER_T *header;
  22554. +
  22555. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  22556. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  22557. +
  22558. + if (flags == VCHI_FLAGS_NONE)
  22559. + if (vchiu_queue_is_empty(&service->queue))
  22560. + return -1;
  22561. +
  22562. + header = vchiu_queue_pop(&service->queue);
  22563. +
  22564. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  22565. + header->size : max_data_size_to_read);
  22566. +
  22567. + *actual_msg_size = header->size;
  22568. +
  22569. + vchiq_release_message(service->handle, header);
  22570. +
  22571. + return 0;
  22572. +}
  22573. +EXPORT_SYMBOL(vchi_msg_dequeue);
  22574. +
  22575. +/***********************************************************
  22576. + * Name: vchi_msg_queuev
  22577. + *
  22578. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  22579. + * VCHI_MSG_VECTOR_T *vector,
  22580. + * uint32_t count,
  22581. + * VCHI_FLAGS_T flags,
  22582. + * void *msg_handle
  22583. + *
  22584. + * Description: Thin wrapper to queue a message onto a connection
  22585. + *
  22586. + * Returns: int32_t - success == 0
  22587. + *
  22588. + ***********************************************************/
  22589. +
  22590. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  22591. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  22592. + offsetof(VCHIQ_ELEMENT_T, data));
  22593. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  22594. + offsetof(VCHIQ_ELEMENT_T, size));
  22595. +
  22596. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  22597. + VCHI_MSG_VECTOR_T *vector,
  22598. + uint32_t count,
  22599. + VCHI_FLAGS_T flags,
  22600. + void *msg_handle)
  22601. +{
  22602. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22603. +
  22604. + (void)msg_handle;
  22605. +
  22606. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  22607. +
  22608. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  22609. + (const VCHIQ_ELEMENT_T *)vector, count));
  22610. +}
  22611. +EXPORT_SYMBOL(vchi_msg_queuev);
  22612. +
  22613. +/***********************************************************
  22614. + * Name: vchi_held_msg_release
  22615. + *
  22616. + * Arguments: VCHI_HELD_MSG_T *message
  22617. + *
  22618. + * Description: Routine to release a held message (after it has been read with
  22619. + * vchi_msg_hold)
  22620. + *
  22621. + * Returns: int32_t - success == 0
  22622. + *
  22623. + ***********************************************************/
  22624. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  22625. +{
  22626. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  22627. + (VCHIQ_HEADER_T *)message->message);
  22628. +
  22629. + return 0;
  22630. +}
  22631. +
  22632. +/***********************************************************
  22633. + * Name: vchi_msg_hold
  22634. + *
  22635. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  22636. + * void **data,
  22637. + * uint32_t *msg_size,
  22638. + * VCHI_FLAGS_T flags,
  22639. + * VCHI_HELD_MSG_T *message_handle
  22640. + *
  22641. + * Description: Routine to return a pointer to the current message (to allow
  22642. + * in place processing). The message is dequeued - don't forget
  22643. + * to release the message using vchi_held_msg_release when you're
  22644. + * finished.
  22645. + *
  22646. + * Returns: int32_t - success == 0
  22647. + *
  22648. + ***********************************************************/
  22649. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  22650. + void **data,
  22651. + uint32_t *msg_size,
  22652. + VCHI_FLAGS_T flags,
  22653. + VCHI_HELD_MSG_T *message_handle)
  22654. +{
  22655. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22656. + VCHIQ_HEADER_T *header;
  22657. +
  22658. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  22659. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  22660. +
  22661. + if (flags == VCHI_FLAGS_NONE)
  22662. + if (vchiu_queue_is_empty(&service->queue))
  22663. + return -1;
  22664. +
  22665. + header = vchiu_queue_pop(&service->queue);
  22666. +
  22667. + *data = header->data;
  22668. + *msg_size = header->size;
  22669. +
  22670. + message_handle->service =
  22671. + (struct opaque_vchi_service_t *)service->handle;
  22672. + message_handle->message = header;
  22673. +
  22674. + return 0;
  22675. +}
  22676. +
  22677. +/***********************************************************
  22678. + * Name: vchi_initialise
  22679. + *
  22680. + * Arguments: VCHI_INSTANCE_T *instance_handle
  22681. + * VCHI_CONNECTION_T **connections
  22682. + * const uint32_t num_connections
  22683. + *
  22684. + * Description: Initialises the hardware but does not transmit anything
  22685. + * When run as a Host App this will be called twice hence the need
  22686. + * to malloc the state information
  22687. + *
  22688. + * Returns: 0 if successful, failure otherwise
  22689. + *
  22690. + ***********************************************************/
  22691. +
  22692. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  22693. +{
  22694. + VCHIQ_INSTANCE_T instance;
  22695. + VCHIQ_STATUS_T status;
  22696. +
  22697. + status = vchiq_initialise(&instance);
  22698. +
  22699. + *instance_handle = (VCHI_INSTANCE_T)instance;
  22700. +
  22701. + return vchiq_status_to_vchi(status);
  22702. +}
  22703. +EXPORT_SYMBOL(vchi_initialise);
  22704. +
  22705. +/***********************************************************
  22706. + * Name: vchi_connect
  22707. + *
  22708. + * Arguments: VCHI_CONNECTION_T **connections
  22709. + * const uint32_t num_connections
  22710. + * VCHI_INSTANCE_T instance_handle)
  22711. + *
  22712. + * Description: Starts the command service on each connection,
  22713. + * causing INIT messages to be pinged back and forth
  22714. + *
  22715. + * Returns: 0 if successful, failure otherwise
  22716. + *
  22717. + ***********************************************************/
  22718. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  22719. + const uint32_t num_connections,
  22720. + VCHI_INSTANCE_T instance_handle)
  22721. +{
  22722. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  22723. +
  22724. + (void)connections;
  22725. + (void)num_connections;
  22726. +
  22727. + return vchiq_connect(instance);
  22728. +}
  22729. +EXPORT_SYMBOL(vchi_connect);
  22730. +
  22731. +
  22732. +/***********************************************************
  22733. + * Name: vchi_disconnect
  22734. + *
  22735. + * Arguments: VCHI_INSTANCE_T instance_handle
  22736. + *
  22737. + * Description: Stops the command service on each connection,
  22738. + * causing DE-INIT messages to be pinged back and forth
  22739. + *
  22740. + * Returns: 0 if successful, failure otherwise
  22741. + *
  22742. + ***********************************************************/
  22743. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  22744. +{
  22745. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  22746. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  22747. +}
  22748. +EXPORT_SYMBOL(vchi_disconnect);
  22749. +
  22750. +
  22751. +/***********************************************************
  22752. + * Name: vchi_service_open
  22753. + * Name: vchi_service_create
  22754. + *
  22755. + * Arguments: VCHI_INSTANCE_T *instance_handle
  22756. + * SERVICE_CREATION_T *setup,
  22757. + * VCHI_SERVICE_HANDLE_T *handle
  22758. + *
  22759. + * Description: Routine to open a service
  22760. + *
  22761. + * Returns: int32_t - success == 0
  22762. + *
  22763. + ***********************************************************/
  22764. +
  22765. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  22766. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  22767. +{
  22768. + SHIM_SERVICE_T *service =
  22769. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  22770. +
  22771. + switch (reason) {
  22772. + case VCHIQ_MESSAGE_AVAILABLE:
  22773. + vchiu_queue_push(&service->queue, header);
  22774. +
  22775. + if (service->callback)
  22776. + service->callback(service->callback_param,
  22777. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  22778. + break;
  22779. + case VCHIQ_BULK_TRANSMIT_DONE:
  22780. + if (service->callback)
  22781. + service->callback(service->callback_param,
  22782. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  22783. + break;
  22784. + case VCHIQ_BULK_RECEIVE_DONE:
  22785. + if (service->callback)
  22786. + service->callback(service->callback_param,
  22787. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  22788. + break;
  22789. + case VCHIQ_SERVICE_CLOSED:
  22790. + if (service->callback)
  22791. + service->callback(service->callback_param,
  22792. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  22793. + break;
  22794. + case VCHIQ_SERVICE_OPENED:
  22795. + /* No equivalent VCHI reason */
  22796. + break;
  22797. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  22798. + if (service->callback)
  22799. + service->callback(service->callback_param,
  22800. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED, bulk_user);
  22801. + break;
  22802. + case VCHIQ_BULK_RECEIVE_ABORTED:
  22803. + if (service->callback)
  22804. + service->callback(service->callback_param,
  22805. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED, bulk_user);
  22806. + break;
  22807. + default:
  22808. + WARN(1, "not supported\n");
  22809. + break;
  22810. + }
  22811. +
  22812. + return VCHIQ_SUCCESS;
  22813. +}
  22814. +
  22815. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  22816. + SERVICE_CREATION_T *setup)
  22817. +{
  22818. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  22819. +
  22820. + (void)instance;
  22821. +
  22822. + if (service) {
  22823. + if (vchiu_queue_init(&service->queue, 64)) {
  22824. + service->callback = setup->callback;
  22825. + service->callback_param = setup->callback_param;
  22826. + } else {
  22827. + kfree(service);
  22828. + service = NULL;
  22829. + }
  22830. + }
  22831. +
  22832. + return service;
  22833. +}
  22834. +
  22835. +static void service_free(SHIM_SERVICE_T *service)
  22836. +{
  22837. + if (service) {
  22838. + vchiu_queue_delete(&service->queue);
  22839. + kfree(service);
  22840. + }
  22841. +}
  22842. +
  22843. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  22844. + SERVICE_CREATION_T *setup,
  22845. + VCHI_SERVICE_HANDLE_T *handle)
  22846. +{
  22847. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  22848. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  22849. + if (service) {
  22850. + VCHIQ_SERVICE_PARAMS_T params;
  22851. + VCHIQ_STATUS_T status;
  22852. +
  22853. + memset(&params, 0, sizeof(params));
  22854. + params.fourcc = setup->service_id;
  22855. + params.callback = shim_callback;
  22856. + params.userdata = service;
  22857. + params.version = setup->version.version;
  22858. + params.version_min = setup->version.version_min;
  22859. +
  22860. + status = vchiq_open_service(instance, &params,
  22861. + &service->handle);
  22862. + if (status != VCHIQ_SUCCESS) {
  22863. + service_free(service);
  22864. + service = NULL;
  22865. + }
  22866. + }
  22867. +
  22868. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  22869. +
  22870. + return (service != NULL) ? 0 : -1;
  22871. +}
  22872. +EXPORT_SYMBOL(vchi_service_open);
  22873. +
  22874. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  22875. + SERVICE_CREATION_T *setup,
  22876. + VCHI_SERVICE_HANDLE_T *handle)
  22877. +{
  22878. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  22879. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  22880. + if (service) {
  22881. + VCHIQ_SERVICE_PARAMS_T params;
  22882. + VCHIQ_STATUS_T status;
  22883. +
  22884. + memset(&params, 0, sizeof(params));
  22885. + params.fourcc = setup->service_id;
  22886. + params.callback = shim_callback;
  22887. + params.userdata = service;
  22888. + params.version = setup->version.version;
  22889. + params.version_min = setup->version.version_min;
  22890. + status = vchiq_add_service(instance, &params, &service->handle);
  22891. +
  22892. + if (status != VCHIQ_SUCCESS) {
  22893. + service_free(service);
  22894. + service = NULL;
  22895. + }
  22896. + }
  22897. +
  22898. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  22899. +
  22900. + return (service != NULL) ? 0 : -1;
  22901. +}
  22902. +EXPORT_SYMBOL(vchi_service_create);
  22903. +
  22904. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  22905. +{
  22906. + int32_t ret = -1;
  22907. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22908. + if (service) {
  22909. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  22910. + if (status == VCHIQ_SUCCESS) {
  22911. + service_free(service);
  22912. + service = NULL;
  22913. + }
  22914. +
  22915. + ret = vchiq_status_to_vchi(status);
  22916. + }
  22917. + return ret;
  22918. +}
  22919. +EXPORT_SYMBOL(vchi_service_close);
  22920. +
  22921. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  22922. +{
  22923. + int32_t ret = -1;
  22924. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22925. + if (service) {
  22926. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  22927. + if (status == VCHIQ_SUCCESS) {
  22928. + service_free(service);
  22929. + service = NULL;
  22930. + }
  22931. +
  22932. + ret = vchiq_status_to_vchi(status);
  22933. + }
  22934. + return ret;
  22935. +}
  22936. +EXPORT_SYMBOL(vchi_service_destroy);
  22937. +
  22938. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  22939. +{
  22940. + int32_t ret = -1;
  22941. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  22942. + if(service)
  22943. + {
  22944. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  22945. + ret = vchiq_status_to_vchi( status );
  22946. + }
  22947. + return ret;
  22948. +}
  22949. +EXPORT_SYMBOL(vchi_get_peer_version);
  22950. +
  22951. +/* ----------------------------------------------------------------------
  22952. + * read a uint32_t from buffer.
  22953. + * network format is defined to be little endian
  22954. + * -------------------------------------------------------------------- */
  22955. +uint32_t
  22956. +vchi_readbuf_uint32(const void *_ptr)
  22957. +{
  22958. + const unsigned char *ptr = _ptr;
  22959. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  22960. +}
  22961. +
  22962. +/* ----------------------------------------------------------------------
  22963. + * write a uint32_t to buffer.
  22964. + * network format is defined to be little endian
  22965. + * -------------------------------------------------------------------- */
  22966. +void
  22967. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  22968. +{
  22969. + unsigned char *ptr = _ptr;
  22970. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  22971. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  22972. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  22973. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  22974. +}
  22975. +
  22976. +/* ----------------------------------------------------------------------
  22977. + * read a uint16_t from buffer.
  22978. + * network format is defined to be little endian
  22979. + * -------------------------------------------------------------------- */
  22980. +uint16_t
  22981. +vchi_readbuf_uint16(const void *_ptr)
  22982. +{
  22983. + const unsigned char *ptr = _ptr;
  22984. + return ptr[0] | (ptr[1] << 8);
  22985. +}
  22986. +
  22987. +/* ----------------------------------------------------------------------
  22988. + * write a uint16_t into the buffer.
  22989. + * network format is defined to be little endian
  22990. + * -------------------------------------------------------------------- */
  22991. +void
  22992. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  22993. +{
  22994. + unsigned char *ptr = _ptr;
  22995. + ptr[0] = (value >> 0) & 0xFF;
  22996. + ptr[1] = (value >> 8) & 0xFF;
  22997. +}
  22998. +
  22999. +/***********************************************************
  23000. + * Name: vchi_service_use
  23001. + *
  23002. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  23003. + *
  23004. + * Description: Routine to increment refcount on a service
  23005. + *
  23006. + * Returns: void
  23007. + *
  23008. + ***********************************************************/
  23009. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  23010. +{
  23011. + int32_t ret = -1;
  23012. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  23013. + if (service)
  23014. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  23015. + return ret;
  23016. +}
  23017. +EXPORT_SYMBOL(vchi_service_use);
  23018. +
  23019. +/***********************************************************
  23020. + * Name: vchi_service_release
  23021. + *
  23022. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  23023. + *
  23024. + * Description: Routine to decrement refcount on a service
  23025. + *
  23026. + * Returns: void
  23027. + *
  23028. + ***********************************************************/
  23029. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  23030. +{
  23031. + int32_t ret = -1;
  23032. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  23033. + if (service)
  23034. + ret = vchiq_status_to_vchi(
  23035. + vchiq_release_service(service->handle));
  23036. + return ret;
  23037. +}
  23038. +EXPORT_SYMBOL(vchi_service_release);
  23039. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  23040. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  23041. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-02-07 19:57:28.000000000 +0100
  23042. @@ -0,0 +1,151 @@
  23043. +/**
  23044. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23045. + *
  23046. + * Redistribution and use in source and binary forms, with or without
  23047. + * modification, are permitted provided that the following conditions
  23048. + * are met:
  23049. + * 1. Redistributions of source code must retain the above copyright
  23050. + * notice, this list of conditions, and the following disclaimer,
  23051. + * without modification.
  23052. + * 2. Redistributions in binary form must reproduce the above copyright
  23053. + * notice, this list of conditions and the following disclaimer in the
  23054. + * documentation and/or other materials provided with the distribution.
  23055. + * 3. The names of the above-listed copyright holders may not be used
  23056. + * to endorse or promote products derived from this software without
  23057. + * specific prior written permission.
  23058. + *
  23059. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23060. + * GNU General Public License ("GPL") version 2, as published by the Free
  23061. + * Software Foundation.
  23062. + *
  23063. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23064. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23065. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23066. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23067. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23068. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23069. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23070. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23071. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23072. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23073. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23074. + */
  23075. +
  23076. +#include "vchiq_util.h"
  23077. +
  23078. +static inline int is_pow2(int i)
  23079. +{
  23080. + return i && !(i & (i - 1));
  23081. +}
  23082. +
  23083. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  23084. +{
  23085. + WARN_ON(!is_pow2(size));
  23086. +
  23087. + queue->size = size;
  23088. + queue->read = 0;
  23089. + queue->write = 0;
  23090. +
  23091. + sema_init(&queue->pop, 0);
  23092. + sema_init(&queue->push, 0);
  23093. +
  23094. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  23095. + if (queue->storage == NULL) {
  23096. + vchiu_queue_delete(queue);
  23097. + return 0;
  23098. + }
  23099. + return 1;
  23100. +}
  23101. +
  23102. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  23103. +{
  23104. + if (queue->storage != NULL)
  23105. + kfree(queue->storage);
  23106. +}
  23107. +
  23108. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  23109. +{
  23110. + return queue->read == queue->write;
  23111. +}
  23112. +
  23113. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  23114. +{
  23115. + return queue->write == queue->read + queue->size;
  23116. +}
  23117. +
  23118. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  23119. +{
  23120. + while (queue->write == queue->read + queue->size) {
  23121. + if (down_interruptible(&queue->pop) != 0) {
  23122. + flush_signals(current);
  23123. + }
  23124. + }
  23125. +
  23126. + /*
  23127. + * Write to queue->storage must be visible after read from
  23128. + * queue->read
  23129. + */
  23130. + smp_mb();
  23131. +
  23132. + queue->storage[queue->write & (queue->size - 1)] = header;
  23133. +
  23134. + /*
  23135. + * Write to queue->storage must be visible before write to
  23136. + * queue->write
  23137. + */
  23138. + smp_wmb();
  23139. +
  23140. + queue->write++;
  23141. +
  23142. + up(&queue->push);
  23143. +}
  23144. +
  23145. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  23146. +{
  23147. + while (queue->write == queue->read) {
  23148. + if (down_interruptible(&queue->push) != 0) {
  23149. + flush_signals(current);
  23150. + }
  23151. + }
  23152. +
  23153. + up(&queue->push); // We haven't removed anything from the queue.
  23154. +
  23155. + /*
  23156. + * Read from queue->storage must be visible after read from
  23157. + * queue->write
  23158. + */
  23159. + smp_rmb();
  23160. +
  23161. + return queue->storage[queue->read & (queue->size - 1)];
  23162. +}
  23163. +
  23164. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  23165. +{
  23166. + VCHIQ_HEADER_T *header;
  23167. +
  23168. + while (queue->write == queue->read) {
  23169. + if (down_interruptible(&queue->push) != 0) {
  23170. + flush_signals(current);
  23171. + }
  23172. + }
  23173. +
  23174. + /*
  23175. + * Read from queue->storage must be visible after read from
  23176. + * queue->write
  23177. + */
  23178. + smp_rmb();
  23179. +
  23180. + header = queue->storage[queue->read & (queue->size - 1)];
  23181. +
  23182. + /*
  23183. + * Read from queue->storage must be visible before write to
  23184. + * queue->read
  23185. + */
  23186. + smp_mb();
  23187. +
  23188. + queue->read++;
  23189. +
  23190. + up(&queue->pop);
  23191. +
  23192. + return header;
  23193. +}
  23194. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  23195. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  23196. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-02-07 19:57:28.000000000 +0100
  23197. @@ -0,0 +1,81 @@
  23198. +/**
  23199. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23200. + *
  23201. + * Redistribution and use in source and binary forms, with or without
  23202. + * modification, are permitted provided that the following conditions
  23203. + * are met:
  23204. + * 1. Redistributions of source code must retain the above copyright
  23205. + * notice, this list of conditions, and the following disclaimer,
  23206. + * without modification.
  23207. + * 2. Redistributions in binary form must reproduce the above copyright
  23208. + * notice, this list of conditions and the following disclaimer in the
  23209. + * documentation and/or other materials provided with the distribution.
  23210. + * 3. The names of the above-listed copyright holders may not be used
  23211. + * to endorse or promote products derived from this software without
  23212. + * specific prior written permission.
  23213. + *
  23214. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23215. + * GNU General Public License ("GPL") version 2, as published by the Free
  23216. + * Software Foundation.
  23217. + *
  23218. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23219. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23220. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23221. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23222. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23223. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23224. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23225. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23226. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23227. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23228. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23229. + */
  23230. +
  23231. +#ifndef VCHIQ_UTIL_H
  23232. +#define VCHIQ_UTIL_H
  23233. +
  23234. +#include <linux/types.h>
  23235. +#include <linux/semaphore.h>
  23236. +#include <linux/mutex.h>
  23237. +#include <linux/bitops.h>
  23238. +#include <linux/kthread.h>
  23239. +#include <linux/wait.h>
  23240. +#include <linux/vmalloc.h>
  23241. +#include <linux/jiffies.h>
  23242. +#include <linux/delay.h>
  23243. +#include <linux/string.h>
  23244. +#include <linux/types.h>
  23245. +#include <linux/interrupt.h>
  23246. +#include <linux/random.h>
  23247. +#include <linux/sched.h>
  23248. +#include <linux/ctype.h>
  23249. +#include <linux/uaccess.h>
  23250. +#include <linux/time.h> /* for time_t */
  23251. +#include <linux/slab.h>
  23252. +#include <linux/vmalloc.h>
  23253. +
  23254. +#include "vchiq_if.h"
  23255. +
  23256. +typedef struct {
  23257. + int size;
  23258. + int read;
  23259. + int write;
  23260. +
  23261. + struct semaphore pop;
  23262. + struct semaphore push;
  23263. +
  23264. + VCHIQ_HEADER_T **storage;
  23265. +} VCHIU_QUEUE_T;
  23266. +
  23267. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  23268. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  23269. +
  23270. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  23271. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  23272. +
  23273. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  23274. +
  23275. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  23276. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  23277. +
  23278. +#endif
  23279. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  23280. --- linux-3.11.10.orig/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  23281. +++ linux-3.11.10/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-02-07 19:57:28.000000000 +0100
  23282. @@ -0,0 +1,59 @@
  23283. +/**
  23284. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23285. + *
  23286. + * Redistribution and use in source and binary forms, with or without
  23287. + * modification, are permitted provided that the following conditions
  23288. + * are met:
  23289. + * 1. Redistributions of source code must retain the above copyright
  23290. + * notice, this list of conditions, and the following disclaimer,
  23291. + * without modification.
  23292. + * 2. Redistributions in binary form must reproduce the above copyright
  23293. + * notice, this list of conditions and the following disclaimer in the
  23294. + * documentation and/or other materials provided with the distribution.
  23295. + * 3. The names of the above-listed copyright holders may not be used
  23296. + * to endorse or promote products derived from this software without
  23297. + * specific prior written permission.
  23298. + *
  23299. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23300. + * GNU General Public License ("GPL") version 2, as published by the Free
  23301. + * Software Foundation.
  23302. + *
  23303. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23304. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23305. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23306. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23307. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23308. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23309. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23310. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23311. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23312. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23313. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23314. + */
  23315. +#include "vchiq_build_info.h"
  23316. +#include <linux/broadcom/vc_debug_sym.h>
  23317. +
  23318. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  23319. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  23320. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  23321. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  23322. +
  23323. +const char *vchiq_get_build_hostname( void )
  23324. +{
  23325. + return vchiq_build_hostname;
  23326. +}
  23327. +
  23328. +const char *vchiq_get_build_version( void )
  23329. +{
  23330. + return vchiq_build_version;
  23331. +}
  23332. +
  23333. +const char *vchiq_get_build_date( void )
  23334. +{
  23335. + return vchiq_build_date;
  23336. +}
  23337. +
  23338. +const char *vchiq_get_build_time( void )
  23339. +{
  23340. + return vchiq_build_time;
  23341. +}
  23342. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/Kconfig linux-3.11.10/drivers/misc/vc04_services/Kconfig
  23343. --- linux-3.11.10.orig/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  23344. +++ linux-3.11.10/drivers/misc/vc04_services/Kconfig 2014-02-07 19:57:28.000000000 +0100
  23345. @@ -0,0 +1,9 @@
  23346. +config BCM2708_VCHIQ
  23347. + tristate "Videocore VCHIQ"
  23348. + depends on MACH_BCM2708
  23349. + default y
  23350. + help
  23351. + Kernel to VideoCore communication interface for the
  23352. + BCM2708 family of products.
  23353. + Defaults to Y when the Broadcom Videocore services
  23354. + are included in the build, N otherwise.
  23355. diff -Nur linux-3.11.10.orig/drivers/misc/vc04_services/Makefile linux-3.11.10/drivers/misc/vc04_services/Makefile
  23356. --- linux-3.11.10.orig/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  23357. +++ linux-3.11.10/drivers/misc/vc04_services/Makefile 2014-02-07 19:57:28.000000000 +0100
  23358. @@ -0,0 +1,17 @@
  23359. +ifeq ($(CONFIG_MACH_BCM2708),y)
  23360. +
  23361. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  23362. +
  23363. +vchiq-objs := \
  23364. + interface/vchiq_arm/vchiq_core.o \
  23365. + interface/vchiq_arm/vchiq_arm.o \
  23366. + interface/vchiq_arm/vchiq_kern_lib.o \
  23367. + interface/vchiq_arm/vchiq_2835_arm.o \
  23368. + interface/vchiq_arm/vchiq_proc.o \
  23369. + interface/vchiq_arm/vchiq_shim.o \
  23370. + interface/vchiq_arm/vchiq_util.o \
  23371. + interface/vchiq_arm/vchiq_connected.o \
  23372. +
  23373. +EXTRA_CFLAGS += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  23374. +
  23375. +endif
  23376. diff -Nur linux-3.11.10.orig/drivers/mmc/card/block.c linux-3.11.10/drivers/mmc/card/block.c
  23377. --- linux-3.11.10.orig/drivers/mmc/card/block.c 2013-11-29 19:42:37.000000000 +0100
  23378. +++ linux-3.11.10/drivers/mmc/card/block.c 2014-02-07 19:57:28.000000000 +0100
  23379. @@ -1322,7 +1322,7 @@
  23380. brq->data.blocks = 1;
  23381. }
  23382. - if (brq->data.blocks > 1 || do_rel_wr) {
  23383. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  23384. /* SPI multiblock writes terminate using a special
  23385. * token, not a STOP_TRANSMISSION request.
  23386. */
  23387. diff -Nur linux-3.11.10.orig/drivers/mmc/core/sd.c linux-3.11.10/drivers/mmc/core/sd.c
  23388. --- linux-3.11.10.orig/drivers/mmc/core/sd.c 2013-11-29 19:42:37.000000000 +0100
  23389. +++ linux-3.11.10/drivers/mmc/core/sd.c 2014-02-07 19:57:28.000000000 +0100
  23390. @@ -13,6 +13,8 @@
  23391. #include <linux/err.h>
  23392. #include <linux/slab.h>
  23393. #include <linux/stat.h>
  23394. +#include <linux/jiffies.h>
  23395. +#include <linux/nmi.h>
  23396. #include <linux/mmc/host.h>
  23397. #include <linux/mmc/card.h>
  23398. @@ -58,6 +60,15 @@
  23399. __res & __mask; \
  23400. })
  23401. +// timeout for tries
  23402. +static const unsigned long retry_timeout_ms= 10*1000;
  23403. +
  23404. +// try at least 10 times, even if timeout is reached
  23405. +static const int retry_min_tries= 10;
  23406. +
  23407. +// delay between tries
  23408. +static const unsigned long retry_delay_ms= 10;
  23409. +
  23410. /*
  23411. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  23412. */
  23413. @@ -210,12 +221,62 @@
  23414. }
  23415. /*
  23416. - * Fetch and process SD Status register.
  23417. + * Fetch and process SD Configuration Register.
  23418. + */
  23419. +static int mmc_read_scr(struct mmc_card *card)
  23420. +{
  23421. + unsigned long timeout_at;
  23422. + int err, tries;
  23423. +
  23424. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  23425. + tries= 0;
  23426. +
  23427. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  23428. + {
  23429. + unsigned long delay_at;
  23430. + tries++;
  23431. +
  23432. + err = mmc_app_send_scr(card, card->raw_scr);
  23433. + if( !err )
  23434. + break; // success!!!
  23435. +
  23436. + touch_nmi_watchdog(); // we are still alive!
  23437. +
  23438. + // delay
  23439. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  23440. + while( time_before( jiffies, delay_at ) )
  23441. + {
  23442. + mdelay( 1 );
  23443. + touch_nmi_watchdog(); // we are still alive!
  23444. + }
  23445. + }
  23446. +
  23447. + if( err)
  23448. + {
  23449. + pr_err("%s: failed to read SD Configuration register (SCR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  23450. + return err;
  23451. + }
  23452. +
  23453. + if( tries > 1 )
  23454. + {
  23455. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  23456. + }
  23457. +
  23458. + err = mmc_decode_scr(card);
  23459. + if (err)
  23460. + return err;
  23461. +
  23462. + return err;
  23463. +}
  23464. +
  23465. +/*
  23466. + * Fetch and process SD Status Register.
  23467. */
  23468. static int mmc_read_ssr(struct mmc_card *card)
  23469. {
  23470. + unsigned long timeout_at;
  23471. unsigned int au, es, et, eo;
  23472. - int err, i;
  23473. + int err, i, tries;
  23474. u32 *ssr;
  23475. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  23476. @@ -228,14 +289,40 @@
  23477. if (!ssr)
  23478. return -ENOMEM;
  23479. - err = mmc_app_sd_status(card, ssr);
  23480. - if (err) {
  23481. - pr_warning("%s: problem reading SD Status "
  23482. - "register.\n", mmc_hostname(card->host));
  23483. - err = 0;
  23484. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  23485. + tries= 0;
  23486. +
  23487. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  23488. + {
  23489. + unsigned long delay_at;
  23490. + tries++;
  23491. +
  23492. + err= mmc_app_sd_status(card, ssr);
  23493. + if( !err )
  23494. + break; // sucess!!!
  23495. +
  23496. + touch_nmi_watchdog(); // we are still alive!
  23497. +
  23498. + // delay
  23499. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  23500. + while( time_before( jiffies, delay_at ) )
  23501. + {
  23502. + mdelay( 1 );
  23503. + touch_nmi_watchdog(); // we are still alive!
  23504. + }
  23505. + }
  23506. +
  23507. + if( err)
  23508. + {
  23509. + pr_err("%s: failed to read SD Status register (SSR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  23510. goto out;
  23511. }
  23512. + if( tries > 1 )
  23513. + {
  23514. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  23515. + }
  23516. +
  23517. for (i = 0; i < 16; i++)
  23518. ssr[i] = be32_to_cpu(ssr[i]);
  23519. @@ -813,14 +900,10 @@
  23520. if (!reinit) {
  23521. /*
  23522. - * Fetch SCR from card.
  23523. + * Fetch and decode SD Configuration register.
  23524. */
  23525. - err = mmc_app_send_scr(card, card->raw_scr);
  23526. - if (err)
  23527. - return err;
  23528. -
  23529. - err = mmc_decode_scr(card);
  23530. - if (err)
  23531. + err = mmc_read_scr(card);
  23532. + if( err )
  23533. return err;
  23534. /*
  23535. diff -Nur linux-3.11.10.orig/drivers/mmc/host/Kconfig linux-3.11.10/drivers/mmc/host/Kconfig
  23536. --- linux-3.11.10.orig/drivers/mmc/host/Kconfig 2013-11-29 19:42:37.000000000 +0100
  23537. +++ linux-3.11.10/drivers/mmc/host/Kconfig 2014-02-07 19:57:28.000000000 +0100
  23538. @@ -260,6 +260,27 @@
  23539. If you have a controller with this interface, say Y or M here.
  23540. +config MMC_SDHCI_BCM2708
  23541. + tristate "SDHCI support on BCM2708"
  23542. + depends on MMC_SDHCI && MACH_BCM2708
  23543. + select MMC_SDHCI_IO_ACCESSORS
  23544. + help
  23545. + This selects the Secure Digital Host Controller Interface (SDHCI)
  23546. + often referrered to as the eMMC block.
  23547. +
  23548. + If you have a controller with this interface, say Y or M here.
  23549. +
  23550. + If unsure, say N.
  23551. +
  23552. +config MMC_SDHCI_BCM2708_DMA
  23553. + bool "DMA support on BCM2708 Arasan controller"
  23554. + depends on MMC_SDHCI_BCM2708
  23555. + help
  23556. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  23557. + based chips.
  23558. +
  23559. + If unsure, say N.
  23560. +
  23561. config MMC_SDHCI_BCM2835
  23562. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  23563. depends on ARCH_BCM2835
  23564. diff -Nur linux-3.11.10.orig/drivers/mmc/host/Makefile linux-3.11.10/drivers/mmc/host/Makefile
  23565. --- linux-3.11.10.orig/drivers/mmc/host/Makefile 2013-11-29 19:42:37.000000000 +0100
  23566. +++ linux-3.11.10/drivers/mmc/host/Makefile 2014-02-07 19:57:28.000000000 +0100
  23567. @@ -15,6 +15,7 @@
  23568. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  23569. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  23570. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  23571. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  23572. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  23573. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  23574. obj-$(CONFIG_MMC_OMAP) += omap.o
  23575. diff -Nur linux-3.11.10.orig/drivers/mmc/host/sdhci-bcm2708.c linux-3.11.10/drivers/mmc/host/sdhci-bcm2708.c
  23576. --- linux-3.11.10.orig/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  23577. +++ linux-3.11.10/drivers/mmc/host/sdhci-bcm2708.c 2014-02-07 19:57:28.000000000 +0100
  23578. @@ -0,0 +1,1420 @@
  23579. +/*
  23580. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  23581. + * Copyright (c) 2010 Broadcom
  23582. + *
  23583. + * This program is free software; you can redistribute it and/or modify
  23584. + * it under the terms of the GNU General Public License version 2 as
  23585. + * published by the Free Software Foundation.
  23586. + *
  23587. + * This program is distributed in the hope that it will be useful,
  23588. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23589. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23590. + * GNU General Public License for more details.
  23591. + *
  23592. + * You should have received a copy of the GNU General Public License
  23593. + * along with this program; if not, write to the Free Software
  23594. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23595. + */
  23596. +
  23597. +/* Supports:
  23598. + * SDHCI platform device - Arasan SD controller in BCM2708
  23599. + *
  23600. + * Inspired by sdhci-pci.c, by Pierre Ossman
  23601. + */
  23602. +
  23603. +#include <linux/delay.h>
  23604. +#include <linux/highmem.h>
  23605. +#include <linux/platform_device.h>
  23606. +#include <linux/module.h>
  23607. +#include <linux/mmc/mmc.h>
  23608. +#include <linux/mmc/host.h>
  23609. +#include <linux/mmc/sd.h>
  23610. +
  23611. +#include <linux/io.h>
  23612. +#include <linux/dma-mapping.h>
  23613. +#include <mach/dma.h>
  23614. +
  23615. +#include "sdhci.h"
  23616. +
  23617. +/*****************************************************************************\
  23618. + * *
  23619. + * Configuration *
  23620. + * *
  23621. +\*****************************************************************************/
  23622. +
  23623. +#define DRIVER_NAME "bcm2708_sdhci"
  23624. +
  23625. +/* for the time being insist on DMA mode - PIO seems not to work */
  23626. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  23627. +#warning Non-DMA (PIO) version of this driver currently unavailable
  23628. +#endif
  23629. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  23630. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  23631. +
  23632. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  23633. +/* #define CHECK_DMA_USE */
  23634. +#endif
  23635. +//#define LOG_REGISTERS
  23636. +
  23637. +#define USE_SCHED_TIME
  23638. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  23639. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  23640. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  23641. +
  23642. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  23643. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  23644. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  23645. +
  23646. +/*! TODO: obtain these from the physical address */
  23647. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  23648. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  23649. +
  23650. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  23651. +
  23652. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  23653. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  23654. +
  23655. +#define REG_EXRDFIFO_EN 0x80
  23656. +#define REG_EXRDFIFO_CFG 0x84
  23657. +
  23658. +int cycle_delay=2;
  23659. +
  23660. +/*****************************************************************************\
  23661. + * *
  23662. + * Debug *
  23663. + * *
  23664. +\*****************************************************************************/
  23665. +
  23666. +
  23667. +
  23668. +#define DBG(f, x...) \
  23669. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  23670. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  23671. +
  23672. +
  23673. +/*****************************************************************************\
  23674. + * *
  23675. + * High Precision Time *
  23676. + * *
  23677. +\*****************************************************************************/
  23678. +
  23679. +#ifdef USE_SCHED_TIME
  23680. +
  23681. +#include <mach/frc.h>
  23682. +
  23683. +typedef unsigned long hptime_t;
  23684. +
  23685. +#define FMT_HPT "lu"
  23686. +
  23687. +static inline hptime_t hptime(void)
  23688. +{
  23689. + return frc_clock_ticks32();
  23690. +}
  23691. +
  23692. +#define HPTIME_CLK_NS 1000ul
  23693. +
  23694. +#else
  23695. +
  23696. +typedef unsigned long hptime_t;
  23697. +
  23698. +#define FMT_HPT "lu"
  23699. +
  23700. +static inline hptime_t hptime(void)
  23701. +{
  23702. + return jiffies;
  23703. +}
  23704. +
  23705. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  23706. +
  23707. +#endif
  23708. +
  23709. +static inline unsigned long int since_ns(hptime_t t)
  23710. +{
  23711. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  23712. +}
  23713. +
  23714. +static bool allow_highspeed = 1;
  23715. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  23716. +static bool sync_after_dma = 1;
  23717. +static bool missing_status = 1;
  23718. +static bool spurious_crc_acmd51 = 0;
  23719. +bool enable_llm = 1;
  23720. +bool extra_messages = 0;
  23721. +
  23722. +#if 0
  23723. +static void hptime_test(void)
  23724. +{
  23725. + hptime_t now;
  23726. + hptime_t later;
  23727. +
  23728. + now = hptime();
  23729. + msleep(10);
  23730. + later = hptime();
  23731. +
  23732. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  23733. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  23734. + later-now, now, later,
  23735. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  23736. +
  23737. + now = hptime();
  23738. + msleep(1000);
  23739. + later = hptime();
  23740. +
  23741. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  23742. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  23743. + later-now, now, later,
  23744. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  23745. +}
  23746. +#endif
  23747. +
  23748. +/*****************************************************************************\
  23749. + * *
  23750. + * SDHCI core callbacks *
  23751. + * *
  23752. +\*****************************************************************************/
  23753. +
  23754. +
  23755. +#ifdef CHECK_DMA_USE
  23756. +/*#define CHECK_DMA_REG_USE*/
  23757. +#endif
  23758. +
  23759. +#ifdef CHECK_DMA_REG_USE
  23760. +/* we don't expect anything to be using these registers during a
  23761. + DMA (except the IRQ status) - so check */
  23762. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  23763. +#else
  23764. +#define check_dma_reg_use(host, reg)
  23765. +#endif
  23766. +
  23767. +
  23768. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  23769. +{
  23770. + return readl(host->ioaddr + reg);
  23771. +}
  23772. +
  23773. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  23774. +{
  23775. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  23776. +
  23777. +#ifdef LOG_REGISTERS
  23778. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  23779. + mmc_hostname(host->mmc), reg, l);
  23780. +#endif
  23781. + check_dma_reg_use(host, reg);
  23782. +
  23783. + return l;
  23784. +}
  23785. +
  23786. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  23787. +{
  23788. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  23789. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  23790. +
  23791. +#ifdef LOG_REGISTERS
  23792. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  23793. + mmc_hostname(host->mmc), reg, w);
  23794. +#endif
  23795. + check_dma_reg_use(host, reg);
  23796. +
  23797. + return (u16)w;
  23798. +}
  23799. +
  23800. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  23801. +{
  23802. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  23803. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  23804. +
  23805. +#ifdef LOG_REGISTERS
  23806. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  23807. + mmc_hostname(host->mmc), reg, b);
  23808. +#endif
  23809. + check_dma_reg_use(host, reg);
  23810. +
  23811. + return (u8)b;
  23812. +}
  23813. +
  23814. +
  23815. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  23816. +{
  23817. + u32 ier;
  23818. +
  23819. +#if USE_SPACED_WRITES_2CLK
  23820. + static bool timeout_disabled = false;
  23821. + unsigned int ns_2clk = 0;
  23822. +
  23823. + /* The Arasan has a bugette whereby it may lose the content of
  23824. + * successive writes to registers that are within two SD-card clock
  23825. + * cycles of each other (a clock domain crossing problem).
  23826. + * It seems, however, that the data register does not have this problem.
  23827. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  23828. + * too)
  23829. + */
  23830. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  23831. + /* host->clock is the clock freq in Hz */
  23832. + static hptime_t last_write_hpt;
  23833. + hptime_t now = hptime();
  23834. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  23835. +
  23836. + if (now == last_write_hpt || now == last_write_hpt+1) {
  23837. + /* we can't guarantee any significant time has
  23838. + * passed - we'll have to wait anyway ! */
  23839. + ndelay(ns_2clk);
  23840. + } else
  23841. + {
  23842. + /* we must have waited at least this many ns: */
  23843. + unsigned int ns_wait = HPTIME_CLK_NS *
  23844. + (last_write_hpt - now - 1);
  23845. + if (ns_wait < ns_2clk)
  23846. + ndelay(ns_2clk - ns_wait);
  23847. + }
  23848. + last_write_hpt = now;
  23849. + }
  23850. +#if USE_SOFTWARE_TIMEOUTS
  23851. + /* The Arasan is clocked for timeouts using the SD clock which is too
  23852. + * fast for ERASE commands and causes issues. So we disable timeouts
  23853. + * for ERASE */
  23854. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  23855. + reg == (SDHCI_COMMAND & ~3)) {
  23856. + mod_timer(&host->timer,
  23857. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  23858. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  23859. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  23860. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  23861. + timeout_disabled = true;
  23862. + ndelay(ns_2clk);
  23863. + } else if (timeout_disabled) {
  23864. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  23865. + ier |= SDHCI_INT_DATA_TIMEOUT;
  23866. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  23867. + timeout_disabled = false;
  23868. + ndelay(ns_2clk);
  23869. + }
  23870. +#endif
  23871. + writel(val, host->ioaddr + reg);
  23872. +#else
  23873. + void __iomem * regaddr = host->ioaddr + reg;
  23874. +
  23875. + writel(val, regaddr);
  23876. +
  23877. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  23878. + {
  23879. + int timeout = 100000;
  23880. + while (val != readl(regaddr) && --timeout > 0)
  23881. + continue;
  23882. +
  23883. + if (timeout <= 0)
  23884. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  23885. + "always gives 0x%X\n",
  23886. + mmc_hostname(host->mmc),
  23887. + val, reg, readl(regaddr));
  23888. + BUG_ON(timeout <= 0);
  23889. + }
  23890. +#endif
  23891. +}
  23892. +
  23893. +
  23894. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  23895. +{
  23896. +#ifdef LOG_REGISTERS
  23897. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  23898. + mmc_hostname(host->mmc), reg, val);
  23899. +#endif
  23900. + check_dma_reg_use(host, reg);
  23901. +
  23902. + sdhci_bcm2708_raw_writel(host, val, reg);
  23903. +}
  23904. +
  23905. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  23906. +{
  23907. + static u32 shadow = 0;
  23908. +
  23909. + u32 p = reg == SDHCI_COMMAND ? shadow :
  23910. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  23911. + u32 s = reg << 3 & 0x18;
  23912. + u32 l = val << s;
  23913. + u32 m = 0xffff << s;
  23914. +
  23915. +#ifdef LOG_REGISTERS
  23916. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  23917. + mmc_hostname(host->mmc), reg, val);
  23918. +#endif
  23919. +
  23920. + if (reg == SDHCI_TRANSFER_MODE)
  23921. + shadow = (p & ~m) | l;
  23922. + else {
  23923. + check_dma_reg_use(host, reg);
  23924. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  23925. + }
  23926. +}
  23927. +
  23928. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  23929. +{
  23930. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  23931. + u32 s = reg << 3 & 0x18;
  23932. + u32 l = val << s;
  23933. + u32 m = 0xff << s;
  23934. +
  23935. +#ifdef LOG_REGISTERS
  23936. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  23937. + mmc_hostname(host->mmc), reg, val);
  23938. +#endif
  23939. +
  23940. + check_dma_reg_use(host, reg);
  23941. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  23942. +}
  23943. +
  23944. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  23945. +{
  23946. + return emmc_clock_freq;
  23947. +}
  23948. +
  23949. +/*****************************************************************************\
  23950. + * *
  23951. + * DMA Operation *
  23952. + * *
  23953. +\*****************************************************************************/
  23954. +
  23955. +struct sdhci_bcm2708_priv {
  23956. + int dma_chan;
  23957. + int dma_irq;
  23958. + void __iomem *dma_chan_base;
  23959. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  23960. + dma_addr_t cb_handle;
  23961. + /* tracking scatter gather progress */
  23962. + unsigned sg_ix; /* scatter gather list index */
  23963. + unsigned sg_done; /* bytes in current sg_ix done */
  23964. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  23965. + unsigned char dma_wanted; /* DMA transfer requested */
  23966. + unsigned char dma_waits; /* wait states in DMAs */
  23967. +#ifdef CHECK_DMA_USE
  23968. + unsigned char dmas_pending; /* no of unfinished DMAs */
  23969. + hptime_t when_started;
  23970. + hptime_t when_reset;
  23971. + hptime_t when_stopped;
  23972. +#endif
  23973. +#endif
  23974. + /* signalling the end of a transfer */
  23975. + void (*complete)(struct sdhci_host *);
  23976. +};
  23977. +
  23978. +#define SDHCI_HOST_PRIV(host) \
  23979. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  23980. +
  23981. +
  23982. +
  23983. +#ifdef CHECK_DMA_REG_USE
  23984. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  23985. +{
  23986. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  23987. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  23988. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  23989. + mmc_hostname(host->mmc), reg);
  23990. + }
  23991. +}
  23992. +#endif
  23993. +
  23994. +
  23995. +
  23996. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  23997. +
  23998. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  23999. +{
  24000. + u32 ier;
  24001. +
  24002. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  24003. + ier &= ~clear;
  24004. + ier |= set;
  24005. + /* change which requests generate IRQs - makes no difference to
  24006. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  24007. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  24008. +}
  24009. +
  24010. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  24011. +{
  24012. + sdhci_clear_set_irqgen(host, 0, irqs);
  24013. +}
  24014. +
  24015. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  24016. +{
  24017. + sdhci_clear_set_irqgen(host, irqs, 0);
  24018. +}
  24019. +
  24020. +
  24021. +
  24022. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  24023. + int ix,
  24024. + dma_addr_t dma_addr, unsigned len,
  24025. + int /*bool*/ is_last)
  24026. +{
  24027. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  24028. + unsigned char dmawaits = host->dma_waits;
  24029. +
  24030. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  24031. + BCM2708_DMA_WAITS(dmawaits) |
  24032. + BCM2708_DMA_S_DREQ |
  24033. + BCM2708_DMA_D_WIDTH |
  24034. + BCM2708_DMA_D_INC;
  24035. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  24036. + cb->dst = dma_addr;
  24037. + cb->length = len;
  24038. + cb->stride = 0;
  24039. +
  24040. + if (is_last) {
  24041. + cb->info |= BCM2708_DMA_INT_EN |
  24042. + BCM2708_DMA_WAIT_RESP;
  24043. + cb->next = 0;
  24044. + } else
  24045. + cb->next = host->cb_handle +
  24046. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  24047. +
  24048. + cb->pad[0] = 0;
  24049. + cb->pad[1] = 0;
  24050. +}
  24051. +
  24052. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  24053. + int ix,
  24054. + dma_addr_t dma_addr, unsigned len,
  24055. + int /*bool*/ is_last)
  24056. +{
  24057. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  24058. + unsigned char dmawaits = host->dma_waits;
  24059. +
  24060. + /* We can make arbitrarily large writes as long as we specify DREQ to
  24061. + pace the delivery of bytes to the Arasan hardware */
  24062. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  24063. + BCM2708_DMA_WAITS(dmawaits) |
  24064. + BCM2708_DMA_D_DREQ |
  24065. + BCM2708_DMA_S_WIDTH |
  24066. + BCM2708_DMA_S_INC;
  24067. + cb->src = dma_addr;
  24068. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  24069. + cb->length = len;
  24070. + cb->stride = 0;
  24071. +
  24072. + if (is_last) {
  24073. + cb->info |= BCM2708_DMA_INT_EN |
  24074. + BCM2708_DMA_WAIT_RESP;
  24075. + cb->next = 0;
  24076. + } else
  24077. + cb->next = host->cb_handle +
  24078. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  24079. +
  24080. + cb->pad[0] = 0;
  24081. + cb->pad[1] = 0;
  24082. +}
  24083. +
  24084. +
  24085. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  24086. +{
  24087. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24088. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  24089. +
  24090. + BUG_ON(host_priv->dma_wanted);
  24091. +#ifdef CHECK_DMA_USE
  24092. + if (host_priv->dma_wanted)
  24093. + printk(KERN_ERR "%s: DMA already in progress - "
  24094. + "now %"FMT_HPT", last started %lu "
  24095. + "reset %lu stopped %lu\n",
  24096. + mmc_hostname(host->mmc),
  24097. + hptime(), since_ns(host_priv->when_started),
  24098. + since_ns(host_priv->when_reset),
  24099. + since_ns(host_priv->when_stopped));
  24100. + else if (host_priv->dmas_pending > 0)
  24101. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  24102. + "already in progress - "
  24103. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  24104. + mmc_hostname(host->mmc),
  24105. + host_priv->dmas_pending,
  24106. + hptime(), since_ns(host_priv->when_started),
  24107. + since_ns(host_priv->when_reset),
  24108. + since_ns(host_priv->when_stopped));
  24109. + host_priv->dmas_pending += 1;
  24110. + host_priv->when_started = hptime();
  24111. +#endif
  24112. + host_priv->dma_wanted = 1;
  24113. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  24114. + host_priv->cb_handle);
  24115. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  24116. +}
  24117. +
  24118. +
  24119. +static void
  24120. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  24121. +{
  24122. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24123. +
  24124. + DBG("PDMA to read %d bytes\n", len);
  24125. + host_priv->sg_done += len;
  24126. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  24127. + schci_bcm2708_dma_go(host);
  24128. +}
  24129. +
  24130. +
  24131. +static void
  24132. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  24133. +{
  24134. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24135. +
  24136. + DBG("PDMA to write %d bytes\n", len);
  24137. + //BUG_ON(0 != (len & 0x1ff));
  24138. +
  24139. + host_priv->sg_done += len;
  24140. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  24141. + schci_bcm2708_dma_go(host);
  24142. +}
  24143. +
  24144. +/*! space is avaiable to receive into or data is available to write
  24145. + Platform DMA exported function
  24146. +*/
  24147. +void
  24148. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  24149. + void(*completion_callback)(struct sdhci_host *host))
  24150. +{
  24151. + struct mmc_data *data = host->data;
  24152. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24153. + int sg_ix;
  24154. + size_t bytes;
  24155. + dma_addr_t addr;
  24156. +
  24157. + BUG_ON(NULL == data);
  24158. + BUG_ON(0 == data->blksz);
  24159. +
  24160. + host_priv->complete = completion_callback;
  24161. +
  24162. + sg_ix = host_priv->sg_ix;
  24163. + BUG_ON(sg_ix >= data->sg_len);
  24164. +
  24165. + /* we can DMA blocks larger than blksz - it may hang the DMA
  24166. + channel but we are its only user */
  24167. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  24168. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  24169. +
  24170. + if (bytes > 0) {
  24171. + /* We're going to poll for read/write available state until
  24172. + we finish this DMA
  24173. + */
  24174. +
  24175. + if (data->flags & MMC_DATA_READ) {
  24176. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  24177. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  24178. + SDHCI_INT_SPACE_AVAIL);
  24179. + sdhci_platdma_read(host, addr, bytes);
  24180. + }
  24181. + } else {
  24182. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  24183. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  24184. + SDHCI_INT_SPACE_AVAIL);
  24185. + sdhci_platdma_write(host, addr, bytes);
  24186. + }
  24187. + }
  24188. + }
  24189. + /* else:
  24190. + we have run out of bytes that need transferring (e.g. we may be in
  24191. + the middle of the last DMA transfer), or
  24192. + it is also possible that we've been called when another IRQ is
  24193. + signalled, even though we've turned off signalling of our own IRQ */
  24194. +
  24195. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  24196. + /* don't let the main sdhci driver act on this .. we'll deal with it
  24197. + when we respond to the DMA - if one is currently in progress */
  24198. +}
  24199. +
  24200. +/* is it possible to DMA the given mmc_data structure?
  24201. + Platform DMA exported function
  24202. +*/
  24203. +int /*bool*/
  24204. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  24205. +{
  24206. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24207. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  24208. +
  24209. + if (!ok)
  24210. + DBG("Reverting to PIO - bad cache alignment\n");
  24211. +
  24212. + else {
  24213. + host_priv->sg_ix = 0; /* first SG index */
  24214. + host_priv->sg_done = 0; /* no bytes done */
  24215. + }
  24216. +
  24217. + return ok;
  24218. +}
  24219. +
  24220. +#include <mach/arm_control.h> //GRAYG
  24221. +/*! the current SD transacton has been abandonned
  24222. + We need to tidy up if we were in the middle of a DMA
  24223. + Platform DMA exported function
  24224. +*/
  24225. +void
  24226. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  24227. +{
  24228. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24229. +// unsigned long flags;
  24230. +
  24231. + BUG_ON(NULL == host);
  24232. +
  24233. +// spin_lock_irqsave(&host->lock, flags);
  24234. +
  24235. + if (host_priv->dma_wanted) {
  24236. + if (NULL == data) {
  24237. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  24238. + mmc_hostname(host->mmc));
  24239. + BUG_ON(NULL == data);
  24240. + } else {
  24241. + struct scatterlist *sg;
  24242. + int sg_len;
  24243. + int sg_todo;
  24244. + int rc;
  24245. + unsigned long cs;
  24246. +
  24247. + sg = data->sg;
  24248. + sg_len = data->sg_len;
  24249. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  24250. +
  24251. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  24252. +
  24253. + if (!(BCM2708_DMA_ACTIVE & cs))
  24254. + {
  24255. + if (extra_messages)
  24256. + printk(KERN_INFO "%s: missed completion of "
  24257. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  24258. + "ignoring it\n",
  24259. + mmc_hostname(host->mmc),
  24260. + host->last_cmdop,
  24261. + host_priv->sg_done, sg_todo,
  24262. + host_priv->sg_ix+1, sg_len);
  24263. + }
  24264. + else
  24265. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  24266. + "DMA before %d/%d [%d]/[%d] complete\n",
  24267. + mmc_hostname(host->mmc),
  24268. + host->last_cmdop,
  24269. + host_priv->sg_done, sg_todo,
  24270. + host_priv->sg_ix+1, sg_len);
  24271. +#ifdef CHECK_DMA_USE
  24272. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  24273. + "last reset %lu last stopped %lu\n",
  24274. + mmc_hostname(host->mmc),
  24275. + hptime(), since_ns(host_priv->when_started),
  24276. + since_ns(host_priv->when_reset),
  24277. + since_ns(host_priv->when_stopped));
  24278. + { unsigned long info, debug;
  24279. + void __iomem *base;
  24280. + unsigned long pend0, pend1, pend2;
  24281. +
  24282. + base = host_priv->dma_chan_base;
  24283. + cs = readl(base + BCM2708_DMA_CS);
  24284. + info = readl(base + BCM2708_DMA_INFO);
  24285. + debug = readl(base + BCM2708_DMA_DEBUG);
  24286. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  24287. + "DEBUG=%08lX\n",
  24288. + mmc_hostname(host->mmc),
  24289. + host_priv->dma_chan,
  24290. + cs, info, debug);
  24291. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  24292. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  24293. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  24294. +
  24295. + printk(KERN_INFO "%s: PEND0=%08lX "
  24296. + "PEND1=%08lX PEND2=%08lX\n",
  24297. + mmc_hostname(host->mmc),
  24298. + pend0, pend1, pend2);
  24299. +
  24300. + //gintsts = readl(__io_address(GINTSTS));
  24301. + //gintmsk = readl(__io_address(GINTMSK));
  24302. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  24303. + // "GINTMSK=%08lX\n",
  24304. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  24305. + }
  24306. +#endif
  24307. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  24308. + BUG_ON(rc != 0);
  24309. + }
  24310. + host_priv->dma_wanted = 0;
  24311. +#ifdef CHECK_DMA_USE
  24312. + host_priv->when_reset = hptime();
  24313. +#endif
  24314. + }
  24315. +
  24316. +// spin_unlock_irqrestore(&host->lock, flags);
  24317. +}
  24318. +
  24319. +
  24320. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  24321. + u32 dma_cs)
  24322. +{
  24323. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24324. + struct mmc_data *data;
  24325. + struct scatterlist *sg;
  24326. + int sg_len;
  24327. + int sg_ix;
  24328. + int sg_todo;
  24329. +// unsigned long flags;
  24330. +
  24331. + BUG_ON(NULL == host);
  24332. +
  24333. +// spin_lock_irqsave(&host->lock, flags);
  24334. + data = host->data;
  24335. +
  24336. +#ifdef CHECK_DMA_USE
  24337. + if (host_priv->dmas_pending <= 0)
  24338. + DBG("on completion no DMA in progress - "
  24339. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  24340. + hptime(), since_ns(host_priv->when_started),
  24341. + since_ns(host_priv->when_reset),
  24342. + since_ns(host_priv->when_stopped));
  24343. + else if (host_priv->dmas_pending > 1)
  24344. + DBG("still %d DMA in progress after completion - "
  24345. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  24346. + host_priv->dmas_pending - 1,
  24347. + hptime(), since_ns(host_priv->when_started),
  24348. + since_ns(host_priv->when_reset),
  24349. + since_ns(host_priv->when_stopped));
  24350. + BUG_ON(host_priv->dmas_pending <= 0);
  24351. + host_priv->dmas_pending -= 1;
  24352. + host_priv->when_stopped = hptime();
  24353. +#endif
  24354. + host_priv->dma_wanted = 0;
  24355. +
  24356. + if (NULL == data) {
  24357. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  24358. +// spin_unlock_irqrestore(&host->lock, flags);
  24359. + return;
  24360. + }
  24361. + sg = data->sg;
  24362. + sg_len = data->sg_len;
  24363. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  24364. +
  24365. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  24366. + host_priv->sg_done, sg_todo,
  24367. + host_priv->sg_ix+1, sg_len);
  24368. +
  24369. + BUG_ON(host_priv->sg_done > sg_todo);
  24370. +
  24371. + if (host_priv->sg_done >= sg_todo) {
  24372. + host_priv->sg_ix++;
  24373. + host_priv->sg_done = 0;
  24374. + }
  24375. +
  24376. + sg_ix = host_priv->sg_ix;
  24377. + if (sg_ix < sg_len) {
  24378. + u32 irq_mask;
  24379. + /* Set off next DMA if we've got the capacity */
  24380. +
  24381. + if (data->flags & MMC_DATA_READ)
  24382. + irq_mask = SDHCI_INT_DATA_AVAIL;
  24383. + else
  24384. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  24385. +
  24386. + /* We have to use the interrupt status register on the BCM2708
  24387. + rather than the SDHCI_PRESENT_STATE register because latency
  24388. + in the glue logic means that the information retrieved from
  24389. + the latter is not always up-to-date w.r.t the DMA engine -
  24390. + it may not indicate that a read or a write is ready yet */
  24391. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  24392. + irq_mask) {
  24393. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  24394. + host_priv->sg_done;
  24395. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  24396. + host_priv->sg_done;
  24397. +
  24398. + /* acknowledge interrupt */
  24399. + sdhci_bcm2708_raw_writel(host, irq_mask,
  24400. + SDHCI_INT_STATUS);
  24401. +
  24402. + BUG_ON(0 == bytes);
  24403. +
  24404. + if (data->flags & MMC_DATA_READ)
  24405. + sdhci_platdma_read(host, addr, bytes);
  24406. + else
  24407. + sdhci_platdma_write(host, addr, bytes);
  24408. + } else {
  24409. + DBG("PDMA - wait avail\n");
  24410. + /* may generate an IRQ if already present */
  24411. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  24412. + SDHCI_INT_SPACE_AVAIL);
  24413. + }
  24414. + } else {
  24415. + if (sync_after_dma) {
  24416. + /* On the Arasan controller the stop command (which will be
  24417. + scheduled after this completes) does not seem to work
  24418. + properly if we allow it to be issued when we are
  24419. + transferring data to/from the SD card.
  24420. + We get CRC and DEND errors unless we wait for
  24421. + the SD controller to finish reading/writing to the card. */
  24422. + u32 state_mask;
  24423. + int timeout=3*1000*1000;
  24424. +
  24425. + DBG("PDMA over - sync card\n");
  24426. + if (data->flags & MMC_DATA_READ)
  24427. + state_mask = SDHCI_DOING_READ;
  24428. + else
  24429. + state_mask = SDHCI_DOING_WRITE;
  24430. +
  24431. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  24432. + & state_mask) && --timeout > 0)
  24433. + {
  24434. + udelay(1);
  24435. + continue;
  24436. + }
  24437. + if (timeout <= 0)
  24438. + printk(KERN_ERR"%s: final %s to SD card still "
  24439. + "running\n",
  24440. + mmc_hostname(host->mmc),
  24441. + data->flags & MMC_DATA_READ? "read": "write");
  24442. + }
  24443. + if (host_priv->complete) {
  24444. + (*host_priv->complete)(host);
  24445. + DBG("PDMA %s complete\n",
  24446. + data->flags & MMC_DATA_READ?"read":"write");
  24447. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  24448. + SDHCI_INT_SPACE_AVAIL);
  24449. + }
  24450. + }
  24451. +// spin_unlock_irqrestore(&host->lock, flags);
  24452. +}
  24453. +
  24454. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  24455. +{
  24456. + irqreturn_t result = IRQ_NONE;
  24457. + struct sdhci_host *host = dev_id;
  24458. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24459. + u32 dma_cs; /* control and status register */
  24460. +
  24461. + BUG_ON(NULL == dev_id);
  24462. + BUG_ON(NULL == host_priv->dma_chan_base);
  24463. +
  24464. + sdhci_spin_lock(host);
  24465. +
  24466. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  24467. +
  24468. + if (dma_cs & BCM2708_DMA_ERR) {
  24469. + unsigned long debug;
  24470. + debug = readl(host_priv->dma_chan_base +
  24471. + BCM2708_DMA_DEBUG);
  24472. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  24473. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  24474. + (unsigned long)debug);
  24475. + /* reset error */
  24476. + writel(debug, host_priv->dma_chan_base +
  24477. + BCM2708_DMA_DEBUG);
  24478. + }
  24479. + if (dma_cs & BCM2708_DMA_INT) {
  24480. + /* acknowledge interrupt */
  24481. + writel(BCM2708_DMA_INT,
  24482. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  24483. +
  24484. + dsb(); /* ARM data synchronization (push) operation */
  24485. +
  24486. + if (!host_priv->dma_wanted) {
  24487. + /* ignore this interrupt - it was reset */
  24488. + if (extra_messages)
  24489. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  24490. + "results were reset\n",
  24491. + mmc_hostname(host->mmc), dma_cs);
  24492. +#ifdef CHECK_DMA_USE
  24493. + printk(KERN_INFO "%s: now %"FMT_HPT
  24494. + " started %lu reset %lu stopped %lu\n",
  24495. + mmc_hostname(host->mmc), hptime(),
  24496. + since_ns(host_priv->when_started),
  24497. + since_ns(host_priv->when_reset),
  24498. + since_ns(host_priv->when_stopped));
  24499. + host_priv->dmas_pending--;
  24500. +#endif
  24501. + } else
  24502. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  24503. +
  24504. + result = IRQ_HANDLED;
  24505. + }
  24506. + sdhci_spin_unlock(host);
  24507. +
  24508. + return result;
  24509. +}
  24510. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  24511. +
  24512. +
  24513. +/***************************************************************************** \
  24514. + * *
  24515. + * Device Attributes *
  24516. + * *
  24517. +\*****************************************************************************/
  24518. +
  24519. +
  24520. +/**
  24521. + * Show the DMA-using status
  24522. + */
  24523. +static ssize_t attr_dma_show(struct device *_dev,
  24524. + struct device_attribute *attr, char *buf)
  24525. +{
  24526. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  24527. +
  24528. + if (host) {
  24529. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  24530. + return sprintf(buf, "%d\n", use_dma);
  24531. + } else
  24532. + return -EINVAL;
  24533. +}
  24534. +
  24535. +/**
  24536. + * Set the DMA-using status
  24537. + */
  24538. +static ssize_t attr_dma_store(struct device *_dev,
  24539. + struct device_attribute *attr,
  24540. + const char *buf, size_t count)
  24541. +{
  24542. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  24543. +
  24544. + if (host) {
  24545. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24546. + int on = simple_strtol(buf, NULL, 0);
  24547. + if (on) {
  24548. + host->flags |= SDHCI_USE_PLATDMA;
  24549. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  24550. + printk(KERN_INFO "%s: DMA enabled\n",
  24551. + mmc_hostname(host->mmc));
  24552. + } else {
  24553. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  24554. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  24555. + printk(KERN_INFO "%s: DMA disabled\n",
  24556. + mmc_hostname(host->mmc));
  24557. + }
  24558. +#endif
  24559. + return count;
  24560. + } else
  24561. + return -EINVAL;
  24562. +}
  24563. +
  24564. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  24565. +
  24566. +
  24567. +/**
  24568. + * Show the DMA wait states used
  24569. + */
  24570. +static ssize_t attr_dmawait_show(struct device *_dev,
  24571. + struct device_attribute *attr, char *buf)
  24572. +{
  24573. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  24574. +
  24575. + if (host) {
  24576. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24577. + int dmawait = host_priv->dma_waits;
  24578. + return sprintf(buf, "%d\n", dmawait);
  24579. + } else
  24580. + return -EINVAL;
  24581. +}
  24582. +
  24583. +/**
  24584. + * Set the DMA wait state used
  24585. + */
  24586. +static ssize_t attr_dmawait_store(struct device *_dev,
  24587. + struct device_attribute *attr,
  24588. + const char *buf, size_t count)
  24589. +{
  24590. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  24591. +
  24592. + if (host) {
  24593. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24594. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24595. + int dma_waits = simple_strtol(buf, NULL, 0);
  24596. + if (dma_waits >= 0 && dma_waits < 32)
  24597. + host_priv->dma_waits = dma_waits;
  24598. + else
  24599. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  24600. + mmc_hostname(host->mmc), dma_waits);
  24601. +#endif
  24602. + return count;
  24603. + } else
  24604. + return -EINVAL;
  24605. +}
  24606. +
  24607. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  24608. + attr_dmawait_show, attr_dmawait_store);
  24609. +
  24610. +
  24611. +/**
  24612. + * Show the DMA-using status
  24613. + */
  24614. +static ssize_t attr_status_show(struct device *_dev,
  24615. + struct device_attribute *attr, char *buf)
  24616. +{
  24617. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  24618. +
  24619. + if (host) {
  24620. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24621. + return sprintf(buf,
  24622. + "present: yes\n"
  24623. + "power: %s\n"
  24624. + "clock: %u Hz\n"
  24625. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24626. + "dma: %s (%d waits)\n",
  24627. +#else
  24628. + "dma: unconfigured\n",
  24629. +#endif
  24630. + "always on",
  24631. + host->clock
  24632. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24633. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  24634. + , host_priv->dma_waits
  24635. +#endif
  24636. + );
  24637. + } else
  24638. + return -EINVAL;
  24639. +}
  24640. +
  24641. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  24642. +
  24643. +/***************************************************************************** \
  24644. + * *
  24645. + * Power Management *
  24646. + * *
  24647. +\*****************************************************************************/
  24648. +
  24649. +
  24650. +#ifdef CONFIG_PM
  24651. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  24652. +{
  24653. + struct sdhci_host *host = (struct sdhci_host *)
  24654. + platform_get_drvdata(dev);
  24655. + int ret = 0;
  24656. +
  24657. + if (host->mmc) {
  24658. + ret = mmc_suspend_host(host->mmc);
  24659. + }
  24660. +
  24661. + return ret;
  24662. +}
  24663. +
  24664. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  24665. +{
  24666. + struct sdhci_host *host = (struct sdhci_host *)
  24667. + platform_get_drvdata(dev);
  24668. + int ret = 0;
  24669. +
  24670. + if (host->mmc) {
  24671. + ret = mmc_resume_host(host->mmc);
  24672. + }
  24673. +
  24674. + return ret;
  24675. +}
  24676. +#endif
  24677. +
  24678. +
  24679. +/*****************************************************************************\
  24680. + * *
  24681. + * Device quirk functions. Implemented as local ops because the flags *
  24682. + * field is out of space with newer kernels. This implementation can be *
  24683. + * back ported to older kernels as well. *
  24684. +\****************************************************************************/
  24685. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  24686. +{
  24687. + return 1;
  24688. +}
  24689. +
  24690. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  24691. +{
  24692. + return 1;
  24693. +}
  24694. +
  24695. +static unsigned int sdhci_bcm2708_quirk_voltage_broken(struct sdhci_host *host)
  24696. +{
  24697. + return 1;
  24698. +}
  24699. +
  24700. +static unsigned int sdhci_bcm2708_uhs_broken(struct sdhci_host *host)
  24701. +{
  24702. + return 1;
  24703. +}
  24704. +
  24705. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  24706. +{
  24707. + return 1;
  24708. +}
  24709. +
  24710. +/***************************************************************************** \
  24711. + * *
  24712. + * Device ops *
  24713. + * *
  24714. +\*****************************************************************************/
  24715. +
  24716. +static struct sdhci_ops sdhci_bcm2708_ops = {
  24717. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  24718. + .read_l = sdhci_bcm2708_readl,
  24719. + .read_w = sdhci_bcm2708_readw,
  24720. + .read_b = sdhci_bcm2708_readb,
  24721. + .write_l = sdhci_bcm2708_writel,
  24722. + .write_w = sdhci_bcm2708_writew,
  24723. + .write_b = sdhci_bcm2708_writeb,
  24724. +#else
  24725. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  24726. +#endif
  24727. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  24728. +
  24729. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24730. + // Platform DMA operations
  24731. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  24732. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  24733. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  24734. +#endif
  24735. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  24736. + .voltage_broken = sdhci_bcm2708_quirk_voltage_broken,
  24737. + .uhs_broken = sdhci_bcm2708_uhs_broken,
  24738. +};
  24739. +
  24740. +/*****************************************************************************\
  24741. + * *
  24742. + * Device probing/removal *
  24743. + * *
  24744. +\*****************************************************************************/
  24745. +
  24746. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  24747. +{
  24748. + struct sdhci_host *host;
  24749. + struct resource *iomem;
  24750. + struct sdhci_bcm2708_priv *host_priv;
  24751. + int ret;
  24752. +
  24753. + BUG_ON(pdev == NULL);
  24754. +
  24755. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  24756. + if (!iomem) {
  24757. + ret = -ENOMEM;
  24758. + goto err;
  24759. + }
  24760. +
  24761. + if (resource_size(iomem) != 0x100)
  24762. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  24763. + "experience problems.\n");
  24764. +
  24765. + if (pdev->dev.parent)
  24766. + host = sdhci_alloc_host(pdev->dev.parent,
  24767. + sizeof(struct sdhci_bcm2708_priv));
  24768. + else
  24769. + host = sdhci_alloc_host(&pdev->dev,
  24770. + sizeof(struct sdhci_bcm2708_priv));
  24771. +
  24772. + if (IS_ERR(host)) {
  24773. + ret = PTR_ERR(host);
  24774. + goto err;
  24775. + }
  24776. + if (missing_status) {
  24777. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  24778. + }
  24779. +
  24780. + if( spurious_crc_acmd51 ) {
  24781. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  24782. + }
  24783. +
  24784. +
  24785. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  24786. +
  24787. + host->hw_name = "BCM2708_Arasan";
  24788. + host->ops = &sdhci_bcm2708_ops;
  24789. + host->irq = platform_get_irq(pdev, 0);
  24790. + host->second_irq = 0;
  24791. +
  24792. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  24793. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  24794. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  24795. + SDHCI_QUIRK_MISSING_CAPS |
  24796. + SDHCI_QUIRK_NO_HISPD_BIT |
  24797. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  24798. +
  24799. +
  24800. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24801. + host->flags = SDHCI_USE_PLATDMA;
  24802. +#endif
  24803. +
  24804. + if (!request_mem_region(iomem->start, resource_size(iomem),
  24805. + mmc_hostname(host->mmc))) {
  24806. + dev_err(&pdev->dev, "cannot request region\n");
  24807. + ret = -EBUSY;
  24808. + goto err_request;
  24809. + }
  24810. +
  24811. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  24812. + if (!host->ioaddr) {
  24813. + dev_err(&pdev->dev, "failed to remap registers\n");
  24814. + ret = -ENOMEM;
  24815. + goto err_remap;
  24816. + }
  24817. +
  24818. + host_priv = SDHCI_HOST_PRIV(host);
  24819. +
  24820. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24821. + host_priv->dma_wanted = 0;
  24822. +#ifdef CHECK_DMA_USE
  24823. + host_priv->dmas_pending = 0;
  24824. + host_priv->when_started = 0;
  24825. + host_priv->when_reset = 0;
  24826. + host_priv->when_stopped = 0;
  24827. +#endif
  24828. + host_priv->sg_ix = 0;
  24829. + host_priv->sg_done = 0;
  24830. + host_priv->complete = NULL;
  24831. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  24832. +
  24833. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  24834. + &host_priv->cb_handle,
  24835. + GFP_KERNEL);
  24836. + if (!host_priv->cb_base) {
  24837. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  24838. + ret = -ENOMEM;
  24839. + goto err_alloc_cb;
  24840. + }
  24841. +
  24842. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  24843. + &host_priv->dma_chan_base,
  24844. + &host_priv->dma_irq);
  24845. + if (ret < 0) {
  24846. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  24847. + goto err_add_dma;
  24848. + }
  24849. + host_priv->dma_chan = ret;
  24850. +
  24851. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,0,//IRQF_SHARED,
  24852. + DRIVER_NAME " (dma)", host);
  24853. + if (ret) {
  24854. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  24855. + goto err_add_dma_irq;
  24856. + }
  24857. + host->second_irq = host_priv->dma_irq;
  24858. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  24859. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  24860. + host_priv->dma_chan, host_priv->dma_chan_base,
  24861. + host_priv->dma_irq);
  24862. +
  24863. + if (allow_highspeed)
  24864. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  24865. +
  24866. + /* single block writes cause data loss with some SD cards! */
  24867. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  24868. +#endif
  24869. +
  24870. + ret = sdhci_add_host(host);
  24871. + if (ret)
  24872. + goto err_add_host;
  24873. +
  24874. + platform_set_drvdata(pdev, host);
  24875. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  24876. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  24877. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  24878. +
  24879. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24880. + /* enable extension fifo for paced DMA transfers */
  24881. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  24882. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  24883. +#endif
  24884. +
  24885. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  24886. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  24887. + host_priv->dma_chan, host_priv->dma_irq);
  24888. +
  24889. + return 0;
  24890. +
  24891. +err_add_host:
  24892. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24893. + free_irq(host_priv->dma_irq, host);
  24894. +err_add_dma_irq:
  24895. + bcm_dma_chan_free(host_priv->dma_chan);
  24896. +err_add_dma:
  24897. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  24898. + host_priv->cb_handle);
  24899. +err_alloc_cb:
  24900. +#endif
  24901. + iounmap(host->ioaddr);
  24902. +err_remap:
  24903. + release_mem_region(iomem->start, resource_size(iomem));
  24904. +err_request:
  24905. + sdhci_free_host(host);
  24906. +err:
  24907. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  24908. + return ret;
  24909. +}
  24910. +
  24911. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  24912. +{
  24913. + struct sdhci_host *host = platform_get_drvdata(pdev);
  24914. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  24915. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  24916. + int dead;
  24917. + u32 scratch;
  24918. +
  24919. + dead = 0;
  24920. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  24921. + if (scratch == (u32)-1)
  24922. + dead = 1;
  24923. +
  24924. + device_remove_file(&pdev->dev, &dev_attr_status);
  24925. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  24926. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  24927. +
  24928. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  24929. + free_irq(host_priv->dma_irq, host);
  24930. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  24931. + host_priv->cb_handle);
  24932. +#endif
  24933. + sdhci_remove_host(host, dead);
  24934. + iounmap(host->ioaddr);
  24935. + release_mem_region(iomem->start, resource_size(iomem));
  24936. + sdhci_free_host(host);
  24937. + platform_set_drvdata(pdev, NULL);
  24938. +
  24939. + return 0;
  24940. +}
  24941. +
  24942. +static struct platform_driver sdhci_bcm2708_driver = {
  24943. + .driver = {
  24944. + .name = DRIVER_NAME,
  24945. + .owner = THIS_MODULE,
  24946. + },
  24947. + .probe = sdhci_bcm2708_probe,
  24948. + .remove = sdhci_bcm2708_remove,
  24949. +
  24950. +#ifdef CONFIG_PM
  24951. + .suspend = sdhci_bcm2708_suspend,
  24952. + .resume = sdhci_bcm2708_resume,
  24953. +#endif
  24954. +
  24955. +};
  24956. +
  24957. +/*****************************************************************************\
  24958. + * *
  24959. + * Driver init/exit *
  24960. + * *
  24961. +\*****************************************************************************/
  24962. +
  24963. +static int __init sdhci_drv_init(void)
  24964. +{
  24965. + return platform_driver_register(&sdhci_bcm2708_driver);
  24966. +}
  24967. +
  24968. +static void __exit sdhci_drv_exit(void)
  24969. +{
  24970. + platform_driver_unregister(&sdhci_bcm2708_driver);
  24971. +}
  24972. +
  24973. +module_init(sdhci_drv_init);
  24974. +module_exit(sdhci_drv_exit);
  24975. +
  24976. +module_param(allow_highspeed, bool, 0444);
  24977. +module_param(emmc_clock_freq, int, 0444);
  24978. +module_param(sync_after_dma, bool, 0444);
  24979. +module_param(missing_status, bool, 0444);
  24980. +module_param(spurious_crc_acmd51, bool, 0444);
  24981. +module_param(enable_llm, bool, 0444);
  24982. +module_param(cycle_delay, int, 0444);
  24983. +module_param(extra_messages, bool, 0444);
  24984. +
  24985. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  24986. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  24987. +MODULE_LICENSE("GPL v2");
  24988. +MODULE_ALIAS("platform:"DRIVER_NAME);
  24989. +
  24990. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  24991. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  24992. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  24993. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  24994. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  24995. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  24996. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  24997. +
  24998. +
  24999. diff -Nur linux-3.11.10.orig/drivers/mmc/host/sdhci.c linux-3.11.10/drivers/mmc/host/sdhci.c
  25000. --- linux-3.11.10.orig/drivers/mmc/host/sdhci.c 2013-11-29 19:42:37.000000000 +0100
  25001. +++ linux-3.11.10/drivers/mmc/host/sdhci.c 2014-02-07 19:57:28.000000000 +0100
  25002. @@ -28,6 +28,7 @@
  25003. #include <linux/mmc/mmc.h>
  25004. #include <linux/mmc/host.h>
  25005. #include <linux/mmc/card.h>
  25006. +#include <linux/mmc/sd.h>
  25007. #include <linux/mmc/slot-gpio.h>
  25008. #include "sdhci.h"
  25009. @@ -131,6 +132,91 @@
  25010. * Low level functions *
  25011. * *
  25012. \*****************************************************************************/
  25013. +extern bool enable_llm;
  25014. +static int sdhci_locked=0;
  25015. +void sdhci_spin_lock(struct sdhci_host *host)
  25016. +{
  25017. + spin_lock(&host->lock);
  25018. +#ifdef CONFIG_PREEMPT
  25019. + if(enable_llm)
  25020. + {
  25021. + disable_irq_nosync(host->irq);
  25022. + if(host->second_irq)
  25023. + disable_irq_nosync(host->second_irq);
  25024. + local_irq_enable();
  25025. + }
  25026. +#endif
  25027. +}
  25028. +
  25029. +void sdhci_spin_unlock(struct sdhci_host *host)
  25030. +{
  25031. +#ifdef CONFIG_PREEMPT
  25032. + if(enable_llm)
  25033. + {
  25034. + local_irq_disable();
  25035. + if(host->second_irq)
  25036. + enable_irq(host->second_irq);
  25037. + enable_irq(host->irq);
  25038. + }
  25039. +#endif
  25040. + spin_unlock(&host->lock);
  25041. +}
  25042. +
  25043. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  25044. +{
  25045. +#ifdef CONFIG_PREEMPT
  25046. + if(enable_llm)
  25047. + {
  25048. + while(sdhci_locked)
  25049. + {
  25050. + preempt_schedule();
  25051. + }
  25052. + spin_lock_irqsave(&host->lock,*flags);
  25053. + disable_irq(host->irq);
  25054. + if(host->second_irq)
  25055. + disable_irq(host->second_irq);
  25056. + local_irq_enable();
  25057. + }
  25058. + else
  25059. +#endif
  25060. + spin_lock_irqsave(&host->lock,*flags);
  25061. +}
  25062. +
  25063. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  25064. +{
  25065. +#ifdef CONFIG_PREEMPT
  25066. + if(enable_llm)
  25067. + {
  25068. + local_irq_disable();
  25069. + if(host->second_irq)
  25070. + enable_irq(host->second_irq);
  25071. + enable_irq(host->irq);
  25072. + }
  25073. +#endif
  25074. + spin_unlock_irqrestore(&host->lock,flags);
  25075. +}
  25076. +
  25077. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  25078. +{
  25079. +#ifdef CONFIG_PREEMPT
  25080. + if(enable_llm)
  25081. + {
  25082. + sdhci_locked = 1;
  25083. + preempt_enable();
  25084. + }
  25085. +#endif
  25086. +}
  25087. +
  25088. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  25089. +{
  25090. +#ifdef CONFIG_PREEMPT
  25091. + if(enable_llm)
  25092. + {
  25093. + preempt_disable();
  25094. + sdhci_locked = 0;
  25095. + }
  25096. +#endif
  25097. +}
  25098. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  25099. {
  25100. @@ -300,7 +386,7 @@
  25101. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  25102. unsigned long flags;
  25103. - spin_lock_irqsave(&host->lock, flags);
  25104. + sdhci_spin_lock_irqsave(host, &flags);
  25105. if (host->runtime_suspended)
  25106. goto out;
  25107. @@ -310,7 +396,7 @@
  25108. else
  25109. sdhci_activate_led(host);
  25110. out:
  25111. - spin_unlock_irqrestore(&host->lock, flags);
  25112. + sdhci_spin_unlock_irqrestore(host, flags);
  25113. }
  25114. #endif
  25115. @@ -327,7 +413,7 @@
  25116. u32 uninitialized_var(scratch);
  25117. u8 *buf;
  25118. - DBG("PIO reading\n");
  25119. + DBG("PIO reading %db\n", host->data->blksz);
  25120. blksize = host->data->blksz;
  25121. chunk = 0;
  25122. @@ -372,7 +458,7 @@
  25123. u32 scratch;
  25124. u8 *buf;
  25125. - DBG("PIO writing\n");
  25126. + DBG("PIO writing %db\n", host->data->blksz);
  25127. blksize = host->data->blksz;
  25128. chunk = 0;
  25129. @@ -411,19 +497,28 @@
  25130. local_irq_restore(flags);
  25131. }
  25132. -static void sdhci_transfer_pio(struct sdhci_host *host)
  25133. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  25134. {
  25135. u32 mask;
  25136. + u32 state = 0;
  25137. + u32 intmask;
  25138. + int available;
  25139. BUG_ON(!host->data);
  25140. if (host->blocks == 0)
  25141. return;
  25142. - if (host->data->flags & MMC_DATA_READ)
  25143. + if (host->data->flags & MMC_DATA_READ) {
  25144. mask = SDHCI_DATA_AVAILABLE;
  25145. - else
  25146. + intmask = SDHCI_INT_DATA_AVAIL;
  25147. + } else {
  25148. mask = SDHCI_SPACE_AVAILABLE;
  25149. + intmask = SDHCI_INT_SPACE_AVAIL;
  25150. + }
  25151. +
  25152. + /* initially we can see whether we can procede using intstate */
  25153. + available = (intstate & intmask);
  25154. /*
  25155. * Some controllers (JMicron JMB38x) mess up the buffer bits
  25156. @@ -434,7 +529,7 @@
  25157. (host->data->blocks == 1))
  25158. mask = ~0;
  25159. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  25160. + while (available) {
  25161. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  25162. udelay(100);
  25163. @@ -446,9 +541,11 @@
  25164. host->blocks--;
  25165. if (host->blocks == 0)
  25166. break;
  25167. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  25168. + available = state & mask;
  25169. }
  25170. - DBG("PIO transfer complete.\n");
  25171. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  25172. }
  25173. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  25174. @@ -721,7 +818,9 @@
  25175. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  25176. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  25177. - if (host->flags & SDHCI_REQ_USE_DMA)
  25178. + /* platform DMA will begin on receipt of PIO irqs */
  25179. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  25180. + !(host->flags & SDHCI_USE_PLATDMA))
  25181. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  25182. else
  25183. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  25184. @@ -753,44 +852,25 @@
  25185. host->data_early = 0;
  25186. host->data->bytes_xfered = 0;
  25187. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  25188. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  25189. host->flags |= SDHCI_REQ_USE_DMA;
  25190. /*
  25191. * FIXME: This doesn't account for merging when mapping the
  25192. * scatterlist.
  25193. */
  25194. - if (host->flags & SDHCI_REQ_USE_DMA) {
  25195. - int broken, i;
  25196. - struct scatterlist *sg;
  25197. -
  25198. - broken = 0;
  25199. - if (host->flags & SDHCI_USE_ADMA) {
  25200. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  25201. - broken = 1;
  25202. - } else {
  25203. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  25204. - broken = 1;
  25205. - }
  25206. -
  25207. - if (unlikely(broken)) {
  25208. - for_each_sg(data->sg, sg, data->sg_len, i) {
  25209. - if (sg->length & 0x3) {
  25210. - DBG("Reverting to PIO because of "
  25211. - "transfer size (%d)\n",
  25212. - sg->length);
  25213. - host->flags &= ~SDHCI_REQ_USE_DMA;
  25214. - break;
  25215. - }
  25216. - }
  25217. - }
  25218. - }
  25219. /*
  25220. * The assumption here being that alignment is the same after
  25221. * translation to device address space.
  25222. */
  25223. - if (host->flags & SDHCI_REQ_USE_DMA) {
  25224. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  25225. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  25226. +
  25227. + if (! sdhci_platdma_dmaable(host, data))
  25228. + host->flags &= ~SDHCI_REQ_USE_DMA;
  25229. +
  25230. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  25231. int broken, i;
  25232. struct scatterlist *sg;
  25233. @@ -849,7 +929,8 @@
  25234. */
  25235. WARN_ON(1);
  25236. host->flags &= ~SDHCI_REQ_USE_DMA;
  25237. - } else {
  25238. + } else
  25239. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  25240. WARN_ON(sg_cnt != 1);
  25241. sdhci_writel(host, sg_dma_address(data->sg),
  25242. SDHCI_DMA_ADDRESS);
  25243. @@ -865,11 +946,13 @@
  25244. if (host->version >= SDHCI_SPEC_200) {
  25245. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  25246. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  25247. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  25248. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  25249. (host->flags & SDHCI_USE_ADMA))
  25250. ctrl |= SDHCI_CTRL_ADMA32;
  25251. else
  25252. ctrl |= SDHCI_CTRL_SDMA;
  25253. + }
  25254. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  25255. }
  25256. @@ -921,7 +1004,8 @@
  25257. if (data->flags & MMC_DATA_READ)
  25258. mode |= SDHCI_TRNS_READ;
  25259. - if (host->flags & SDHCI_REQ_USE_DMA)
  25260. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  25261. + !(host->flags & SDHCI_USE_PLATDMA))
  25262. mode |= SDHCI_TRNS_DMA;
  25263. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  25264. @@ -937,13 +1021,16 @@
  25265. host->data = NULL;
  25266. if (host->flags & SDHCI_REQ_USE_DMA) {
  25267. - if (host->flags & SDHCI_USE_ADMA)
  25268. - sdhci_adma_table_post(host, data);
  25269. - else {
  25270. + /* we may have to abandon an ongoing platform DMA */
  25271. + if (host->flags & SDHCI_USE_PLATDMA)
  25272. + sdhci_platdma_reset(host, data);
  25273. +
  25274. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  25275. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  25276. data->sg_len, (data->flags & MMC_DATA_READ) ?
  25277. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  25278. - }
  25279. + } else if (host->flags & SDHCI_USE_ADMA)
  25280. + sdhci_adma_table_post(host, data);
  25281. }
  25282. /*
  25283. @@ -996,6 +1083,12 @@
  25284. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  25285. mask |= SDHCI_DATA_INHIBIT;
  25286. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  25287. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  25288. + // which might cause the STATUS command to get stuck when a data operation is in flow
  25289. + mask |= SDHCI_DATA_INHIBIT;
  25290. + }
  25291. +
  25292. /* We shouldn't wait for data inihibit for stop commands, even
  25293. though they might use busy signaling */
  25294. if (host->mrq->data && (cmd == host->mrq->data->stop))
  25295. @@ -1011,12 +1104,20 @@
  25296. return;
  25297. }
  25298. timeout--;
  25299. + sdhci_spin_enable_schedule(host);
  25300. mdelay(1);
  25301. + sdhci_spin_disable_schedule(host);
  25302. }
  25303. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  25304. + sdhci_readl(host, SDHCI_INT_STATUS));
  25305. mod_timer(&host->timer, jiffies + 10 * HZ);
  25306. host->cmd = cmd;
  25307. + if (host->last_cmdop == MMC_APP_CMD)
  25308. + host->last_cmdop = -cmd->opcode;
  25309. + else
  25310. + host->last_cmdop = cmd->opcode;
  25311. sdhci_prepare_data(host, cmd);
  25312. @@ -1232,7 +1333,9 @@
  25313. return;
  25314. }
  25315. timeout--;
  25316. + sdhci_spin_enable_schedule(host);
  25317. mdelay(1);
  25318. + sdhci_spin_disable_schedule(host);
  25319. }
  25320. clk |= SDHCI_CLOCK_CARD_EN;
  25321. @@ -1333,7 +1436,7 @@
  25322. sdhci_runtime_pm_get(host);
  25323. - spin_lock_irqsave(&host->lock, flags);
  25324. + sdhci_spin_lock_irqsave(host, &flags);
  25325. WARN_ON(host->mrq != NULL);
  25326. @@ -1391,9 +1494,9 @@
  25327. mmc->card->type == MMC_TYPE_MMC ?
  25328. MMC_SEND_TUNING_BLOCK_HS200 :
  25329. MMC_SEND_TUNING_BLOCK;
  25330. - spin_unlock_irqrestore(&host->lock, flags);
  25331. + sdhci_spin_unlock_irqrestore(host, flags);
  25332. sdhci_execute_tuning(mmc, tuning_opcode);
  25333. - spin_lock_irqsave(&host->lock, flags);
  25334. + sdhci_spin_lock_irqsave(host, &flags);
  25335. /* Restore original mmc_request structure */
  25336. host->mrq = mrq;
  25337. @@ -1407,7 +1510,7 @@
  25338. }
  25339. mmiowb();
  25340. - spin_unlock_irqrestore(&host->lock, flags);
  25341. + sdhci_spin_unlock_irqrestore(host, flags);
  25342. }
  25343. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  25344. @@ -1416,10 +1519,10 @@
  25345. int vdd_bit = -1;
  25346. u8 ctrl;
  25347. - spin_lock_irqsave(&host->lock, flags);
  25348. + sdhci_spin_lock_irqsave(host, &flags);
  25349. if (host->flags & SDHCI_DEVICE_DEAD) {
  25350. - spin_unlock_irqrestore(&host->lock, flags);
  25351. + sdhci_spin_unlock_irqrestore(host, flags);
  25352. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  25353. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  25354. return;
  25355. @@ -1446,9 +1549,9 @@
  25356. vdd_bit = sdhci_set_power(host, ios->vdd);
  25357. if (host->vmmc && vdd_bit != -1) {
  25358. - spin_unlock_irqrestore(&host->lock, flags);
  25359. + sdhci_spin_unlock_irqrestore(host, flags);
  25360. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  25361. - spin_lock_irqsave(&host->lock, flags);
  25362. + sdhci_spin_lock_irqsave(host, &flags);
  25363. }
  25364. if (host->ops->platform_send_init_74_clocks)
  25365. @@ -1487,7 +1590,7 @@
  25366. else
  25367. ctrl &= ~SDHCI_CTRL_HISPD;
  25368. - if (host->version >= SDHCI_SPEC_300) {
  25369. + if (host->version >= SDHCI_SPEC_300 && !(host->ops->uhs_broken)) {
  25370. u16 clk, ctrl_2;
  25371. /* In case of UHS-I modes, set High Speed Enable */
  25372. @@ -1585,7 +1688,7 @@
  25373. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  25374. mmiowb();
  25375. - spin_unlock_irqrestore(&host->lock, flags);
  25376. + sdhci_spin_unlock_irqrestore(host, flags);
  25377. }
  25378. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  25379. @@ -1633,7 +1736,7 @@
  25380. unsigned long flags;
  25381. int is_readonly;
  25382. - spin_lock_irqsave(&host->lock, flags);
  25383. + sdhci_spin_lock_irqsave(host, &flags);
  25384. if (host->flags & SDHCI_DEVICE_DEAD)
  25385. is_readonly = 0;
  25386. @@ -1643,7 +1746,7 @@
  25387. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  25388. & SDHCI_WRITE_PROTECT);
  25389. - spin_unlock_irqrestore(&host->lock, flags);
  25390. + sdhci_spin_unlock_irqrestore(host, flags);
  25391. /* This quirk needs to be replaced by a callback-function later */
  25392. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  25393. @@ -1716,9 +1819,9 @@
  25394. struct sdhci_host *host = mmc_priv(mmc);
  25395. unsigned long flags;
  25396. - spin_lock_irqsave(&host->lock, flags);
  25397. + sdhci_spin_lock_irqsave(host, &flags);
  25398. sdhci_enable_sdio_irq_nolock(host, enable);
  25399. - spin_unlock_irqrestore(&host->lock, flags);
  25400. + sdhci_spin_unlock_irqrestore(host, flags);
  25401. }
  25402. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  25403. @@ -2066,7 +2169,7 @@
  25404. if (host->ops->card_event)
  25405. host->ops->card_event(host);
  25406. - spin_lock_irqsave(&host->lock, flags);
  25407. + sdhci_spin_lock_irqsave(host, &flags);
  25408. /* Check host->mrq first in case we are runtime suspended */
  25409. if (host->mrq && !sdhci_do_get_cd(host)) {
  25410. @@ -2082,7 +2185,7 @@
  25411. tasklet_schedule(&host->finish_tasklet);
  25412. }
  25413. - spin_unlock_irqrestore(&host->lock, flags);
  25414. + sdhci_spin_unlock_irqrestore(host, flags);
  25415. }
  25416. static const struct mmc_host_ops sdhci_ops = {
  25417. @@ -2121,14 +2224,14 @@
  25418. host = (struct sdhci_host*)param;
  25419. - spin_lock_irqsave(&host->lock, flags);
  25420. + sdhci_spin_lock_irqsave(host, &flags);
  25421. /*
  25422. * If this tasklet gets rescheduled while running, it will
  25423. * be run again afterwards but without any active request.
  25424. */
  25425. if (!host->mrq) {
  25426. - spin_unlock_irqrestore(&host->lock, flags);
  25427. + sdhci_spin_unlock_irqrestore(host, flags);
  25428. return;
  25429. }
  25430. @@ -2166,7 +2269,7 @@
  25431. #endif
  25432. mmiowb();
  25433. - spin_unlock_irqrestore(&host->lock, flags);
  25434. + sdhci_spin_unlock_irqrestore(host, flags);
  25435. mmc_request_done(host->mmc, mrq);
  25436. sdhci_runtime_pm_put(host);
  25437. @@ -2179,11 +2282,11 @@
  25438. host = (struct sdhci_host*)data;
  25439. - spin_lock_irqsave(&host->lock, flags);
  25440. + sdhci_spin_lock_irqsave(host, &flags);
  25441. if (host->mrq) {
  25442. pr_err("%s: Timeout waiting for hardware "
  25443. - "interrupt.\n", mmc_hostname(host->mmc));
  25444. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  25445. sdhci_dumpregs(host);
  25446. if (host->data) {
  25447. @@ -2200,7 +2303,7 @@
  25448. }
  25449. mmiowb();
  25450. - spin_unlock_irqrestore(&host->lock, flags);
  25451. + sdhci_spin_unlock_irqrestore(host, flags);
  25452. }
  25453. static void sdhci_tuning_timer(unsigned long data)
  25454. @@ -2210,11 +2313,11 @@
  25455. host = (struct sdhci_host *)data;
  25456. - spin_lock_irqsave(&host->lock, flags);
  25457. + sdhci_spin_lock_irqsave(host, &flags);
  25458. host->flags |= SDHCI_NEEDS_RETUNING;
  25459. - spin_unlock_irqrestore(&host->lock, flags);
  25460. + sdhci_spin_unlock_irqrestore(host, flags);
  25461. }
  25462. /*****************************************************************************\
  25463. @@ -2228,10 +2331,13 @@
  25464. BUG_ON(intmask == 0);
  25465. if (!host->cmd) {
  25466. + if (!(host->ops->extra_ints)) {
  25467. pr_err("%s: Got command interrupt 0x%08x even "
  25468. "though no command operation was in progress.\n",
  25469. mmc_hostname(host->mmc), (unsigned)intmask);
  25470. sdhci_dumpregs(host);
  25471. + } else
  25472. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  25473. return;
  25474. }
  25475. @@ -2301,6 +2407,19 @@
  25476. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  25477. #endif
  25478. +static void sdhci_data_end(struct sdhci_host *host)
  25479. +{
  25480. + if (host->cmd) {
  25481. + /*
  25482. + * Data managed to finish before the
  25483. + * command completed. Make sure we do
  25484. + * things in the proper order.
  25485. + */
  25486. + host->data_early = 1;
  25487. + } else
  25488. + sdhci_finish_data(host);
  25489. +}
  25490. +
  25491. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  25492. {
  25493. u32 command;
  25494. @@ -2330,23 +2449,39 @@
  25495. }
  25496. }
  25497. + if (!(host->ops->extra_ints)) {
  25498. pr_err("%s: Got data interrupt 0x%08x even "
  25499. "though no data operation was in progress.\n",
  25500. mmc_hostname(host->mmc), (unsigned)intmask);
  25501. sdhci_dumpregs(host);
  25502. + } else
  25503. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  25504. return;
  25505. }
  25506. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  25507. host->data->error = -ETIMEDOUT;
  25508. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  25509. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  25510. + DBG("end error in cmd %d\n", host->last_cmdop);
  25511. + if (host->ops->spurious_crc_acmd51 &&
  25512. + host->last_cmdop == -SD_APP_SEND_SCR) {
  25513. + DBG("ignoring spurious data_end_bit error\n");
  25514. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  25515. + } else
  25516. host->data->error = -EILSEQ;
  25517. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  25518. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  25519. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  25520. - != MMC_BUS_TEST_R)
  25521. + != MMC_BUS_TEST_R) {
  25522. + DBG("crc error in cmd %d\n", host->last_cmdop);
  25523. + if (host->ops->spurious_crc_acmd51 &&
  25524. + host->last_cmdop == -SD_APP_SEND_SCR) {
  25525. + DBG("ignoring spurious data_crc_bit error\n");
  25526. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  25527. + } else {
  25528. host->data->error = -EILSEQ;
  25529. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  25530. + }
  25531. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  25532. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  25533. sdhci_show_adma_error(host);
  25534. host->data->error = -EIO;
  25535. @@ -2354,11 +2489,18 @@
  25536. host->ops->adma_workaround(host, intmask);
  25537. }
  25538. - if (host->data->error)
  25539. + if (host->data->error) {
  25540. + DBG("finish request early on error %d\n", host->data->error);
  25541. sdhci_finish_data(host);
  25542. - else {
  25543. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  25544. - sdhci_transfer_pio(host);
  25545. + } else {
  25546. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  25547. + if (host->flags & SDHCI_REQ_USE_DMA) {
  25548. + /* possible only in PLATDMA mode */
  25549. + sdhci_platdma_avail(host, &intmask,
  25550. + &sdhci_data_end);
  25551. + } else
  25552. + sdhci_transfer_pio(host, intmask);
  25553. + }
  25554. /*
  25555. * We currently don't do anything fancy with DMA
  25556. @@ -2387,18 +2529,8 @@
  25557. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  25558. }
  25559. - if (intmask & SDHCI_INT_DATA_END) {
  25560. - if (host->cmd) {
  25561. - /*
  25562. - * Data managed to finish before the
  25563. - * command completed. Make sure we do
  25564. - * things in the proper order.
  25565. - */
  25566. - host->data_early = 1;
  25567. - } else {
  25568. - sdhci_finish_data(host);
  25569. - }
  25570. - }
  25571. + if (intmask & SDHCI_INT_DATA_END)
  25572. + sdhci_data_end(host);
  25573. }
  25574. }
  25575. @@ -2409,10 +2541,10 @@
  25576. u32 intmask, unexpected = 0;
  25577. int cardint = 0, max_loops = 16;
  25578. - spin_lock(&host->lock);
  25579. + sdhci_spin_lock(host);
  25580. if (host->runtime_suspended) {
  25581. - spin_unlock(&host->lock);
  25582. + sdhci_spin_unlock(host);
  25583. pr_warning("%s: got irq while runtime suspended\n",
  25584. mmc_hostname(host->mmc));
  25585. return IRQ_HANDLED;
  25586. @@ -2454,6 +2586,22 @@
  25587. tasklet_schedule(&host->card_tasklet);
  25588. }
  25589. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  25590. + DBG("controller reports error 0x%x -"
  25591. + "%s%s%s%s%s%s%s%s%s%s",
  25592. + intmask,
  25593. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  25594. + intmask & SDHCI_INT_CRC ? " crc": "",
  25595. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  25596. + intmask & SDHCI_INT_INDEX? " index": "",
  25597. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  25598. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  25599. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  25600. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  25601. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  25602. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  25603. + );
  25604. +
  25605. if (intmask & SDHCI_INT_CMD_MASK) {
  25606. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  25607. SDHCI_INT_STATUS);
  25608. @@ -2468,7 +2616,13 @@
  25609. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  25610. - intmask &= ~SDHCI_INT_ERROR;
  25611. + if (intmask & SDHCI_INT_ERROR_MASK) {
  25612. + /* collect any uncovered errors */
  25613. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  25614. + SDHCI_INT_STATUS);
  25615. + }
  25616. +
  25617. + intmask &= ~SDHCI_INT_ERROR_MASK;
  25618. if (intmask & SDHCI_INT_BUS_POWER) {
  25619. pr_err("%s: Card is consuming too much power!\n",
  25620. @@ -2494,7 +2648,7 @@
  25621. if (intmask && --max_loops)
  25622. goto again;
  25623. out:
  25624. - spin_unlock(&host->lock);
  25625. + sdhci_spin_unlock(host);
  25626. if (unexpected) {
  25627. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  25628. @@ -2588,7 +2742,8 @@
  25629. {
  25630. int ret;
  25631. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  25632. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  25633. + SDHCI_USE_PLATDMA)) {
  25634. if (host->ops->enable_dma)
  25635. host->ops->enable_dma(host);
  25636. }
  25637. @@ -2671,15 +2826,15 @@
  25638. host->flags &= ~SDHCI_NEEDS_RETUNING;
  25639. }
  25640. - spin_lock_irqsave(&host->lock, flags);
  25641. + sdhci_spin_lock_irqsave(host, &flags);
  25642. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  25643. - spin_unlock_irqrestore(&host->lock, flags);
  25644. + sdhci_spin_unlock_irqrestore(host, flags);
  25645. synchronize_irq(host->irq);
  25646. - spin_lock_irqsave(&host->lock, flags);
  25647. + sdhci_spin_lock_irqsave(host, &flags);
  25648. host->runtime_suspended = true;
  25649. - spin_unlock_irqrestore(&host->lock, flags);
  25650. + sdhci_spin_unlock_irqrestore(host, flags);
  25651. return ret;
  25652. }
  25653. @@ -2705,16 +2860,16 @@
  25654. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  25655. if ((host_flags & SDHCI_PV_ENABLED) &&
  25656. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  25657. - spin_lock_irqsave(&host->lock, flags);
  25658. + sdhci_spin_lock_irqsave(host, &flags);
  25659. sdhci_enable_preset_value(host, true);
  25660. - spin_unlock_irqrestore(&host->lock, flags);
  25661. + sdhci_spin_unlock_irqrestore(host, flags);
  25662. }
  25663. /* Set the re-tuning expiration flag */
  25664. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  25665. host->flags |= SDHCI_NEEDS_RETUNING;
  25666. - spin_lock_irqsave(&host->lock, flags);
  25667. + sdhci_spin_lock_irqsave(host, &flags);
  25668. host->runtime_suspended = false;
  25669. @@ -2725,7 +2880,7 @@
  25670. /* Enable Card Detection */
  25671. sdhci_enable_card_detection(host);
  25672. - spin_unlock_irqrestore(&host->lock, flags);
  25673. + sdhci_spin_unlock_irqrestore(host, flags);
  25674. return ret;
  25675. }
  25676. @@ -2820,14 +2975,16 @@
  25677. host->flags &= ~SDHCI_USE_ADMA;
  25678. }
  25679. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  25680. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  25681. + SDHCI_USE_PLATDMA)) {
  25682. if (host->ops->enable_dma) {
  25683. if (host->ops->enable_dma(host)) {
  25684. pr_warning("%s: No suitable DMA "
  25685. "available. Falling back to PIO.\n",
  25686. mmc_hostname(mmc));
  25687. host->flags &=
  25688. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  25689. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  25690. + SDHCI_USE_PLATDMA);
  25691. }
  25692. }
  25693. }
  25694. @@ -3119,6 +3276,12 @@
  25695. SDHCI_MAX_CURRENT_MULTIPLIER;
  25696. }
  25697. + if(host->ops->voltage_broken) {
  25698. + ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
  25699. + // Cannot support UHS modes if we are stuck at 3.3V;
  25700. + mmc->caps &= ~(MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_DDR50);
  25701. + }
  25702. +
  25703. mmc->ocr_avail = ocr_avail;
  25704. mmc->ocr_avail_sdio = ocr_avail;
  25705. if (host->ocr_avail_sdio)
  25706. @@ -3213,7 +3376,7 @@
  25707. host->tuning_timer.function = sdhci_tuning_timer;
  25708. }
  25709. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  25710. + ret = request_irq(host->irq, sdhci_irq, 0,//IRQF_SHARED,
  25711. mmc_hostname(mmc), host);
  25712. if (ret) {
  25713. pr_err("%s: Failed to request IRQ %d: %d\n",
  25714. @@ -3249,6 +3412,7 @@
  25715. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  25716. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  25717. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  25718. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  25719. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  25720. @@ -3276,7 +3440,7 @@
  25721. unsigned long flags;
  25722. if (dead) {
  25723. - spin_lock_irqsave(&host->lock, flags);
  25724. + sdhci_spin_lock_irqsave(host, &flags);
  25725. host->flags |= SDHCI_DEVICE_DEAD;
  25726. @@ -3288,7 +3452,7 @@
  25727. tasklet_schedule(&host->finish_tasklet);
  25728. }
  25729. - spin_unlock_irqrestore(&host->lock, flags);
  25730. + sdhci_spin_unlock_irqrestore(host, flags);
  25731. }
  25732. sdhci_disable_card_detection(host);
  25733. diff -Nur linux-3.11.10.orig/drivers/mmc/host/sdhci.h linux-3.11.10/drivers/mmc/host/sdhci.h
  25734. --- linux-3.11.10.orig/drivers/mmc/host/sdhci.h 2013-11-29 19:42:37.000000000 +0100
  25735. +++ linux-3.11.10/drivers/mmc/host/sdhci.h 2014-02-07 19:57:28.000000000 +0100
  25736. @@ -289,6 +289,20 @@
  25737. void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
  25738. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  25739. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  25740. +
  25741. + int (*pdma_able)(struct sdhci_host *host,
  25742. + struct mmc_data *data);
  25743. + void (*pdma_avail)(struct sdhci_host *host,
  25744. + unsigned int *ref_intmask,
  25745. + void(*complete)(struct sdhci_host *));
  25746. + void (*pdma_reset)(struct sdhci_host *host,
  25747. + struct mmc_data *data);
  25748. + unsigned int (*extra_ints)(struct sdhci_host *host);
  25749. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  25750. + unsigned int (*voltage_broken)(struct sdhci_host *host);
  25751. + unsigned int (*uhs_broken)(struct sdhci_host *host);
  25752. + unsigned int (*missing_status)(struct sdhci_host *host);
  25753. +
  25754. void (*hw_reset)(struct sdhci_host *host);
  25755. void (*platform_suspend)(struct sdhci_host *host);
  25756. void (*platform_resume)(struct sdhci_host *host);
  25757. @@ -400,9 +414,38 @@
  25758. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  25759. #endif
  25760. +static inline int /*bool*/
  25761. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  25762. +{
  25763. + if (host->ops->pdma_able)
  25764. + return host->ops->pdma_able(host, data);
  25765. + else
  25766. + return 1;
  25767. +}
  25768. +static inline void
  25769. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  25770. + void(*completion_callback)(struct sdhci_host *))
  25771. +{
  25772. + if (host->ops->pdma_avail)
  25773. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  25774. +}
  25775. +
  25776. +static inline void
  25777. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  25778. +{
  25779. + if (host->ops->pdma_reset)
  25780. + host->ops->pdma_reset(host, data);
  25781. +}
  25782. +
  25783. #ifdef CONFIG_PM_RUNTIME
  25784. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  25785. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  25786. #endif
  25787. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  25788. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  25789. +extern void sdhci_spin_lock(struct sdhci_host *host);
  25790. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  25791. +
  25792. +
  25793. #endif /* __SDHCI_HW_H */
  25794. diff -Nur linux-3.11.10.orig/drivers/net/usb/smsc95xx.c linux-3.11.10/drivers/net/usb/smsc95xx.c
  25795. --- linux-3.11.10.orig/drivers/net/usb/smsc95xx.c 2013-11-29 19:42:37.000000000 +0100
  25796. +++ linux-3.11.10/drivers/net/usb/smsc95xx.c 2014-02-07 19:57:28.000000000 +0100
  25797. @@ -61,6 +61,7 @@
  25798. #define SUSPEND_SUSPEND3 (0x08)
  25799. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  25800. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  25801. +#define MAC_ADDR_LEN (6)
  25802. struct smsc95xx_priv {
  25803. u32 mac_cr;
  25804. @@ -76,6 +77,10 @@
  25805. module_param(turbo_mode, bool, 0644);
  25806. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  25807. +static char *macaddr = ":";
  25808. +module_param(macaddr, charp, 0);
  25809. +MODULE_PARM_DESC(macaddr, "MAC address");
  25810. +
  25811. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  25812. u32 *data, int in_pm)
  25813. {
  25814. @@ -765,8 +770,59 @@
  25815. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  25816. }
  25817. +/* Check the macaddr module parameter for a MAC address */
  25818. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  25819. +{
  25820. + int i, j, got_num, num;
  25821. + u8 mtbl[MAC_ADDR_LEN];
  25822. +
  25823. + if (macaddr[0] == ':')
  25824. + return 0;
  25825. +
  25826. + i = 0;
  25827. + j = 0;
  25828. + num = 0;
  25829. + got_num = 0;
  25830. + while (j < MAC_ADDR_LEN) {
  25831. + if (macaddr[i] && macaddr[i] != ':') {
  25832. + got_num++;
  25833. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  25834. + num = num * 16 + macaddr[i] - '0';
  25835. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  25836. + num = num * 16 + 10 + macaddr[i] - 'A';
  25837. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  25838. + num = num * 16 + 10 + macaddr[i] - 'a';
  25839. + else
  25840. + break;
  25841. + i++;
  25842. + } else if (got_num == 2) {
  25843. + mtbl[j++] = (u8) num;
  25844. + num = 0;
  25845. + got_num = 0;
  25846. + i++;
  25847. + } else {
  25848. + break;
  25849. + }
  25850. + }
  25851. +
  25852. + if (j == MAC_ADDR_LEN) {
  25853. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  25854. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  25855. + mtbl[3], mtbl[4], mtbl[5]);
  25856. + for (i = 0; i < MAC_ADDR_LEN; i++)
  25857. + dev_mac[i] = mtbl[i];
  25858. + return 1;
  25859. + } else {
  25860. + return 0;
  25861. + }
  25862. +}
  25863. +
  25864. static void smsc95xx_init_mac_address(struct usbnet *dev)
  25865. {
  25866. + /* Check module parameters */
  25867. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  25868. + return;
  25869. +
  25870. /* try reading mac address from EEPROM */
  25871. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  25872. dev->net->dev_addr) == 0) {
  25873. diff -Nur linux-3.11.10.orig/drivers/net/wireless/ath/ath9k/hif_usb.c linux-3.11.10/drivers/net/wireless/ath/ath9k/hif_usb.c
  25874. --- linux-3.11.10.orig/drivers/net/wireless/ath/ath9k/hif_usb.c 2013-11-29 19:42:37.000000000 +0100
  25875. +++ linux-3.11.10/drivers/net/wireless/ath/ath9k/hif_usb.c 2014-02-07 19:57:28.000000000 +0100
  25876. @@ -37,9 +37,11 @@
  25877. { USB_DEVICE(0x13D3, 0x3350) }, /* Azurewave */
  25878. { USB_DEVICE(0x04CA, 0x4605) }, /* Liteon */
  25879. { USB_DEVICE(0x040D, 0x3801) }, /* VIA */
  25880. + { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */
  25881. { USB_DEVICE(0x0cf3, 0xb003) }, /* Ubiquiti WifiStation Ext */
  25882. { USB_DEVICE(0x0cf3, 0xb002) }, /* Ubiquiti WifiStation */
  25883. { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
  25884. + { USB_DEVICE(0x057c, 0x8403) }, /* AVM FRITZ!WLAN 11N v2 USB */
  25885. { USB_DEVICE(0x0cf3, 0x7015),
  25886. .driver_info = AR9287_USB }, /* Atheros */
  25887. diff -Nur linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800.h linux-3.11.10/drivers/net/wireless/rt2x00/rt2800.h
  25888. --- linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800.h 2013-11-29 19:42:37.000000000 +0100
  25889. +++ linux-3.11.10/drivers/net/wireless/rt2x00/rt2800.h 2014-02-07 19:57:28.000000000 +0100
  25890. @@ -70,6 +70,7 @@
  25891. #define RF3322 0x000c
  25892. #define RF3053 0x000d
  25893. #define RF5592 0x000f
  25894. +#define RF3070 0x3070
  25895. #define RF3290 0x3290
  25896. #define RF5360 0x5360
  25897. #define RF5370 0x5370
  25898. diff -Nur linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800lib.c linux-3.11.10/drivers/net/wireless/rt2x00/rt2800lib.c
  25899. --- linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800lib.c 2013-11-29 19:42:37.000000000 +0100
  25900. +++ linux-3.11.10/drivers/net/wireless/rt2x00/rt2800lib.c 2014-02-07 19:57:28.000000000 +0100
  25901. @@ -2599,6 +2599,7 @@
  25902. break;
  25903. case RF5360:
  25904. case RF5370:
  25905. + case RF3070:
  25906. case RF5372:
  25907. case RF5390:
  25908. case RF5392:
  25909. @@ -2615,6 +2616,7 @@
  25910. rt2x00_rf(rt2x00dev, RF3322) ||
  25911. rt2x00_rf(rt2x00dev, RF5360) ||
  25912. rt2x00_rf(rt2x00dev, RF5370) ||
  25913. + rt2x00_rf(rt2x00dev, RF3070) ||
  25914. rt2x00_rf(rt2x00dev, RF5372) ||
  25915. rt2x00_rf(rt2x00dev, RF5390) ||
  25916. rt2x00_rf(rt2x00dev, RF5392)) {
  25917. @@ -3229,6 +3231,7 @@
  25918. case RF3290:
  25919. case RF5360:
  25920. case RF5370:
  25921. + case RF3070:
  25922. case RF5372:
  25923. case RF5390:
  25924. case RF5392:
  25925. @@ -5747,6 +5750,7 @@
  25926. case RF3322:
  25927. case RF5360:
  25928. case RF5370:
  25929. + case RF3070:
  25930. case RF5372:
  25931. case RF5390:
  25932. case RF5392:
  25933. @@ -6202,6 +6206,7 @@
  25934. rt2x00_rf(rt2x00dev, RF3322) ||
  25935. rt2x00_rf(rt2x00dev, RF5360) ||
  25936. rt2x00_rf(rt2x00dev, RF5370) ||
  25937. + rt2x00_rf(rt2x00dev, RF3070) ||
  25938. rt2x00_rf(rt2x00dev, RF5372) ||
  25939. rt2x00_rf(rt2x00dev, RF5390) ||
  25940. rt2x00_rf(rt2x00dev, RF5392)) {
  25941. @@ -6304,6 +6309,7 @@
  25942. case RF3290:
  25943. case RF5360:
  25944. case RF5370:
  25945. + case RF3070:
  25946. case RF5372:
  25947. case RF5390:
  25948. case RF5392:
  25949. diff -Nur linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800lib.c.orig linux-3.11.10/drivers/net/wireless/rt2x00/rt2800lib.c.orig
  25950. --- linux-3.11.10.orig/drivers/net/wireless/rt2x00/rt2800lib.c.orig 1970-01-01 01:00:00.000000000 +0100
  25951. +++ linux-3.11.10/drivers/net/wireless/rt2x00/rt2800lib.c.orig 2013-11-29 19:42:37.000000000 +0100
  25952. @@ -0,0 +1,6652 @@
  25953. +/*
  25954. + Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  25955. + Copyright (C) 2010 Ivo van Doorn <IvDoorn@gmail.com>
  25956. + Copyright (C) 2009 Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
  25957. + Copyright (C) 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  25958. +
  25959. + Based on the original rt2800pci.c and rt2800usb.c.
  25960. + Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
  25961. + Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
  25962. + Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
  25963. + Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
  25964. + Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
  25965. + Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
  25966. + <http://rt2x00.serialmonkey.com>
  25967. +
  25968. + This program is free software; you can redistribute it and/or modify
  25969. + it under the terms of the GNU General Public License as published by
  25970. + the Free Software Foundation; either version 2 of the License, or
  25971. + (at your option) any later version.
  25972. +
  25973. + This program is distributed in the hope that it will be useful,
  25974. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  25975. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25976. + GNU General Public License for more details.
  25977. +
  25978. + You should have received a copy of the GNU General Public License
  25979. + along with this program; if not, write to the
  25980. + Free Software Foundation, Inc.,
  25981. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25982. + */
  25983. +
  25984. +/*
  25985. + Module: rt2800lib
  25986. + Abstract: rt2800 generic device routines.
  25987. + */
  25988. +
  25989. +#include <linux/crc-ccitt.h>
  25990. +#include <linux/kernel.h>
  25991. +#include <linux/module.h>
  25992. +#include <linux/slab.h>
  25993. +
  25994. +#include "rt2x00.h"
  25995. +#include "rt2800lib.h"
  25996. +#include "rt2800.h"
  25997. +
  25998. +/*
  25999. + * Register access.
  26000. + * All access to the CSR registers will go through the methods
  26001. + * rt2800_register_read and rt2800_register_write.
  26002. + * BBP and RF register require indirect register access,
  26003. + * and use the CSR registers BBPCSR and RFCSR to achieve this.
  26004. + * These indirect registers work with busy bits,
  26005. + * and we will try maximal REGISTER_BUSY_COUNT times to access
  26006. + * the register while taking a REGISTER_BUSY_DELAY us delay
  26007. + * between each attampt. When the busy bit is still set at that time,
  26008. + * the access attempt is considered to have failed,
  26009. + * and we will print an error.
  26010. + * The _lock versions must be used if you already hold the csr_mutex
  26011. + */
  26012. +#define WAIT_FOR_BBP(__dev, __reg) \
  26013. + rt2800_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
  26014. +#define WAIT_FOR_RFCSR(__dev, __reg) \
  26015. + rt2800_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
  26016. +#define WAIT_FOR_RF(__dev, __reg) \
  26017. + rt2800_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
  26018. +#define WAIT_FOR_MCU(__dev, __reg) \
  26019. + rt2800_regbusy_read((__dev), H2M_MAILBOX_CSR, \
  26020. + H2M_MAILBOX_CSR_OWNER, (__reg))
  26021. +
  26022. +static inline bool rt2800_is_305x_soc(struct rt2x00_dev *rt2x00dev)
  26023. +{
  26024. + /* check for rt2872 on SoC */
  26025. + if (!rt2x00_is_soc(rt2x00dev) ||
  26026. + !rt2x00_rt(rt2x00dev, RT2872))
  26027. + return false;
  26028. +
  26029. + /* we know for sure that these rf chipsets are used on rt305x boards */
  26030. + if (rt2x00_rf(rt2x00dev, RF3020) ||
  26031. + rt2x00_rf(rt2x00dev, RF3021) ||
  26032. + rt2x00_rf(rt2x00dev, RF3022))
  26033. + return true;
  26034. +
  26035. + rt2x00_warn(rt2x00dev, "Unknown RF chipset on rt305x\n");
  26036. + return false;
  26037. +}
  26038. +
  26039. +static void rt2800_bbp_write(struct rt2x00_dev *rt2x00dev,
  26040. + const unsigned int word, const u8 value)
  26041. +{
  26042. + u32 reg;
  26043. +
  26044. + mutex_lock(&rt2x00dev->csr_mutex);
  26045. +
  26046. + /*
  26047. + * Wait until the BBP becomes available, afterwards we
  26048. + * can safely write the new data into the register.
  26049. + */
  26050. + if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  26051. + reg = 0;
  26052. + rt2x00_set_field32(&reg, BBP_CSR_CFG_VALUE, value);
  26053. + rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  26054. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  26055. + rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 0);
  26056. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
  26057. +
  26058. + rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  26059. + }
  26060. +
  26061. + mutex_unlock(&rt2x00dev->csr_mutex);
  26062. +}
  26063. +
  26064. +static void rt2800_bbp_read(struct rt2x00_dev *rt2x00dev,
  26065. + const unsigned int word, u8 *value)
  26066. +{
  26067. + u32 reg;
  26068. +
  26069. + mutex_lock(&rt2x00dev->csr_mutex);
  26070. +
  26071. + /*
  26072. + * Wait until the BBP becomes available, afterwards we
  26073. + * can safely write the read request into the register.
  26074. + * After the data has been written, we wait until hardware
  26075. + * returns the correct value, if at any time the register
  26076. + * doesn't become available in time, reg will be 0xffffffff
  26077. + * which means we return 0xff to the caller.
  26078. + */
  26079. + if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
  26080. + reg = 0;
  26081. + rt2x00_set_field32(&reg, BBP_CSR_CFG_REGNUM, word);
  26082. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BUSY, 1);
  26083. + rt2x00_set_field32(&reg, BBP_CSR_CFG_READ_CONTROL, 1);
  26084. + rt2x00_set_field32(&reg, BBP_CSR_CFG_BBP_RW_MODE, 1);
  26085. +
  26086. + rt2800_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
  26087. +
  26088. + WAIT_FOR_BBP(rt2x00dev, &reg);
  26089. + }
  26090. +
  26091. + *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
  26092. +
  26093. + mutex_unlock(&rt2x00dev->csr_mutex);
  26094. +}
  26095. +
  26096. +static void rt2800_rfcsr_write(struct rt2x00_dev *rt2x00dev,
  26097. + const unsigned int word, const u8 value)
  26098. +{
  26099. + u32 reg;
  26100. +
  26101. + mutex_lock(&rt2x00dev->csr_mutex);
  26102. +
  26103. + /*
  26104. + * Wait until the RFCSR becomes available, afterwards we
  26105. + * can safely write the new data into the register.
  26106. + */
  26107. + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  26108. + reg = 0;
  26109. + rt2x00_set_field32(&reg, RF_CSR_CFG_DATA, value);
  26110. + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  26111. + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 1);
  26112. + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  26113. +
  26114. + rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  26115. + }
  26116. +
  26117. + mutex_unlock(&rt2x00dev->csr_mutex);
  26118. +}
  26119. +
  26120. +static void rt2800_rfcsr_read(struct rt2x00_dev *rt2x00dev,
  26121. + const unsigned int word, u8 *value)
  26122. +{
  26123. + u32 reg;
  26124. +
  26125. + mutex_lock(&rt2x00dev->csr_mutex);
  26126. +
  26127. + /*
  26128. + * Wait until the RFCSR becomes available, afterwards we
  26129. + * can safely write the read request into the register.
  26130. + * After the data has been written, we wait until hardware
  26131. + * returns the correct value, if at any time the register
  26132. + * doesn't become available in time, reg will be 0xffffffff
  26133. + * which means we return 0xff to the caller.
  26134. + */
  26135. + if (WAIT_FOR_RFCSR(rt2x00dev, &reg)) {
  26136. + reg = 0;
  26137. + rt2x00_set_field32(&reg, RF_CSR_CFG_REGNUM, word);
  26138. + rt2x00_set_field32(&reg, RF_CSR_CFG_WRITE, 0);
  26139. + rt2x00_set_field32(&reg, RF_CSR_CFG_BUSY, 1);
  26140. +
  26141. + rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
  26142. +
  26143. + WAIT_FOR_RFCSR(rt2x00dev, &reg);
  26144. + }
  26145. +
  26146. + *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
  26147. +
  26148. + mutex_unlock(&rt2x00dev->csr_mutex);
  26149. +}
  26150. +
  26151. +static void rt2800_rf_write(struct rt2x00_dev *rt2x00dev,
  26152. + const unsigned int word, const u32 value)
  26153. +{
  26154. + u32 reg;
  26155. +
  26156. + mutex_lock(&rt2x00dev->csr_mutex);
  26157. +
  26158. + /*
  26159. + * Wait until the RF becomes available, afterwards we
  26160. + * can safely write the new data into the register.
  26161. + */
  26162. + if (WAIT_FOR_RF(rt2x00dev, &reg)) {
  26163. + reg = 0;
  26164. + rt2x00_set_field32(&reg, RF_CSR_CFG0_REG_VALUE_BW, value);
  26165. + rt2x00_set_field32(&reg, RF_CSR_CFG0_STANDBYMODE, 0);
  26166. + rt2x00_set_field32(&reg, RF_CSR_CFG0_SEL, 0);
  26167. + rt2x00_set_field32(&reg, RF_CSR_CFG0_BUSY, 1);
  26168. +
  26169. + rt2800_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
  26170. + rt2x00_rf_write(rt2x00dev, word, value);
  26171. + }
  26172. +
  26173. + mutex_unlock(&rt2x00dev->csr_mutex);
  26174. +}
  26175. +
  26176. +static int rt2800_enable_wlan_rt3290(struct rt2x00_dev *rt2x00dev)
  26177. +{
  26178. + u32 reg;
  26179. + int i, count;
  26180. +
  26181. + rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
  26182. + if (rt2x00_get_field32(reg, WLAN_EN))
  26183. + return 0;
  26184. +
  26185. + rt2x00_set_field32(&reg, WLAN_GPIO_OUT_OE_BIT_ALL, 0xff);
  26186. + rt2x00_set_field32(&reg, FRC_WL_ANT_SET, 1);
  26187. + rt2x00_set_field32(&reg, WLAN_CLK_EN, 0);
  26188. + rt2x00_set_field32(&reg, WLAN_EN, 1);
  26189. + rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
  26190. +
  26191. + udelay(REGISTER_BUSY_DELAY);
  26192. +
  26193. + count = 0;
  26194. + do {
  26195. + /*
  26196. + * Check PLL_LD & XTAL_RDY.
  26197. + */
  26198. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  26199. + rt2800_register_read(rt2x00dev, CMB_CTRL, &reg);
  26200. + if (rt2x00_get_field32(reg, PLL_LD) &&
  26201. + rt2x00_get_field32(reg, XTAL_RDY))
  26202. + break;
  26203. + udelay(REGISTER_BUSY_DELAY);
  26204. + }
  26205. +
  26206. + if (i >= REGISTER_BUSY_COUNT) {
  26207. +
  26208. + if (count >= 10)
  26209. + return -EIO;
  26210. +
  26211. + rt2800_register_write(rt2x00dev, 0x58, 0x018);
  26212. + udelay(REGISTER_BUSY_DELAY);
  26213. + rt2800_register_write(rt2x00dev, 0x58, 0x418);
  26214. + udelay(REGISTER_BUSY_DELAY);
  26215. + rt2800_register_write(rt2x00dev, 0x58, 0x618);
  26216. + udelay(REGISTER_BUSY_DELAY);
  26217. + count++;
  26218. + } else {
  26219. + count = 0;
  26220. + }
  26221. +
  26222. + rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
  26223. + rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 0);
  26224. + rt2x00_set_field32(&reg, WLAN_CLK_EN, 1);
  26225. + rt2x00_set_field32(&reg, WLAN_RESET, 1);
  26226. + rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
  26227. + udelay(10);
  26228. + rt2x00_set_field32(&reg, WLAN_RESET, 0);
  26229. + rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
  26230. + udelay(10);
  26231. + rt2800_register_write(rt2x00dev, INT_SOURCE_CSR, 0x7fffffff);
  26232. + } while (count != 0);
  26233. +
  26234. + return 0;
  26235. +}
  26236. +
  26237. +void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
  26238. + const u8 command, const u8 token,
  26239. + const u8 arg0, const u8 arg1)
  26240. +{
  26241. + u32 reg;
  26242. +
  26243. + /*
  26244. + * SOC devices don't support MCU requests.
  26245. + */
  26246. + if (rt2x00_is_soc(rt2x00dev))
  26247. + return;
  26248. +
  26249. + mutex_lock(&rt2x00dev->csr_mutex);
  26250. +
  26251. + /*
  26252. + * Wait until the MCU becomes available, afterwards we
  26253. + * can safely write the new data into the register.
  26254. + */
  26255. + if (WAIT_FOR_MCU(rt2x00dev, &reg)) {
  26256. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  26257. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  26258. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  26259. + rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  26260. + rt2800_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
  26261. +
  26262. + reg = 0;
  26263. + rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  26264. + rt2800_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
  26265. + }
  26266. +
  26267. + mutex_unlock(&rt2x00dev->csr_mutex);
  26268. +}
  26269. +EXPORT_SYMBOL_GPL(rt2800_mcu_request);
  26270. +
  26271. +int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev)
  26272. +{
  26273. + unsigned int i = 0;
  26274. + u32 reg;
  26275. +
  26276. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  26277. + rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  26278. + if (reg && reg != ~0)
  26279. + return 0;
  26280. + msleep(1);
  26281. + }
  26282. +
  26283. + rt2x00_err(rt2x00dev, "Unstable hardware\n");
  26284. + return -EBUSY;
  26285. +}
  26286. +EXPORT_SYMBOL_GPL(rt2800_wait_csr_ready);
  26287. +
  26288. +int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
  26289. +{
  26290. + unsigned int i;
  26291. + u32 reg;
  26292. +
  26293. + /*
  26294. + * Some devices are really slow to respond here. Wait a whole second
  26295. + * before timing out.
  26296. + */
  26297. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  26298. + rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  26299. + if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
  26300. + !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
  26301. + return 0;
  26302. +
  26303. + msleep(10);
  26304. + }
  26305. +
  26306. + rt2x00_err(rt2x00dev, "WPDMA TX/RX busy [0x%08x]\n", reg);
  26307. + return -EACCES;
  26308. +}
  26309. +EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
  26310. +
  26311. +void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
  26312. +{
  26313. + u32 reg;
  26314. +
  26315. + rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  26316. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  26317. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  26318. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  26319. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  26320. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  26321. + rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  26322. +}
  26323. +EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
  26324. +
  26325. +static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
  26326. +{
  26327. + u16 fw_crc;
  26328. + u16 crc;
  26329. +
  26330. + /*
  26331. + * The last 2 bytes in the firmware array are the crc checksum itself,
  26332. + * this means that we should never pass those 2 bytes to the crc
  26333. + * algorithm.
  26334. + */
  26335. + fw_crc = (data[len - 2] << 8 | data[len - 1]);
  26336. +
  26337. + /*
  26338. + * Use the crc ccitt algorithm.
  26339. + * This will return the same value as the legacy driver which
  26340. + * used bit ordering reversion on the both the firmware bytes
  26341. + * before input input as well as on the final output.
  26342. + * Obviously using crc ccitt directly is much more efficient.
  26343. + */
  26344. + crc = crc_ccitt(~0, data, len - 2);
  26345. +
  26346. + /*
  26347. + * There is a small difference between the crc-itu-t + bitrev and
  26348. + * the crc-ccitt crc calculation. In the latter method the 2 bytes
  26349. + * will be swapped, use swab16 to convert the crc to the correct
  26350. + * value.
  26351. + */
  26352. + crc = swab16(crc);
  26353. +
  26354. + return fw_crc == crc;
  26355. +}
  26356. +
  26357. +int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
  26358. + const u8 *data, const size_t len)
  26359. +{
  26360. + size_t offset = 0;
  26361. + size_t fw_len;
  26362. + bool multiple;
  26363. +
  26364. + /*
  26365. + * PCI(e) & SOC devices require firmware with a length
  26366. + * of 8kb. USB devices require firmware files with a length
  26367. + * of 4kb. Certain USB chipsets however require different firmware,
  26368. + * which Ralink only provides attached to the original firmware
  26369. + * file. Thus for USB devices, firmware files have a length
  26370. + * which is a multiple of 4kb. The firmware for rt3290 chip also
  26371. + * have a length which is a multiple of 4kb.
  26372. + */
  26373. + if (rt2x00_is_usb(rt2x00dev) || rt2x00_rt(rt2x00dev, RT3290))
  26374. + fw_len = 4096;
  26375. + else
  26376. + fw_len = 8192;
  26377. +
  26378. + multiple = true;
  26379. + /*
  26380. + * Validate the firmware length
  26381. + */
  26382. + if (len != fw_len && (!multiple || (len % fw_len) != 0))
  26383. + return FW_BAD_LENGTH;
  26384. +
  26385. + /*
  26386. + * Check if the chipset requires one of the upper parts
  26387. + * of the firmware.
  26388. + */
  26389. + if (rt2x00_is_usb(rt2x00dev) &&
  26390. + !rt2x00_rt(rt2x00dev, RT2860) &&
  26391. + !rt2x00_rt(rt2x00dev, RT2872) &&
  26392. + !rt2x00_rt(rt2x00dev, RT3070) &&
  26393. + ((len / fw_len) == 1))
  26394. + return FW_BAD_VERSION;
  26395. +
  26396. + /*
  26397. + * 8kb firmware files must be checked as if it were
  26398. + * 2 separate firmware files.
  26399. + */
  26400. + while (offset < len) {
  26401. + if (!rt2800_check_firmware_crc(data + offset, fw_len))
  26402. + return FW_BAD_CRC;
  26403. +
  26404. + offset += fw_len;
  26405. + }
  26406. +
  26407. + return FW_OK;
  26408. +}
  26409. +EXPORT_SYMBOL_GPL(rt2800_check_firmware);
  26410. +
  26411. +int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
  26412. + const u8 *data, const size_t len)
  26413. +{
  26414. + unsigned int i;
  26415. + u32 reg;
  26416. + int retval;
  26417. +
  26418. + if (rt2x00_rt(rt2x00dev, RT3290)) {
  26419. + retval = rt2800_enable_wlan_rt3290(rt2x00dev);
  26420. + if (retval)
  26421. + return -EBUSY;
  26422. + }
  26423. +
  26424. + /*
  26425. + * If driver doesn't wake up firmware here,
  26426. + * rt2800_load_firmware will hang forever when interface is up again.
  26427. + */
  26428. + rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0x00000000);
  26429. +
  26430. + /*
  26431. + * Wait for stable hardware.
  26432. + */
  26433. + if (rt2800_wait_csr_ready(rt2x00dev))
  26434. + return -EBUSY;
  26435. +
  26436. + if (rt2x00_is_pci(rt2x00dev)) {
  26437. + if (rt2x00_rt(rt2x00dev, RT3290) ||
  26438. + rt2x00_rt(rt2x00dev, RT3572) ||
  26439. + rt2x00_rt(rt2x00dev, RT5390) ||
  26440. + rt2x00_rt(rt2x00dev, RT5392)) {
  26441. + rt2800_register_read(rt2x00dev, AUX_CTRL, &reg);
  26442. + rt2x00_set_field32(&reg, AUX_CTRL_FORCE_PCIE_CLK, 1);
  26443. + rt2x00_set_field32(&reg, AUX_CTRL_WAKE_PCIE_EN, 1);
  26444. + rt2800_register_write(rt2x00dev, AUX_CTRL, reg);
  26445. + }
  26446. + rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
  26447. + }
  26448. +
  26449. + rt2800_disable_wpdma(rt2x00dev);
  26450. +
  26451. + /*
  26452. + * Write firmware to the device.
  26453. + */
  26454. + rt2800_drv_write_firmware(rt2x00dev, data, len);
  26455. +
  26456. + /*
  26457. + * Wait for device to stabilize.
  26458. + */
  26459. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  26460. + rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, &reg);
  26461. + if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
  26462. + break;
  26463. + msleep(1);
  26464. + }
  26465. +
  26466. + if (i == REGISTER_BUSY_COUNT) {
  26467. + rt2x00_err(rt2x00dev, "PBF system register not ready\n");
  26468. + return -EBUSY;
  26469. + }
  26470. +
  26471. + /*
  26472. + * Disable DMA, will be reenabled later when enabling
  26473. + * the radio.
  26474. + */
  26475. + rt2800_disable_wpdma(rt2x00dev);
  26476. +
  26477. + /*
  26478. + * Initialize firmware.
  26479. + */
  26480. + rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  26481. + rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  26482. + if (rt2x00_is_usb(rt2x00dev)) {
  26483. + rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
  26484. + rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
  26485. + }
  26486. + msleep(1);
  26487. +
  26488. + return 0;
  26489. +}
  26490. +EXPORT_SYMBOL_GPL(rt2800_load_firmware);
  26491. +
  26492. +void rt2800_write_tx_data(struct queue_entry *entry,
  26493. + struct txentry_desc *txdesc)
  26494. +{
  26495. + __le32 *txwi = rt2800_drv_get_txwi(entry);
  26496. + u32 word;
  26497. + int i;
  26498. +
  26499. + /*
  26500. + * Initialize TX Info descriptor
  26501. + */
  26502. + rt2x00_desc_read(txwi, 0, &word);
  26503. + rt2x00_set_field32(&word, TXWI_W0_FRAG,
  26504. + test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  26505. + rt2x00_set_field32(&word, TXWI_W0_MIMO_PS,
  26506. + test_bit(ENTRY_TXD_HT_MIMO_PS, &txdesc->flags));
  26507. + rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
  26508. + rt2x00_set_field32(&word, TXWI_W0_TS,
  26509. + test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  26510. + rt2x00_set_field32(&word, TXWI_W0_AMPDU,
  26511. + test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
  26512. + rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY,
  26513. + txdesc->u.ht.mpdu_density);
  26514. + rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->u.ht.txop);
  26515. + rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->u.ht.mcs);
  26516. + rt2x00_set_field32(&word, TXWI_W0_BW,
  26517. + test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
  26518. + rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
  26519. + test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
  26520. + rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->u.ht.stbc);
  26521. + rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
  26522. + rt2x00_desc_write(txwi, 0, word);
  26523. +
  26524. + rt2x00_desc_read(txwi, 1, &word);
  26525. + rt2x00_set_field32(&word, TXWI_W1_ACK,
  26526. + test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  26527. + rt2x00_set_field32(&word, TXWI_W1_NSEQ,
  26528. + test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  26529. + rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->u.ht.ba_size);
  26530. + rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
  26531. + test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
  26532. + txdesc->key_idx : txdesc->u.ht.wcid);
  26533. + rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
  26534. + txdesc->length);
  26535. + rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
  26536. + rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
  26537. + rt2x00_desc_write(txwi, 1, word);
  26538. +
  26539. + /*
  26540. + * Always write 0 to IV/EIV fields (word 2 and 3), hardware will insert
  26541. + * the IV from the IVEIV register when TXD_W3_WIV is set to 0.
  26542. + * When TXD_W3_WIV is set to 1 it will use the IV data
  26543. + * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
  26544. + * crypto entry in the registers should be used to encrypt the frame.
  26545. + *
  26546. + * Nulify all remaining words as well, we don't know how to program them.
  26547. + */
  26548. + for (i = 2; i < entry->queue->winfo_size / sizeof(__le32); i++)
  26549. + _rt2x00_desc_write(txwi, i, 0);
  26550. +}
  26551. +EXPORT_SYMBOL_GPL(rt2800_write_tx_data);
  26552. +
  26553. +static int rt2800_agc_to_rssi(struct rt2x00_dev *rt2x00dev, u32 rxwi_w2)
  26554. +{
  26555. + s8 rssi0 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI0);
  26556. + s8 rssi1 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI1);
  26557. + s8 rssi2 = rt2x00_get_field32(rxwi_w2, RXWI_W2_RSSI2);
  26558. + u16 eeprom;
  26559. + u8 offset0;
  26560. + u8 offset1;
  26561. + u8 offset2;
  26562. +
  26563. + if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  26564. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &eeprom);
  26565. + offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET0);
  26566. + offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG_OFFSET1);
  26567. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
  26568. + offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_OFFSET2);
  26569. + } else {
  26570. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &eeprom);
  26571. + offset0 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET0);
  26572. + offset1 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A_OFFSET1);
  26573. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
  26574. + offset2 = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_OFFSET2);
  26575. + }
  26576. +
  26577. + /*
  26578. + * Convert the value from the descriptor into the RSSI value
  26579. + * If the value in the descriptor is 0, it is considered invalid
  26580. + * and the default (extremely low) rssi value is assumed
  26581. + */
  26582. + rssi0 = (rssi0) ? (-12 - offset0 - rt2x00dev->lna_gain - rssi0) : -128;
  26583. + rssi1 = (rssi1) ? (-12 - offset1 - rt2x00dev->lna_gain - rssi1) : -128;
  26584. + rssi2 = (rssi2) ? (-12 - offset2 - rt2x00dev->lna_gain - rssi2) : -128;
  26585. +
  26586. + /*
  26587. + * mac80211 only accepts a single RSSI value. Calculating the
  26588. + * average doesn't deliver a fair answer either since -60:-60 would
  26589. + * be considered equally good as -50:-70 while the second is the one
  26590. + * which gives less energy...
  26591. + */
  26592. + rssi0 = max(rssi0, rssi1);
  26593. + return (int)max(rssi0, rssi2);
  26594. +}
  26595. +
  26596. +void rt2800_process_rxwi(struct queue_entry *entry,
  26597. + struct rxdone_entry_desc *rxdesc)
  26598. +{
  26599. + __le32 *rxwi = (__le32 *) entry->skb->data;
  26600. + u32 word;
  26601. +
  26602. + rt2x00_desc_read(rxwi, 0, &word);
  26603. +
  26604. + rxdesc->cipher = rt2x00_get_field32(word, RXWI_W0_UDF);
  26605. + rxdesc->size = rt2x00_get_field32(word, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
  26606. +
  26607. + rt2x00_desc_read(rxwi, 1, &word);
  26608. +
  26609. + if (rt2x00_get_field32(word, RXWI_W1_SHORT_GI))
  26610. + rxdesc->flags |= RX_FLAG_SHORT_GI;
  26611. +
  26612. + if (rt2x00_get_field32(word, RXWI_W1_BW))
  26613. + rxdesc->flags |= RX_FLAG_40MHZ;
  26614. +
  26615. + /*
  26616. + * Detect RX rate, always use MCS as signal type.
  26617. + */
  26618. + rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
  26619. + rxdesc->signal = rt2x00_get_field32(word, RXWI_W1_MCS);
  26620. + rxdesc->rate_mode = rt2x00_get_field32(word, RXWI_W1_PHYMODE);
  26621. +
  26622. + /*
  26623. + * Mask of 0x8 bit to remove the short preamble flag.
  26624. + */
  26625. + if (rxdesc->rate_mode == RATE_MODE_CCK)
  26626. + rxdesc->signal &= ~0x8;
  26627. +
  26628. + rt2x00_desc_read(rxwi, 2, &word);
  26629. +
  26630. + /*
  26631. + * Convert descriptor AGC value to RSSI value.
  26632. + */
  26633. + rxdesc->rssi = rt2800_agc_to_rssi(entry->queue->rt2x00dev, word);
  26634. + /*
  26635. + * Remove RXWI descriptor from start of the buffer.
  26636. + */
  26637. + skb_pull(entry->skb, entry->queue->winfo_size);
  26638. +}
  26639. +EXPORT_SYMBOL_GPL(rt2800_process_rxwi);
  26640. +
  26641. +void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi)
  26642. +{
  26643. + struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  26644. + struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  26645. + struct txdone_entry_desc txdesc;
  26646. + u32 word;
  26647. + u16 mcs, real_mcs;
  26648. + int aggr, ampdu;
  26649. +
  26650. + /*
  26651. + * Obtain the status about this packet.
  26652. + */
  26653. + txdesc.flags = 0;
  26654. + rt2x00_desc_read(txwi, 0, &word);
  26655. +
  26656. + mcs = rt2x00_get_field32(word, TXWI_W0_MCS);
  26657. + ampdu = rt2x00_get_field32(word, TXWI_W0_AMPDU);
  26658. +
  26659. + real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
  26660. + aggr = rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE);
  26661. +
  26662. + /*
  26663. + * If a frame was meant to be sent as a single non-aggregated MPDU
  26664. + * but ended up in an aggregate the used tx rate doesn't correlate
  26665. + * with the one specified in the TXWI as the whole aggregate is sent
  26666. + * with the same rate.
  26667. + *
  26668. + * For example: two frames are sent to rt2x00, the first one sets
  26669. + * AMPDU=1 and requests MCS7 whereas the second frame sets AMDPU=0
  26670. + * and requests MCS15. If the hw aggregates both frames into one
  26671. + * AMDPU the tx status for both frames will contain MCS7 although
  26672. + * the frame was sent successfully.
  26673. + *
  26674. + * Hence, replace the requested rate with the real tx rate to not
  26675. + * confuse the rate control algortihm by providing clearly wrong
  26676. + * data.
  26677. + */
  26678. + if (unlikely(aggr == 1 && ampdu == 0 && real_mcs != mcs)) {
  26679. + skbdesc->tx_rate_idx = real_mcs;
  26680. + mcs = real_mcs;
  26681. + }
  26682. +
  26683. + if (aggr == 1 || ampdu == 1)
  26684. + __set_bit(TXDONE_AMPDU, &txdesc.flags);
  26685. +
  26686. + /*
  26687. + * Ralink has a retry mechanism using a global fallback
  26688. + * table. We setup this fallback table to try the immediate
  26689. + * lower rate for all rates. In the TX_STA_FIFO, the MCS field
  26690. + * always contains the MCS used for the last transmission, be
  26691. + * it successful or not.
  26692. + */
  26693. + if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
  26694. + /*
  26695. + * Transmission succeeded. The number of retries is
  26696. + * mcs - real_mcs
  26697. + */
  26698. + __set_bit(TXDONE_SUCCESS, &txdesc.flags);
  26699. + txdesc.retry = ((mcs > real_mcs) ? mcs - real_mcs : 0);
  26700. + } else {
  26701. + /*
  26702. + * Transmission failed. The number of retries is
  26703. + * always 7 in this case (for a total number of 8
  26704. + * frames sent).
  26705. + */
  26706. + __set_bit(TXDONE_FAILURE, &txdesc.flags);
  26707. + txdesc.retry = rt2x00dev->long_retry;
  26708. + }
  26709. +
  26710. + /*
  26711. + * the frame was retried at least once
  26712. + * -> hw used fallback rates
  26713. + */
  26714. + if (txdesc.retry)
  26715. + __set_bit(TXDONE_FALLBACK, &txdesc.flags);
  26716. +
  26717. + rt2x00lib_txdone(entry, &txdesc);
  26718. +}
  26719. +EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
  26720. +
  26721. +void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc)
  26722. +{
  26723. + struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  26724. + struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  26725. + unsigned int beacon_base;
  26726. + unsigned int padding_len;
  26727. + u32 orig_reg, reg;
  26728. + const int txwi_desc_size = entry->queue->winfo_size;
  26729. +
  26730. + /*
  26731. + * Disable beaconing while we are reloading the beacon data,
  26732. + * otherwise we might be sending out invalid data.
  26733. + */
  26734. + rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  26735. + orig_reg = reg;
  26736. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  26737. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  26738. +
  26739. + /*
  26740. + * Add space for the TXWI in front of the skb.
  26741. + */
  26742. + memset(skb_push(entry->skb, txwi_desc_size), 0, txwi_desc_size);
  26743. +
  26744. + /*
  26745. + * Register descriptor details in skb frame descriptor.
  26746. + */
  26747. + skbdesc->flags |= SKBDESC_DESC_IN_SKB;
  26748. + skbdesc->desc = entry->skb->data;
  26749. + skbdesc->desc_len = txwi_desc_size;
  26750. +
  26751. + /*
  26752. + * Add the TXWI for the beacon to the skb.
  26753. + */
  26754. + rt2800_write_tx_data(entry, txdesc);
  26755. +
  26756. + /*
  26757. + * Dump beacon to userspace through debugfs.
  26758. + */
  26759. + rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
  26760. +
  26761. + /*
  26762. + * Write entire beacon with TXWI and padding to register.
  26763. + */
  26764. + padding_len = roundup(entry->skb->len, 4) - entry->skb->len;
  26765. + if (padding_len && skb_pad(entry->skb, padding_len)) {
  26766. + rt2x00_err(rt2x00dev, "Failure padding beacon, aborting\n");
  26767. + /* skb freed by skb_pad() on failure */
  26768. + entry->skb = NULL;
  26769. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, orig_reg);
  26770. + return;
  26771. + }
  26772. +
  26773. + beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  26774. + rt2800_register_multiwrite(rt2x00dev, beacon_base, entry->skb->data,
  26775. + entry->skb->len + padding_len);
  26776. +
  26777. + /*
  26778. + * Enable beaconing again.
  26779. + */
  26780. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  26781. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  26782. +
  26783. + /*
  26784. + * Clean up beacon skb.
  26785. + */
  26786. + dev_kfree_skb_any(entry->skb);
  26787. + entry->skb = NULL;
  26788. +}
  26789. +EXPORT_SYMBOL_GPL(rt2800_write_beacon);
  26790. +
  26791. +static inline void rt2800_clear_beacon_register(struct rt2x00_dev *rt2x00dev,
  26792. + unsigned int beacon_base)
  26793. +{
  26794. + int i;
  26795. + const int txwi_desc_size = rt2x00dev->bcn->winfo_size;
  26796. +
  26797. + /*
  26798. + * For the Beacon base registers we only need to clear
  26799. + * the whole TXWI which (when set to 0) will invalidate
  26800. + * the entire beacon.
  26801. + */
  26802. + for (i = 0; i < txwi_desc_size; i += sizeof(__le32))
  26803. + rt2800_register_write(rt2x00dev, beacon_base + i, 0);
  26804. +}
  26805. +
  26806. +void rt2800_clear_beacon(struct queue_entry *entry)
  26807. +{
  26808. + struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  26809. + u32 reg;
  26810. +
  26811. + /*
  26812. + * Disable beaconing while we are reloading the beacon data,
  26813. + * otherwise we might be sending out invalid data.
  26814. + */
  26815. + rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  26816. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  26817. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  26818. +
  26819. + /*
  26820. + * Clear beacon.
  26821. + */
  26822. + rt2800_clear_beacon_register(rt2x00dev,
  26823. + HW_BEACON_OFFSET(entry->entry_idx));
  26824. +
  26825. + /*
  26826. + * Enabled beaconing again.
  26827. + */
  26828. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 1);
  26829. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  26830. +}
  26831. +EXPORT_SYMBOL_GPL(rt2800_clear_beacon);
  26832. +
  26833. +#ifdef CONFIG_RT2X00_LIB_DEBUGFS
  26834. +const struct rt2x00debug rt2800_rt2x00debug = {
  26835. + .owner = THIS_MODULE,
  26836. + .csr = {
  26837. + .read = rt2800_register_read,
  26838. + .write = rt2800_register_write,
  26839. + .flags = RT2X00DEBUGFS_OFFSET,
  26840. + .word_base = CSR_REG_BASE,
  26841. + .word_size = sizeof(u32),
  26842. + .word_count = CSR_REG_SIZE / sizeof(u32),
  26843. + },
  26844. + .eeprom = {
  26845. + .read = rt2x00_eeprom_read,
  26846. + .write = rt2x00_eeprom_write,
  26847. + .word_base = EEPROM_BASE,
  26848. + .word_size = sizeof(u16),
  26849. + .word_count = EEPROM_SIZE / sizeof(u16),
  26850. + },
  26851. + .bbp = {
  26852. + .read = rt2800_bbp_read,
  26853. + .write = rt2800_bbp_write,
  26854. + .word_base = BBP_BASE,
  26855. + .word_size = sizeof(u8),
  26856. + .word_count = BBP_SIZE / sizeof(u8),
  26857. + },
  26858. + .rf = {
  26859. + .read = rt2x00_rf_read,
  26860. + .write = rt2800_rf_write,
  26861. + .word_base = RF_BASE,
  26862. + .word_size = sizeof(u32),
  26863. + .word_count = RF_SIZE / sizeof(u32),
  26864. + },
  26865. + .rfcsr = {
  26866. + .read = rt2800_rfcsr_read,
  26867. + .write = rt2800_rfcsr_write,
  26868. + .word_base = RFCSR_BASE,
  26869. + .word_size = sizeof(u8),
  26870. + .word_count = RFCSR_SIZE / sizeof(u8),
  26871. + },
  26872. +};
  26873. +EXPORT_SYMBOL_GPL(rt2800_rt2x00debug);
  26874. +#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  26875. +
  26876. +int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  26877. +{
  26878. + u32 reg;
  26879. +
  26880. + if (rt2x00_rt(rt2x00dev, RT3290)) {
  26881. + rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
  26882. + return rt2x00_get_field32(reg, WLAN_GPIO_IN_BIT0);
  26883. + } else {
  26884. + rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
  26885. + return rt2x00_get_field32(reg, GPIO_CTRL_VAL2);
  26886. + }
  26887. +}
  26888. +EXPORT_SYMBOL_GPL(rt2800_rfkill_poll);
  26889. +
  26890. +#ifdef CONFIG_RT2X00_LIB_LEDS
  26891. +static void rt2800_brightness_set(struct led_classdev *led_cdev,
  26892. + enum led_brightness brightness)
  26893. +{
  26894. + struct rt2x00_led *led =
  26895. + container_of(led_cdev, struct rt2x00_led, led_dev);
  26896. + unsigned int enabled = brightness != LED_OFF;
  26897. + unsigned int bg_mode =
  26898. + (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  26899. + unsigned int polarity =
  26900. + rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  26901. + EEPROM_FREQ_LED_POLARITY);
  26902. + unsigned int ledmode =
  26903. + rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
  26904. + EEPROM_FREQ_LED_MODE);
  26905. + u32 reg;
  26906. +
  26907. + /* Check for SoC (SOC devices don't support MCU requests) */
  26908. + if (rt2x00_is_soc(led->rt2x00dev)) {
  26909. + rt2800_register_read(led->rt2x00dev, LED_CFG, &reg);
  26910. +
  26911. + /* Set LED Polarity */
  26912. + rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, polarity);
  26913. +
  26914. + /* Set LED Mode */
  26915. + if (led->type == LED_TYPE_RADIO) {
  26916. + rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE,
  26917. + enabled ? 3 : 0);
  26918. + } else if (led->type == LED_TYPE_ASSOC) {
  26919. + rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE,
  26920. + enabled ? 3 : 0);
  26921. + } else if (led->type == LED_TYPE_QUALITY) {
  26922. + rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE,
  26923. + enabled ? 3 : 0);
  26924. + }
  26925. +
  26926. + rt2800_register_write(led->rt2x00dev, LED_CFG, reg);
  26927. +
  26928. + } else {
  26929. + if (led->type == LED_TYPE_RADIO) {
  26930. + rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  26931. + enabled ? 0x20 : 0);
  26932. + } else if (led->type == LED_TYPE_ASSOC) {
  26933. + rt2800_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
  26934. + enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
  26935. + } else if (led->type == LED_TYPE_QUALITY) {
  26936. + /*
  26937. + * The brightness is divided into 6 levels (0 - 5),
  26938. + * The specs tell us the following levels:
  26939. + * 0, 1 ,3, 7, 15, 31
  26940. + * to determine the level in a simple way we can simply
  26941. + * work with bitshifting:
  26942. + * (1 << level) - 1
  26943. + */
  26944. + rt2800_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  26945. + (1 << brightness / (LED_FULL / 6)) - 1,
  26946. + polarity);
  26947. + }
  26948. + }
  26949. +}
  26950. +
  26951. +static void rt2800_init_led(struct rt2x00_dev *rt2x00dev,
  26952. + struct rt2x00_led *led, enum led_type type)
  26953. +{
  26954. + led->rt2x00dev = rt2x00dev;
  26955. + led->type = type;
  26956. + led->led_dev.brightness_set = rt2800_brightness_set;
  26957. + led->flags = LED_INITIALIZED;
  26958. +}
  26959. +#endif /* CONFIG_RT2X00_LIB_LEDS */
  26960. +
  26961. +/*
  26962. + * Configuration handlers.
  26963. + */
  26964. +static void rt2800_config_wcid(struct rt2x00_dev *rt2x00dev,
  26965. + const u8 *address,
  26966. + int wcid)
  26967. +{
  26968. + struct mac_wcid_entry wcid_entry;
  26969. + u32 offset;
  26970. +
  26971. + offset = MAC_WCID_ENTRY(wcid);
  26972. +
  26973. + memset(&wcid_entry, 0xff, sizeof(wcid_entry));
  26974. + if (address)
  26975. + memcpy(wcid_entry.mac, address, ETH_ALEN);
  26976. +
  26977. + rt2800_register_multiwrite(rt2x00dev, offset,
  26978. + &wcid_entry, sizeof(wcid_entry));
  26979. +}
  26980. +
  26981. +static void rt2800_delete_wcid_attr(struct rt2x00_dev *rt2x00dev, int wcid)
  26982. +{
  26983. + u32 offset;
  26984. + offset = MAC_WCID_ATTR_ENTRY(wcid);
  26985. + rt2800_register_write(rt2x00dev, offset, 0);
  26986. +}
  26987. +
  26988. +static void rt2800_config_wcid_attr_bssidx(struct rt2x00_dev *rt2x00dev,
  26989. + int wcid, u32 bssidx)
  26990. +{
  26991. + u32 offset = MAC_WCID_ATTR_ENTRY(wcid);
  26992. + u32 reg;
  26993. +
  26994. + /*
  26995. + * The BSS Idx numbers is split in a main value of 3 bits,
  26996. + * and a extended field for adding one additional bit to the value.
  26997. + */
  26998. + rt2800_register_read(rt2x00dev, offset, &reg);
  26999. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX, (bssidx & 0x7));
  27000. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_BSS_IDX_EXT,
  27001. + (bssidx & 0x8) >> 3);
  27002. + rt2800_register_write(rt2x00dev, offset, reg);
  27003. +}
  27004. +
  27005. +static void rt2800_config_wcid_attr_cipher(struct rt2x00_dev *rt2x00dev,
  27006. + struct rt2x00lib_crypto *crypto,
  27007. + struct ieee80211_key_conf *key)
  27008. +{
  27009. + struct mac_iveiv_entry iveiv_entry;
  27010. + u32 offset;
  27011. + u32 reg;
  27012. +
  27013. + offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
  27014. +
  27015. + if (crypto->cmd == SET_KEY) {
  27016. + rt2800_register_read(rt2x00dev, offset, &reg);
  27017. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB,
  27018. + !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
  27019. + /*
  27020. + * Both the cipher as the BSS Idx numbers are split in a main
  27021. + * value of 3 bits, and a extended field for adding one additional
  27022. + * bit to the value.
  27023. + */
  27024. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER,
  27025. + (crypto->cipher & 0x7));
  27026. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT,
  27027. + (crypto->cipher & 0x8) >> 3);
  27028. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
  27029. + rt2800_register_write(rt2x00dev, offset, reg);
  27030. + } else {
  27031. + /* Delete the cipher without touching the bssidx */
  27032. + rt2800_register_read(rt2x00dev, offset, &reg);
  27033. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_KEYTAB, 0);
  27034. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER, 0);
  27035. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_CIPHER_EXT, 0);
  27036. + rt2x00_set_field32(&reg, MAC_WCID_ATTRIBUTE_RX_WIUDF, 0);
  27037. + rt2800_register_write(rt2x00dev, offset, reg);
  27038. + }
  27039. +
  27040. + offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
  27041. +
  27042. + memset(&iveiv_entry, 0, sizeof(iveiv_entry));
  27043. + if ((crypto->cipher == CIPHER_TKIP) ||
  27044. + (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
  27045. + (crypto->cipher == CIPHER_AES))
  27046. + iveiv_entry.iv[3] |= 0x20;
  27047. + iveiv_entry.iv[3] |= key->keyidx << 6;
  27048. + rt2800_register_multiwrite(rt2x00dev, offset,
  27049. + &iveiv_entry, sizeof(iveiv_entry));
  27050. +}
  27051. +
  27052. +int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
  27053. + struct rt2x00lib_crypto *crypto,
  27054. + struct ieee80211_key_conf *key)
  27055. +{
  27056. + struct hw_key_entry key_entry;
  27057. + struct rt2x00_field32 field;
  27058. + u32 offset;
  27059. + u32 reg;
  27060. +
  27061. + if (crypto->cmd == SET_KEY) {
  27062. + key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
  27063. +
  27064. + memcpy(key_entry.key, crypto->key,
  27065. + sizeof(key_entry.key));
  27066. + memcpy(key_entry.tx_mic, crypto->tx_mic,
  27067. + sizeof(key_entry.tx_mic));
  27068. + memcpy(key_entry.rx_mic, crypto->rx_mic,
  27069. + sizeof(key_entry.rx_mic));
  27070. +
  27071. + offset = SHARED_KEY_ENTRY(key->hw_key_idx);
  27072. + rt2800_register_multiwrite(rt2x00dev, offset,
  27073. + &key_entry, sizeof(key_entry));
  27074. + }
  27075. +
  27076. + /*
  27077. + * The cipher types are stored over multiple registers
  27078. + * starting with SHARED_KEY_MODE_BASE each word will have
  27079. + * 32 bits and contains the cipher types for 2 bssidx each.
  27080. + * Using the correct defines correctly will cause overhead,
  27081. + * so just calculate the correct offset.
  27082. + */
  27083. + field.bit_offset = 4 * (key->hw_key_idx % 8);
  27084. + field.bit_mask = 0x7 << field.bit_offset;
  27085. +
  27086. + offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
  27087. +
  27088. + rt2800_register_read(rt2x00dev, offset, &reg);
  27089. + rt2x00_set_field32(&reg, field,
  27090. + (crypto->cmd == SET_KEY) * crypto->cipher);
  27091. + rt2800_register_write(rt2x00dev, offset, reg);
  27092. +
  27093. + /*
  27094. + * Update WCID information
  27095. + */
  27096. + rt2800_config_wcid(rt2x00dev, crypto->address, key->hw_key_idx);
  27097. + rt2800_config_wcid_attr_bssidx(rt2x00dev, key->hw_key_idx,
  27098. + crypto->bssidx);
  27099. + rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
  27100. +
  27101. + return 0;
  27102. +}
  27103. +EXPORT_SYMBOL_GPL(rt2800_config_shared_key);
  27104. +
  27105. +static inline int rt2800_find_wcid(struct rt2x00_dev *rt2x00dev)
  27106. +{
  27107. + struct mac_wcid_entry wcid_entry;
  27108. + int idx;
  27109. + u32 offset;
  27110. +
  27111. + /*
  27112. + * Search for the first free WCID entry and return the corresponding
  27113. + * index.
  27114. + *
  27115. + * Make sure the WCID starts _after_ the last possible shared key
  27116. + * entry (>32).
  27117. + *
  27118. + * Since parts of the pairwise key table might be shared with
  27119. + * the beacon frame buffers 6 & 7 we should only write into the
  27120. + * first 222 entries.
  27121. + */
  27122. + for (idx = 33; idx <= 222; idx++) {
  27123. + offset = MAC_WCID_ENTRY(idx);
  27124. + rt2800_register_multiread(rt2x00dev, offset, &wcid_entry,
  27125. + sizeof(wcid_entry));
  27126. + if (is_broadcast_ether_addr(wcid_entry.mac))
  27127. + return idx;
  27128. + }
  27129. +
  27130. + /*
  27131. + * Use -1 to indicate that we don't have any more space in the WCID
  27132. + * table.
  27133. + */
  27134. + return -1;
  27135. +}
  27136. +
  27137. +int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  27138. + struct rt2x00lib_crypto *crypto,
  27139. + struct ieee80211_key_conf *key)
  27140. +{
  27141. + struct hw_key_entry key_entry;
  27142. + u32 offset;
  27143. +
  27144. + if (crypto->cmd == SET_KEY) {
  27145. + /*
  27146. + * Allow key configuration only for STAs that are
  27147. + * known by the hw.
  27148. + */
  27149. + if (crypto->wcid < 0)
  27150. + return -ENOSPC;
  27151. + key->hw_key_idx = crypto->wcid;
  27152. +
  27153. + memcpy(key_entry.key, crypto->key,
  27154. + sizeof(key_entry.key));
  27155. + memcpy(key_entry.tx_mic, crypto->tx_mic,
  27156. + sizeof(key_entry.tx_mic));
  27157. + memcpy(key_entry.rx_mic, crypto->rx_mic,
  27158. + sizeof(key_entry.rx_mic));
  27159. +
  27160. + offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  27161. + rt2800_register_multiwrite(rt2x00dev, offset,
  27162. + &key_entry, sizeof(key_entry));
  27163. + }
  27164. +
  27165. + /*
  27166. + * Update WCID information
  27167. + */
  27168. + rt2800_config_wcid_attr_cipher(rt2x00dev, crypto, key);
  27169. +
  27170. + return 0;
  27171. +}
  27172. +EXPORT_SYMBOL_GPL(rt2800_config_pairwise_key);
  27173. +
  27174. +int rt2800_sta_add(struct rt2x00_dev *rt2x00dev, struct ieee80211_vif *vif,
  27175. + struct ieee80211_sta *sta)
  27176. +{
  27177. + int wcid;
  27178. + struct rt2x00_sta *sta_priv = sta_to_rt2x00_sta(sta);
  27179. +
  27180. + /*
  27181. + * Find next free WCID.
  27182. + */
  27183. + wcid = rt2800_find_wcid(rt2x00dev);
  27184. +
  27185. + /*
  27186. + * Store selected wcid even if it is invalid so that we can
  27187. + * later decide if the STA is uploaded into the hw.
  27188. + */
  27189. + sta_priv->wcid = wcid;
  27190. +
  27191. + /*
  27192. + * No space left in the device, however, we can still communicate
  27193. + * with the STA -> No error.
  27194. + */
  27195. + if (wcid < 0)
  27196. + return 0;
  27197. +
  27198. + /*
  27199. + * Clean up WCID attributes and write STA address to the device.
  27200. + */
  27201. + rt2800_delete_wcid_attr(rt2x00dev, wcid);
  27202. + rt2800_config_wcid(rt2x00dev, sta->addr, wcid);
  27203. + rt2800_config_wcid_attr_bssidx(rt2x00dev, wcid,
  27204. + rt2x00lib_get_bssidx(rt2x00dev, vif));
  27205. + return 0;
  27206. +}
  27207. +EXPORT_SYMBOL_GPL(rt2800_sta_add);
  27208. +
  27209. +int rt2800_sta_remove(struct rt2x00_dev *rt2x00dev, int wcid)
  27210. +{
  27211. + /*
  27212. + * Remove WCID entry, no need to clean the attributes as they will
  27213. + * get renewed when the WCID is reused.
  27214. + */
  27215. + rt2800_config_wcid(rt2x00dev, NULL, wcid);
  27216. +
  27217. + return 0;
  27218. +}
  27219. +EXPORT_SYMBOL_GPL(rt2800_sta_remove);
  27220. +
  27221. +void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
  27222. + const unsigned int filter_flags)
  27223. +{
  27224. + u32 reg;
  27225. +
  27226. + /*
  27227. + * Start configuration steps.
  27228. + * Note that the version error will always be dropped
  27229. + * and broadcast frames will always be accepted since
  27230. + * there is no filter for it at this time.
  27231. + */
  27232. + rt2800_register_read(rt2x00dev, RX_FILTER_CFG, &reg);
  27233. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CRC_ERROR,
  27234. + !(filter_flags & FIF_FCSFAIL));
  27235. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PHY_ERROR,
  27236. + !(filter_flags & FIF_PLCPFAIL));
  27237. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_TO_ME,
  27238. + !(filter_flags & FIF_PROMISC_IN_BSS));
  27239. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
  27240. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_VER_ERROR, 1);
  27241. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_MULTICAST,
  27242. + !(filter_flags & FIF_ALLMULTI));
  27243. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BROADCAST, 0);
  27244. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_DUPLICATE, 1);
  27245. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END_ACK,
  27246. + !(filter_flags & FIF_CONTROL));
  27247. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CF_END,
  27248. + !(filter_flags & FIF_CONTROL));
  27249. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_ACK,
  27250. + !(filter_flags & FIF_CONTROL));
  27251. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CTS,
  27252. + !(filter_flags & FIF_CONTROL));
  27253. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_RTS,
  27254. + !(filter_flags & FIF_CONTROL));
  27255. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_PSPOLL,
  27256. + !(filter_flags & FIF_PSPOLL));
  27257. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BA, 0);
  27258. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_BAR,
  27259. + !(filter_flags & FIF_CONTROL));
  27260. + rt2x00_set_field32(&reg, RX_FILTER_CFG_DROP_CNTL,
  27261. + !(filter_flags & FIF_CONTROL));
  27262. + rt2800_register_write(rt2x00dev, RX_FILTER_CFG, reg);
  27263. +}
  27264. +EXPORT_SYMBOL_GPL(rt2800_config_filter);
  27265. +
  27266. +void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
  27267. + struct rt2x00intf_conf *conf, const unsigned int flags)
  27268. +{
  27269. + u32 reg;
  27270. + bool update_bssid = false;
  27271. +
  27272. + if (flags & CONFIG_UPDATE_TYPE) {
  27273. + /*
  27274. + * Enable synchronisation.
  27275. + */
  27276. + rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  27277. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, conf->sync);
  27278. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  27279. +
  27280. + if (conf->sync == TSF_SYNC_AP_NONE) {
  27281. + /*
  27282. + * Tune beacon queue transmit parameters for AP mode
  27283. + */
  27284. + rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, &reg);
  27285. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 0);
  27286. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 1);
  27287. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
  27288. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 0);
  27289. + rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
  27290. + } else {
  27291. + rt2800_register_read(rt2x00dev, TBTT_SYNC_CFG, &reg);
  27292. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_CWMIN, 4);
  27293. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_AIFSN, 2);
  27294. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_BCN_EXP_WIN, 32);
  27295. + rt2x00_set_field32(&reg, TBTT_SYNC_CFG_TBTT_ADJUST, 16);
  27296. + rt2800_register_write(rt2x00dev, TBTT_SYNC_CFG, reg);
  27297. + }
  27298. + }
  27299. +
  27300. + if (flags & CONFIG_UPDATE_MAC) {
  27301. + if (flags & CONFIG_UPDATE_TYPE &&
  27302. + conf->sync == TSF_SYNC_AP_NONE) {
  27303. + /*
  27304. + * The BSSID register has to be set to our own mac
  27305. + * address in AP mode.
  27306. + */
  27307. + memcpy(conf->bssid, conf->mac, sizeof(conf->mac));
  27308. + update_bssid = true;
  27309. + }
  27310. +
  27311. + if (!is_zero_ether_addr((const u8 *)conf->mac)) {
  27312. + reg = le32_to_cpu(conf->mac[1]);
  27313. + rt2x00_set_field32(&reg, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
  27314. + conf->mac[1] = cpu_to_le32(reg);
  27315. + }
  27316. +
  27317. + rt2800_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
  27318. + conf->mac, sizeof(conf->mac));
  27319. + }
  27320. +
  27321. + if ((flags & CONFIG_UPDATE_BSSID) || update_bssid) {
  27322. + if (!is_zero_ether_addr((const u8 *)conf->bssid)) {
  27323. + reg = le32_to_cpu(conf->bssid[1]);
  27324. + rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_ID_MASK, 3);
  27325. + rt2x00_set_field32(&reg, MAC_BSSID_DW1_BSS_BCN_NUM, 7);
  27326. + conf->bssid[1] = cpu_to_le32(reg);
  27327. + }
  27328. +
  27329. + rt2800_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
  27330. + conf->bssid, sizeof(conf->bssid));
  27331. + }
  27332. +}
  27333. +EXPORT_SYMBOL_GPL(rt2800_config_intf);
  27334. +
  27335. +static void rt2800_config_ht_opmode(struct rt2x00_dev *rt2x00dev,
  27336. + struct rt2x00lib_erp *erp)
  27337. +{
  27338. + bool any_sta_nongf = !!(erp->ht_opmode &
  27339. + IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  27340. + u8 protection = erp->ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION;
  27341. + u8 mm20_mode, mm40_mode, gf20_mode, gf40_mode;
  27342. + u16 mm20_rate, mm40_rate, gf20_rate, gf40_rate;
  27343. + u32 reg;
  27344. +
  27345. + /* default protection rate for HT20: OFDM 24M */
  27346. + mm20_rate = gf20_rate = 0x4004;
  27347. +
  27348. + /* default protection rate for HT40: duplicate OFDM 24M */
  27349. + mm40_rate = gf40_rate = 0x4084;
  27350. +
  27351. + switch (protection) {
  27352. + case IEEE80211_HT_OP_MODE_PROTECTION_NONE:
  27353. + /*
  27354. + * All STAs in this BSS are HT20/40 but there might be
  27355. + * STAs not supporting greenfield mode.
  27356. + * => Disable protection for HT transmissions.
  27357. + */
  27358. + mm20_mode = mm40_mode = gf20_mode = gf40_mode = 0;
  27359. +
  27360. + break;
  27361. + case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  27362. + /*
  27363. + * All STAs in this BSS are HT20 or HT20/40 but there
  27364. + * might be STAs not supporting greenfield mode.
  27365. + * => Protect all HT40 transmissions.
  27366. + */
  27367. + mm20_mode = gf20_mode = 0;
  27368. + mm40_mode = gf40_mode = 2;
  27369. +
  27370. + break;
  27371. + case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER:
  27372. + /*
  27373. + * Nonmember protection:
  27374. + * According to 802.11n we _should_ protect all
  27375. + * HT transmissions (but we don't have to).
  27376. + *
  27377. + * But if cts_protection is enabled we _shall_ protect
  27378. + * all HT transmissions using a CCK rate.
  27379. + *
  27380. + * And if any station is non GF we _shall_ protect
  27381. + * GF transmissions.
  27382. + *
  27383. + * We decide to protect everything
  27384. + * -> fall through to mixed mode.
  27385. + */
  27386. + case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  27387. + /*
  27388. + * Legacy STAs are present
  27389. + * => Protect all HT transmissions.
  27390. + */
  27391. + mm20_mode = mm40_mode = gf20_mode = gf40_mode = 2;
  27392. +
  27393. + /*
  27394. + * If erp protection is needed we have to protect HT
  27395. + * transmissions with CCK 11M long preamble.
  27396. + */
  27397. + if (erp->cts_protection) {
  27398. + /* don't duplicate RTS/CTS in CCK mode */
  27399. + mm20_rate = mm40_rate = 0x0003;
  27400. + gf20_rate = gf40_rate = 0x0003;
  27401. + }
  27402. + break;
  27403. + }
  27404. +
  27405. + /* check for STAs not supporting greenfield mode */
  27406. + if (any_sta_nongf)
  27407. + gf20_mode = gf40_mode = 2;
  27408. +
  27409. + /* Update HT protection config */
  27410. + rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  27411. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, mm20_rate);
  27412. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, mm20_mode);
  27413. + rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  27414. +
  27415. + rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  27416. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, mm40_rate);
  27417. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, mm40_mode);
  27418. + rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  27419. +
  27420. + rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  27421. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, gf20_rate);
  27422. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, gf20_mode);
  27423. + rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  27424. +
  27425. + rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  27426. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, gf40_rate);
  27427. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, gf40_mode);
  27428. + rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  27429. +}
  27430. +
  27431. +void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
  27432. + u32 changed)
  27433. +{
  27434. + u32 reg;
  27435. +
  27436. + if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  27437. + rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  27438. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY,
  27439. + !!erp->short_preamble);
  27440. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE,
  27441. + !!erp->short_preamble);
  27442. + rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  27443. + }
  27444. +
  27445. + if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  27446. + rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  27447. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL,
  27448. + erp->cts_protection ? 2 : 0);
  27449. + rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  27450. + }
  27451. +
  27452. + if (changed & BSS_CHANGED_BASIC_RATES) {
  27453. + rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE,
  27454. + erp->basic_rates);
  27455. + rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  27456. + }
  27457. +
  27458. + if (changed & BSS_CHANGED_ERP_SLOT) {
  27459. + rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
  27460. + rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME,
  27461. + erp->slot_time);
  27462. + rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
  27463. +
  27464. + rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
  27465. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, erp->eifs);
  27466. + rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
  27467. + }
  27468. +
  27469. + if (changed & BSS_CHANGED_BEACON_INT) {
  27470. + rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  27471. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL,
  27472. + erp->beacon_int * 16);
  27473. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  27474. + }
  27475. +
  27476. + if (changed & BSS_CHANGED_HT)
  27477. + rt2800_config_ht_opmode(rt2x00dev, erp);
  27478. +}
  27479. +EXPORT_SYMBOL_GPL(rt2800_config_erp);
  27480. +
  27481. +static void rt2800_config_3572bt_ant(struct rt2x00_dev *rt2x00dev)
  27482. +{
  27483. + u32 reg;
  27484. + u16 eeprom;
  27485. + u8 led_ctrl, led_g_mode, led_r_mode;
  27486. +
  27487. + rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
  27488. + if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  27489. + rt2x00_set_field32(&reg, GPIO_SWITCH_0, 1);
  27490. + rt2x00_set_field32(&reg, GPIO_SWITCH_1, 1);
  27491. + } else {
  27492. + rt2x00_set_field32(&reg, GPIO_SWITCH_0, 0);
  27493. + rt2x00_set_field32(&reg, GPIO_SWITCH_1, 0);
  27494. + }
  27495. + rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
  27496. +
  27497. + rt2800_register_read(rt2x00dev, LED_CFG, &reg);
  27498. + led_g_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 3 : 0;
  27499. + led_r_mode = rt2x00_get_field32(reg, LED_CFG_LED_POLAR) ? 0 : 3;
  27500. + if (led_g_mode != rt2x00_get_field32(reg, LED_CFG_G_LED_MODE) ||
  27501. + led_r_mode != rt2x00_get_field32(reg, LED_CFG_R_LED_MODE)) {
  27502. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  27503. + led_ctrl = rt2x00_get_field16(eeprom, EEPROM_FREQ_LED_MODE);
  27504. + if (led_ctrl == 0 || led_ctrl > 0x40) {
  27505. + rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, led_g_mode);
  27506. + rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, led_r_mode);
  27507. + rt2800_register_write(rt2x00dev, LED_CFG, reg);
  27508. + } else {
  27509. + rt2800_mcu_request(rt2x00dev, MCU_BAND_SELECT, 0xff,
  27510. + (led_g_mode << 2) | led_r_mode, 1);
  27511. + }
  27512. + }
  27513. +}
  27514. +
  27515. +static void rt2800_set_ant_diversity(struct rt2x00_dev *rt2x00dev,
  27516. + enum antenna ant)
  27517. +{
  27518. + u32 reg;
  27519. + u8 eesk_pin = (ant == ANTENNA_A) ? 1 : 0;
  27520. + u8 gpio_bit3 = (ant == ANTENNA_A) ? 0 : 1;
  27521. +
  27522. + if (rt2x00_is_pci(rt2x00dev)) {
  27523. + rt2800_register_read(rt2x00dev, E2PROM_CSR, &reg);
  27524. + rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK, eesk_pin);
  27525. + rt2800_register_write(rt2x00dev, E2PROM_CSR, reg);
  27526. + } else if (rt2x00_is_usb(rt2x00dev))
  27527. + rt2800_mcu_request(rt2x00dev, MCU_ANT_SELECT, 0xff,
  27528. + eesk_pin, 0);
  27529. +
  27530. + rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
  27531. + rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
  27532. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, gpio_bit3);
  27533. + rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
  27534. +}
  27535. +
  27536. +void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant)
  27537. +{
  27538. + u8 r1;
  27539. + u8 r3;
  27540. + u16 eeprom;
  27541. +
  27542. + rt2800_bbp_read(rt2x00dev, 1, &r1);
  27543. + rt2800_bbp_read(rt2x00dev, 3, &r3);
  27544. +
  27545. + if (rt2x00_rt(rt2x00dev, RT3572) &&
  27546. + test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
  27547. + rt2800_config_3572bt_ant(rt2x00dev);
  27548. +
  27549. + /*
  27550. + * Configure the TX antenna.
  27551. + */
  27552. + switch (ant->tx_chain_num) {
  27553. + case 1:
  27554. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
  27555. + break;
  27556. + case 2:
  27557. + if (rt2x00_rt(rt2x00dev, RT3572) &&
  27558. + test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
  27559. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 1);
  27560. + else
  27561. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
  27562. + break;
  27563. + case 3:
  27564. + rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
  27565. + break;
  27566. + }
  27567. +
  27568. + /*
  27569. + * Configure the RX antenna.
  27570. + */
  27571. + switch (ant->rx_chain_num) {
  27572. + case 1:
  27573. + if (rt2x00_rt(rt2x00dev, RT3070) ||
  27574. + rt2x00_rt(rt2x00dev, RT3090) ||
  27575. + rt2x00_rt(rt2x00dev, RT3352) ||
  27576. + rt2x00_rt(rt2x00dev, RT3390)) {
  27577. + rt2x00_eeprom_read(rt2x00dev,
  27578. + EEPROM_NIC_CONF1, &eeprom);
  27579. + if (rt2x00_get_field16(eeprom,
  27580. + EEPROM_NIC_CONF1_ANT_DIVERSITY))
  27581. + rt2800_set_ant_diversity(rt2x00dev,
  27582. + rt2x00dev->default_ant.rx);
  27583. + }
  27584. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
  27585. + break;
  27586. + case 2:
  27587. + if (rt2x00_rt(rt2x00dev, RT3572) &&
  27588. + test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
  27589. + rt2x00_set_field8(&r3, BBP3_RX_ADC, 1);
  27590. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA,
  27591. + rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  27592. + rt2800_set_ant_diversity(rt2x00dev, ANTENNA_B);
  27593. + } else {
  27594. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
  27595. + }
  27596. + break;
  27597. + case 3:
  27598. + rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
  27599. + break;
  27600. + }
  27601. +
  27602. + rt2800_bbp_write(rt2x00dev, 3, r3);
  27603. + rt2800_bbp_write(rt2x00dev, 1, r1);
  27604. +}
  27605. +EXPORT_SYMBOL_GPL(rt2800_config_ant);
  27606. +
  27607. +static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  27608. + struct rt2x00lib_conf *libconf)
  27609. +{
  27610. + u16 eeprom;
  27611. + short lna_gain;
  27612. +
  27613. + if (libconf->rf.channel <= 14) {
  27614. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  27615. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
  27616. + } else if (libconf->rf.channel <= 64) {
  27617. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
  27618. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
  27619. + } else if (libconf->rf.channel <= 128) {
  27620. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
  27621. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
  27622. + } else {
  27623. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
  27624. + lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
  27625. + }
  27626. +
  27627. + rt2x00dev->lna_gain = lna_gain;
  27628. +}
  27629. +
  27630. +static void rt2800_config_channel_rf2xxx(struct rt2x00_dev *rt2x00dev,
  27631. + struct ieee80211_conf *conf,
  27632. + struct rf_channel *rf,
  27633. + struct channel_info *info)
  27634. +{
  27635. + rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  27636. +
  27637. + if (rt2x00dev->default_ant.tx_chain_num == 1)
  27638. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
  27639. +
  27640. + if (rt2x00dev->default_ant.rx_chain_num == 1) {
  27641. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
  27642. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  27643. + } else if (rt2x00dev->default_ant.rx_chain_num == 2)
  27644. + rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
  27645. +
  27646. + if (rf->channel > 14) {
  27647. + /*
  27648. + * When TX power is below 0, we should increase it by 7 to
  27649. + * make it a positive value (Minimum value is -7).
  27650. + * However this means that values between 0 and 7 have
  27651. + * double meaning, and we should set a 7DBm boost flag.
  27652. + */
  27653. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
  27654. + (info->default_power1 >= 0));
  27655. +
  27656. + if (info->default_power1 < 0)
  27657. + info->default_power1 += 7;
  27658. +
  27659. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A, info->default_power1);
  27660. +
  27661. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
  27662. + (info->default_power2 >= 0));
  27663. +
  27664. + if (info->default_power2 < 0)
  27665. + info->default_power2 += 7;
  27666. +
  27667. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A, info->default_power2);
  27668. + } else {
  27669. + rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G, info->default_power1);
  27670. + rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G, info->default_power2);
  27671. + }
  27672. +
  27673. + rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
  27674. +
  27675. + rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  27676. + rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  27677. + rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  27678. + rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  27679. +
  27680. + udelay(200);
  27681. +
  27682. + rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  27683. + rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  27684. + rt2800_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  27685. + rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  27686. +
  27687. + udelay(200);
  27688. +
  27689. + rt2800_rf_write(rt2x00dev, 1, rf->rf1);
  27690. + rt2800_rf_write(rt2x00dev, 2, rf->rf2);
  27691. + rt2800_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  27692. + rt2800_rf_write(rt2x00dev, 4, rf->rf4);
  27693. +}
  27694. +
  27695. +static void rt2800_config_channel_rf3xxx(struct rt2x00_dev *rt2x00dev,
  27696. + struct ieee80211_conf *conf,
  27697. + struct rf_channel *rf,
  27698. + struct channel_info *info)
  27699. +{
  27700. + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
  27701. + u8 rfcsr, calib_tx, calib_rx;
  27702. +
  27703. + rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
  27704. +
  27705. + rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
  27706. + rt2x00_set_field8(&rfcsr, RFCSR3_K, rf->rf3);
  27707. + rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
  27708. +
  27709. + rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
  27710. + rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
  27711. + rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
  27712. +
  27713. + rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
  27714. + rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER, info->default_power1);
  27715. + rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
  27716. +
  27717. + rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
  27718. + rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER, info->default_power2);
  27719. + rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
  27720. +
  27721. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  27722. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
  27723. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
  27724. + rt2x00dev->default_ant.rx_chain_num <= 1);
  27725. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD,
  27726. + rt2x00dev->default_ant.rx_chain_num <= 2);
  27727. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
  27728. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
  27729. + rt2x00dev->default_ant.tx_chain_num <= 1);
  27730. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD,
  27731. + rt2x00dev->default_ant.tx_chain_num <= 2);
  27732. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  27733. +
  27734. + rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  27735. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  27736. + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  27737. + msleep(1);
  27738. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  27739. + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  27740. +
  27741. + rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
  27742. + rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
  27743. + rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
  27744. +
  27745. + if (rt2x00_rt(rt2x00dev, RT3390)) {
  27746. + calib_tx = conf_is_ht40(conf) ? 0x68 : 0x4f;
  27747. + calib_rx = conf_is_ht40(conf) ? 0x6f : 0x4f;
  27748. + } else {
  27749. + if (conf_is_ht40(conf)) {
  27750. + calib_tx = drv_data->calibration_bw40;
  27751. + calib_rx = drv_data->calibration_bw40;
  27752. + } else {
  27753. + calib_tx = drv_data->calibration_bw20;
  27754. + calib_rx = drv_data->calibration_bw20;
  27755. + }
  27756. + }
  27757. +
  27758. + rt2800_rfcsr_read(rt2x00dev, 24, &rfcsr);
  27759. + rt2x00_set_field8(&rfcsr, RFCSR24_TX_CALIB, calib_tx);
  27760. + rt2800_rfcsr_write(rt2x00dev, 24, rfcsr);
  27761. +
  27762. + rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
  27763. + rt2x00_set_field8(&rfcsr, RFCSR31_RX_CALIB, calib_rx);
  27764. + rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
  27765. +
  27766. + rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
  27767. + rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  27768. + rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
  27769. +
  27770. + rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  27771. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
  27772. + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  27773. + msleep(1);
  27774. + rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
  27775. + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  27776. +}
  27777. +
  27778. +static void rt2800_config_channel_rf3052(struct rt2x00_dev *rt2x00dev,
  27779. + struct ieee80211_conf *conf,
  27780. + struct rf_channel *rf,
  27781. + struct channel_info *info)
  27782. +{
  27783. + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
  27784. + u8 rfcsr;
  27785. + u32 reg;
  27786. +
  27787. + if (rf->channel <= 14) {
  27788. + rt2800_bbp_write(rt2x00dev, 25, drv_data->bbp25);
  27789. + rt2800_bbp_write(rt2x00dev, 26, drv_data->bbp26);
  27790. + } else {
  27791. + rt2800_bbp_write(rt2x00dev, 25, 0x09);
  27792. + rt2800_bbp_write(rt2x00dev, 26, 0xff);
  27793. + }
  27794. +
  27795. + rt2800_rfcsr_write(rt2x00dev, 2, rf->rf1);
  27796. + rt2800_rfcsr_write(rt2x00dev, 3, rf->rf3);
  27797. +
  27798. + rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
  27799. + rt2x00_set_field8(&rfcsr, RFCSR6_R1, rf->rf2);
  27800. + if (rf->channel <= 14)
  27801. + rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 2);
  27802. + else
  27803. + rt2x00_set_field8(&rfcsr, RFCSR6_TXDIV, 1);
  27804. + rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
  27805. +
  27806. + rt2800_rfcsr_read(rt2x00dev, 5, &rfcsr);
  27807. + if (rf->channel <= 14)
  27808. + rt2x00_set_field8(&rfcsr, RFCSR5_R1, 1);
  27809. + else
  27810. + rt2x00_set_field8(&rfcsr, RFCSR5_R1, 2);
  27811. + rt2800_rfcsr_write(rt2x00dev, 5, rfcsr);
  27812. +
  27813. + rt2800_rfcsr_read(rt2x00dev, 12, &rfcsr);
  27814. + if (rf->channel <= 14) {
  27815. + rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 3);
  27816. + rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
  27817. + info->default_power1);
  27818. + } else {
  27819. + rt2x00_set_field8(&rfcsr, RFCSR12_DR0, 7);
  27820. + rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
  27821. + (info->default_power1 & 0x3) |
  27822. + ((info->default_power1 & 0xC) << 1));
  27823. + }
  27824. + rt2800_rfcsr_write(rt2x00dev, 12, rfcsr);
  27825. +
  27826. + rt2800_rfcsr_read(rt2x00dev, 13, &rfcsr);
  27827. + if (rf->channel <= 14) {
  27828. + rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 3);
  27829. + rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
  27830. + info->default_power2);
  27831. + } else {
  27832. + rt2x00_set_field8(&rfcsr, RFCSR13_DR0, 7);
  27833. + rt2x00_set_field8(&rfcsr, RFCSR13_TX_POWER,
  27834. + (info->default_power2 & 0x3) |
  27835. + ((info->default_power2 & 0xC) << 1));
  27836. + }
  27837. + rt2800_rfcsr_write(rt2x00dev, 13, rfcsr);
  27838. +
  27839. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  27840. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
  27841. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
  27842. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
  27843. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
  27844. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
  27845. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
  27846. + if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
  27847. + if (rf->channel <= 14) {
  27848. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
  27849. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
  27850. + }
  27851. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
  27852. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
  27853. + } else {
  27854. + switch (rt2x00dev->default_ant.tx_chain_num) {
  27855. + case 1:
  27856. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
  27857. + case 2:
  27858. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
  27859. + break;
  27860. + }
  27861. +
  27862. + switch (rt2x00dev->default_ant.rx_chain_num) {
  27863. + case 1:
  27864. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
  27865. + case 2:
  27866. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
  27867. + break;
  27868. + }
  27869. + }
  27870. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  27871. +
  27872. + rt2800_rfcsr_read(rt2x00dev, 23, &rfcsr);
  27873. + rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
  27874. + rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
  27875. +
  27876. + if (conf_is_ht40(conf)) {
  27877. + rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw40);
  27878. + rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw40);
  27879. + } else {
  27880. + rt2800_rfcsr_write(rt2x00dev, 24, drv_data->calibration_bw20);
  27881. + rt2800_rfcsr_write(rt2x00dev, 31, drv_data->calibration_bw20);
  27882. + }
  27883. +
  27884. + if (rf->channel <= 14) {
  27885. + rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
  27886. + rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
  27887. + rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
  27888. + rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
  27889. + rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
  27890. + rfcsr = 0x4c;
  27891. + rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
  27892. + drv_data->txmixer_gain_24g);
  27893. + rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
  27894. + rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
  27895. + rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
  27896. + rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
  27897. + rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
  27898. + rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
  27899. + rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
  27900. + rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
  27901. + } else {
  27902. + rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
  27903. + rt2x00_set_field8(&rfcsr, RFCSR7_BIT2, 1);
  27904. + rt2x00_set_field8(&rfcsr, RFCSR7_BIT3, 0);
  27905. + rt2x00_set_field8(&rfcsr, RFCSR7_BIT4, 1);
  27906. + rt2x00_set_field8(&rfcsr, RFCSR7_BITS67, 0);
  27907. + rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
  27908. + rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
  27909. + rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
  27910. + rt2800_rfcsr_write(rt2x00dev, 11, 0x00);
  27911. + rt2800_rfcsr_write(rt2x00dev, 15, 0x43);
  27912. + rfcsr = 0x7a;
  27913. + rt2x00_set_field8(&rfcsr, RFCSR16_TXMIXER_GAIN,
  27914. + drv_data->txmixer_gain_5g);
  27915. + rt2800_rfcsr_write(rt2x00dev, 16, rfcsr);
  27916. + rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
  27917. + if (rf->channel <= 64) {
  27918. + rt2800_rfcsr_write(rt2x00dev, 19, 0xb7);
  27919. + rt2800_rfcsr_write(rt2x00dev, 20, 0xf6);
  27920. + rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
  27921. + } else if (rf->channel <= 128) {
  27922. + rt2800_rfcsr_write(rt2x00dev, 19, 0x74);
  27923. + rt2800_rfcsr_write(rt2x00dev, 20, 0xf4);
  27924. + rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  27925. + } else {
  27926. + rt2800_rfcsr_write(rt2x00dev, 19, 0x72);
  27927. + rt2800_rfcsr_write(rt2x00dev, 20, 0xf3);
  27928. + rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  27929. + }
  27930. + rt2800_rfcsr_write(rt2x00dev, 26, 0x87);
  27931. + rt2800_rfcsr_write(rt2x00dev, 27, 0x01);
  27932. + rt2800_rfcsr_write(rt2x00dev, 29, 0x9f);
  27933. + }
  27934. +
  27935. + rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
  27936. + rt2x00_set_field32(&reg, GPIO_CTRL_DIR7, 0);
  27937. + if (rf->channel <= 14)
  27938. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 1);
  27939. + else
  27940. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL7, 0);
  27941. + rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
  27942. +
  27943. + rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
  27944. + rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  27945. + rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
  27946. +}
  27947. +
  27948. +#define POWER_BOUND 0x27
  27949. +#define POWER_BOUND_5G 0x2b
  27950. +#define FREQ_OFFSET_BOUND 0x5f
  27951. +
  27952. +static void rt2800_adjust_freq_offset(struct rt2x00_dev *rt2x00dev)
  27953. +{
  27954. + u8 rfcsr;
  27955. +
  27956. + rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
  27957. + if (rt2x00dev->freq_offset > FREQ_OFFSET_BOUND)
  27958. + rt2x00_set_field8(&rfcsr, RFCSR17_CODE, FREQ_OFFSET_BOUND);
  27959. + else
  27960. + rt2x00_set_field8(&rfcsr, RFCSR17_CODE, rt2x00dev->freq_offset);
  27961. + rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
  27962. +}
  27963. +
  27964. +static void rt2800_config_channel_rf3290(struct rt2x00_dev *rt2x00dev,
  27965. + struct ieee80211_conf *conf,
  27966. + struct rf_channel *rf,
  27967. + struct channel_info *info)
  27968. +{
  27969. + u8 rfcsr;
  27970. +
  27971. + rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
  27972. + rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
  27973. + rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
  27974. + rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
  27975. + rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
  27976. +
  27977. + rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
  27978. + if (info->default_power1 > POWER_BOUND)
  27979. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
  27980. + else
  27981. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
  27982. + rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
  27983. +
  27984. + rt2800_adjust_freq_offset(rt2x00dev);
  27985. +
  27986. + if (rf->channel <= 14) {
  27987. + if (rf->channel == 6)
  27988. + rt2800_bbp_write(rt2x00dev, 68, 0x0c);
  27989. + else
  27990. + rt2800_bbp_write(rt2x00dev, 68, 0x0b);
  27991. +
  27992. + if (rf->channel >= 1 && rf->channel <= 6)
  27993. + rt2800_bbp_write(rt2x00dev, 59, 0x0f);
  27994. + else if (rf->channel >= 7 && rf->channel <= 11)
  27995. + rt2800_bbp_write(rt2x00dev, 59, 0x0e);
  27996. + else if (rf->channel >= 12 && rf->channel <= 14)
  27997. + rt2800_bbp_write(rt2x00dev, 59, 0x0d);
  27998. + }
  27999. +}
  28000. +
  28001. +static void rt2800_config_channel_rf3322(struct rt2x00_dev *rt2x00dev,
  28002. + struct ieee80211_conf *conf,
  28003. + struct rf_channel *rf,
  28004. + struct channel_info *info)
  28005. +{
  28006. + u8 rfcsr;
  28007. +
  28008. + rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
  28009. + rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
  28010. +
  28011. + rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
  28012. + rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
  28013. + rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
  28014. +
  28015. + if (info->default_power1 > POWER_BOUND)
  28016. + rt2800_rfcsr_write(rt2x00dev, 47, POWER_BOUND);
  28017. + else
  28018. + rt2800_rfcsr_write(rt2x00dev, 47, info->default_power1);
  28019. +
  28020. + if (info->default_power2 > POWER_BOUND)
  28021. + rt2800_rfcsr_write(rt2x00dev, 48, POWER_BOUND);
  28022. + else
  28023. + rt2800_rfcsr_write(rt2x00dev, 48, info->default_power2);
  28024. +
  28025. + rt2800_adjust_freq_offset(rt2x00dev);
  28026. +
  28027. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  28028. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
  28029. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
  28030. +
  28031. + if ( rt2x00dev->default_ant.tx_chain_num == 2 )
  28032. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
  28033. + else
  28034. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
  28035. +
  28036. + if ( rt2x00dev->default_ant.rx_chain_num == 2 )
  28037. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
  28038. + else
  28039. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
  28040. +
  28041. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
  28042. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
  28043. +
  28044. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  28045. +
  28046. + rt2800_rfcsr_write(rt2x00dev, 31, 80);
  28047. +}
  28048. +
  28049. +static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
  28050. + struct ieee80211_conf *conf,
  28051. + struct rf_channel *rf,
  28052. + struct channel_info *info)
  28053. +{
  28054. + u8 rfcsr;
  28055. +
  28056. + rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
  28057. + rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
  28058. + rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
  28059. + rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf2);
  28060. + rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
  28061. +
  28062. + rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
  28063. + if (info->default_power1 > POWER_BOUND)
  28064. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, POWER_BOUND);
  28065. + else
  28066. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
  28067. + rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
  28068. +
  28069. + if (rt2x00_rt(rt2x00dev, RT5392)) {
  28070. + rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
  28071. + if (info->default_power1 > POWER_BOUND)
  28072. + rt2x00_set_field8(&rfcsr, RFCSR50_TX, POWER_BOUND);
  28073. + else
  28074. + rt2x00_set_field8(&rfcsr, RFCSR50_TX,
  28075. + info->default_power2);
  28076. + rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
  28077. + }
  28078. +
  28079. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  28080. + if (rt2x00_rt(rt2x00dev, RT5392)) {
  28081. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
  28082. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
  28083. + }
  28084. + rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
  28085. + rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
  28086. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
  28087. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
  28088. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  28089. +
  28090. + rt2800_adjust_freq_offset(rt2x00dev);
  28091. +
  28092. + if (rf->channel <= 14) {
  28093. + int idx = rf->channel-1;
  28094. +
  28095. + if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
  28096. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
  28097. + /* r55/r59 value array of channel 1~14 */
  28098. + static const char r55_bt_rev[] = {0x83, 0x83,
  28099. + 0x83, 0x73, 0x73, 0x63, 0x53, 0x53,
  28100. + 0x53, 0x43, 0x43, 0x43, 0x43, 0x43};
  28101. + static const char r59_bt_rev[] = {0x0e, 0x0e,
  28102. + 0x0e, 0x0e, 0x0e, 0x0b, 0x0a, 0x09,
  28103. + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07};
  28104. +
  28105. + rt2800_rfcsr_write(rt2x00dev, 55,
  28106. + r55_bt_rev[idx]);
  28107. + rt2800_rfcsr_write(rt2x00dev, 59,
  28108. + r59_bt_rev[idx]);
  28109. + } else {
  28110. + static const char r59_bt[] = {0x8b, 0x8b, 0x8b,
  28111. + 0x8b, 0x8b, 0x8b, 0x8b, 0x8a, 0x89,
  28112. + 0x88, 0x88, 0x86, 0x85, 0x84};
  28113. +
  28114. + rt2800_rfcsr_write(rt2x00dev, 59, r59_bt[idx]);
  28115. + }
  28116. + } else {
  28117. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F)) {
  28118. + static const char r55_nonbt_rev[] = {0x23, 0x23,
  28119. + 0x23, 0x23, 0x13, 0x13, 0x03, 0x03,
  28120. + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03};
  28121. + static const char r59_nonbt_rev[] = {0x07, 0x07,
  28122. + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
  28123. + 0x07, 0x07, 0x06, 0x05, 0x04, 0x04};
  28124. +
  28125. + rt2800_rfcsr_write(rt2x00dev, 55,
  28126. + r55_nonbt_rev[idx]);
  28127. + rt2800_rfcsr_write(rt2x00dev, 59,
  28128. + r59_nonbt_rev[idx]);
  28129. + } else if (rt2x00_rt(rt2x00dev, RT5390) ||
  28130. + rt2x00_rt(rt2x00dev, RT5392)) {
  28131. + static const char r59_non_bt[] = {0x8f, 0x8f,
  28132. + 0x8f, 0x8f, 0x8f, 0x8f, 0x8f, 0x8d,
  28133. + 0x8a, 0x88, 0x88, 0x87, 0x87, 0x86};
  28134. +
  28135. + rt2800_rfcsr_write(rt2x00dev, 59,
  28136. + r59_non_bt[idx]);
  28137. + }
  28138. + }
  28139. + }
  28140. +}
  28141. +
  28142. +static void rt2800_config_channel_rf55xx(struct rt2x00_dev *rt2x00dev,
  28143. + struct ieee80211_conf *conf,
  28144. + struct rf_channel *rf,
  28145. + struct channel_info *info)
  28146. +{
  28147. + u8 rfcsr, ep_reg;
  28148. + u32 reg;
  28149. + int power_bound;
  28150. +
  28151. + /* TODO */
  28152. + const bool is_11b = false;
  28153. + const bool is_type_ep = false;
  28154. +
  28155. + rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
  28156. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL,
  28157. + (rf->channel > 14 || conf_is_ht40(conf)) ? 5 : 0);
  28158. + rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
  28159. +
  28160. + /* Order of values on rf_channel entry: N, K, mod, R */
  28161. + rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1 & 0xff);
  28162. +
  28163. + rt2800_rfcsr_read(rt2x00dev, 9, &rfcsr);
  28164. + rt2x00_set_field8(&rfcsr, RFCSR9_K, rf->rf2 & 0xf);
  28165. + rt2x00_set_field8(&rfcsr, RFCSR9_N, (rf->rf1 & 0x100) >> 8);
  28166. + rt2x00_set_field8(&rfcsr, RFCSR9_MOD, ((rf->rf3 - 8) & 0x4) >> 2);
  28167. + rt2800_rfcsr_write(rt2x00dev, 9, rfcsr);
  28168. +
  28169. + rt2800_rfcsr_read(rt2x00dev, 11, &rfcsr);
  28170. + rt2x00_set_field8(&rfcsr, RFCSR11_R, rf->rf4 - 1);
  28171. + rt2x00_set_field8(&rfcsr, RFCSR11_MOD, (rf->rf3 - 8) & 0x3);
  28172. + rt2800_rfcsr_write(rt2x00dev, 11, rfcsr);
  28173. +
  28174. + if (rf->channel <= 14) {
  28175. + rt2800_rfcsr_write(rt2x00dev, 10, 0x90);
  28176. + /* FIXME: RF11 owerwrite ? */
  28177. + rt2800_rfcsr_write(rt2x00dev, 11, 0x4A);
  28178. + rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
  28179. + rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
  28180. + rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
  28181. + rt2800_rfcsr_write(rt2x00dev, 24, 0x4A);
  28182. + rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
  28183. + rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
  28184. + rt2800_rfcsr_write(rt2x00dev, 36, 0x80);
  28185. + rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
  28186. + rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
  28187. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1B);
  28188. + rt2800_rfcsr_write(rt2x00dev, 40, 0x0D);
  28189. + rt2800_rfcsr_write(rt2x00dev, 41, 0x9B);
  28190. + rt2800_rfcsr_write(rt2x00dev, 42, 0xD5);
  28191. + rt2800_rfcsr_write(rt2x00dev, 43, 0x72);
  28192. + rt2800_rfcsr_write(rt2x00dev, 44, 0x0E);
  28193. + rt2800_rfcsr_write(rt2x00dev, 45, 0xA2);
  28194. + rt2800_rfcsr_write(rt2x00dev, 46, 0x6B);
  28195. + rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
  28196. + rt2800_rfcsr_write(rt2x00dev, 51, 0x3E);
  28197. + rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
  28198. + rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
  28199. + rt2800_rfcsr_write(rt2x00dev, 56, 0xA1);
  28200. + rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
  28201. + rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
  28202. + rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
  28203. + rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
  28204. + rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
  28205. +
  28206. + /* TODO RF27 <- tssi */
  28207. +
  28208. + rfcsr = rf->channel <= 10 ? 0x07 : 0x06;
  28209. + rt2800_rfcsr_write(rt2x00dev, 23, rfcsr);
  28210. + rt2800_rfcsr_write(rt2x00dev, 59, rfcsr);
  28211. +
  28212. + if (is_11b) {
  28213. + /* CCK */
  28214. + rt2800_rfcsr_write(rt2x00dev, 31, 0xF8);
  28215. + rt2800_rfcsr_write(rt2x00dev, 32, 0xC0);
  28216. + if (is_type_ep)
  28217. + rt2800_rfcsr_write(rt2x00dev, 55, 0x06);
  28218. + else
  28219. + rt2800_rfcsr_write(rt2x00dev, 55, 0x47);
  28220. + } else {
  28221. + /* OFDM */
  28222. + if (is_type_ep)
  28223. + rt2800_rfcsr_write(rt2x00dev, 55, 0x03);
  28224. + else
  28225. + rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
  28226. + }
  28227. +
  28228. + power_bound = POWER_BOUND;
  28229. + ep_reg = 0x2;
  28230. + } else {
  28231. + rt2800_rfcsr_write(rt2x00dev, 10, 0x97);
  28232. + /* FIMXE: RF11 overwrite */
  28233. + rt2800_rfcsr_write(rt2x00dev, 11, 0x40);
  28234. + rt2800_rfcsr_write(rt2x00dev, 25, 0xBF);
  28235. + rt2800_rfcsr_write(rt2x00dev, 27, 0x42);
  28236. + rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
  28237. + rt2800_rfcsr_write(rt2x00dev, 37, 0x04);
  28238. + rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
  28239. + rt2800_rfcsr_write(rt2x00dev, 40, 0x42);
  28240. + rt2800_rfcsr_write(rt2x00dev, 41, 0xBB);
  28241. + rt2800_rfcsr_write(rt2x00dev, 42, 0xD7);
  28242. + rt2800_rfcsr_write(rt2x00dev, 45, 0x41);
  28243. + rt2800_rfcsr_write(rt2x00dev, 48, 0x00);
  28244. + rt2800_rfcsr_write(rt2x00dev, 57, 0x77);
  28245. + rt2800_rfcsr_write(rt2x00dev, 60, 0x05);
  28246. + rt2800_rfcsr_write(rt2x00dev, 61, 0x01);
  28247. +
  28248. + /* TODO RF27 <- tssi */
  28249. +
  28250. + if (rf->channel >= 36 && rf->channel <= 64) {
  28251. +
  28252. + rt2800_rfcsr_write(rt2x00dev, 12, 0x2E);
  28253. + rt2800_rfcsr_write(rt2x00dev, 13, 0x22);
  28254. + rt2800_rfcsr_write(rt2x00dev, 22, 0x60);
  28255. + rt2800_rfcsr_write(rt2x00dev, 23, 0x7F);
  28256. + if (rf->channel <= 50)
  28257. + rt2800_rfcsr_write(rt2x00dev, 24, 0x09);
  28258. + else if (rf->channel >= 52)
  28259. + rt2800_rfcsr_write(rt2x00dev, 24, 0x07);
  28260. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1C);
  28261. + rt2800_rfcsr_write(rt2x00dev, 43, 0x5B);
  28262. + rt2800_rfcsr_write(rt2x00dev, 44, 0X40);
  28263. + rt2800_rfcsr_write(rt2x00dev, 46, 0X00);
  28264. + rt2800_rfcsr_write(rt2x00dev, 51, 0xFE);
  28265. + rt2800_rfcsr_write(rt2x00dev, 52, 0x0C);
  28266. + rt2800_rfcsr_write(rt2x00dev, 54, 0xF8);
  28267. + if (rf->channel <= 50) {
  28268. + rt2800_rfcsr_write(rt2x00dev, 55, 0x06),
  28269. + rt2800_rfcsr_write(rt2x00dev, 56, 0xD3);
  28270. + } else if (rf->channel >= 52) {
  28271. + rt2800_rfcsr_write(rt2x00dev, 55, 0x04);
  28272. + rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
  28273. + }
  28274. +
  28275. + rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
  28276. + rt2800_rfcsr_write(rt2x00dev, 59, 0x7F);
  28277. + rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
  28278. +
  28279. + } else if (rf->channel >= 100 && rf->channel <= 165) {
  28280. +
  28281. + rt2800_rfcsr_write(rt2x00dev, 12, 0x0E);
  28282. + rt2800_rfcsr_write(rt2x00dev, 13, 0x42);
  28283. + rt2800_rfcsr_write(rt2x00dev, 22, 0x40);
  28284. + if (rf->channel <= 153) {
  28285. + rt2800_rfcsr_write(rt2x00dev, 23, 0x3C);
  28286. + rt2800_rfcsr_write(rt2x00dev, 24, 0x06);
  28287. + } else if (rf->channel >= 155) {
  28288. + rt2800_rfcsr_write(rt2x00dev, 23, 0x38);
  28289. + rt2800_rfcsr_write(rt2x00dev, 24, 0x05);
  28290. + }
  28291. + if (rf->channel <= 138) {
  28292. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1A);
  28293. + rt2800_rfcsr_write(rt2x00dev, 43, 0x3B);
  28294. + rt2800_rfcsr_write(rt2x00dev, 44, 0x20);
  28295. + rt2800_rfcsr_write(rt2x00dev, 46, 0x18);
  28296. + } else if (rf->channel >= 140) {
  28297. + rt2800_rfcsr_write(rt2x00dev, 39, 0x18);
  28298. + rt2800_rfcsr_write(rt2x00dev, 43, 0x1B);
  28299. + rt2800_rfcsr_write(rt2x00dev, 44, 0x10);
  28300. + rt2800_rfcsr_write(rt2x00dev, 46, 0X08);
  28301. + }
  28302. + if (rf->channel <= 124)
  28303. + rt2800_rfcsr_write(rt2x00dev, 51, 0xFC);
  28304. + else if (rf->channel >= 126)
  28305. + rt2800_rfcsr_write(rt2x00dev, 51, 0xEC);
  28306. + if (rf->channel <= 138)
  28307. + rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
  28308. + else if (rf->channel >= 140)
  28309. + rt2800_rfcsr_write(rt2x00dev, 52, 0x06);
  28310. + rt2800_rfcsr_write(rt2x00dev, 54, 0xEB);
  28311. + if (rf->channel <= 138)
  28312. + rt2800_rfcsr_write(rt2x00dev, 55, 0x01);
  28313. + else if (rf->channel >= 140)
  28314. + rt2800_rfcsr_write(rt2x00dev, 55, 0x00);
  28315. + if (rf->channel <= 128)
  28316. + rt2800_rfcsr_write(rt2x00dev, 56, 0xBB);
  28317. + else if (rf->channel >= 130)
  28318. + rt2800_rfcsr_write(rt2x00dev, 56, 0xAB);
  28319. + if (rf->channel <= 116)
  28320. + rt2800_rfcsr_write(rt2x00dev, 58, 0x1D);
  28321. + else if (rf->channel >= 118)
  28322. + rt2800_rfcsr_write(rt2x00dev, 58, 0x15);
  28323. + if (rf->channel <= 138)
  28324. + rt2800_rfcsr_write(rt2x00dev, 59, 0x3F);
  28325. + else if (rf->channel >= 140)
  28326. + rt2800_rfcsr_write(rt2x00dev, 59, 0x7C);
  28327. + if (rf->channel <= 116)
  28328. + rt2800_rfcsr_write(rt2x00dev, 62, 0x1D);
  28329. + else if (rf->channel >= 118)
  28330. + rt2800_rfcsr_write(rt2x00dev, 62, 0x15);
  28331. + }
  28332. +
  28333. + power_bound = POWER_BOUND_5G;
  28334. + ep_reg = 0x3;
  28335. + }
  28336. +
  28337. + rt2800_rfcsr_read(rt2x00dev, 49, &rfcsr);
  28338. + if (info->default_power1 > power_bound)
  28339. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, power_bound);
  28340. + else
  28341. + rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
  28342. + if (is_type_ep)
  28343. + rt2x00_set_field8(&rfcsr, RFCSR49_EP, ep_reg);
  28344. + rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
  28345. +
  28346. + rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
  28347. + if (info->default_power2 > power_bound)
  28348. + rt2x00_set_field8(&rfcsr, RFCSR50_TX, power_bound);
  28349. + else
  28350. + rt2x00_set_field8(&rfcsr, RFCSR50_TX, info->default_power2);
  28351. + if (is_type_ep)
  28352. + rt2x00_set_field8(&rfcsr, RFCSR50_EP, ep_reg);
  28353. + rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
  28354. +
  28355. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  28356. + rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
  28357. + rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
  28358. +
  28359. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD,
  28360. + rt2x00dev->default_ant.tx_chain_num >= 1);
  28361. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD,
  28362. + rt2x00dev->default_ant.tx_chain_num == 2);
  28363. + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
  28364. +
  28365. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD,
  28366. + rt2x00dev->default_ant.rx_chain_num >= 1);
  28367. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD,
  28368. + rt2x00dev->default_ant.rx_chain_num == 2);
  28369. + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
  28370. +
  28371. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  28372. + rt2800_rfcsr_write(rt2x00dev, 6, 0xe4);
  28373. +
  28374. + if (conf_is_ht40(conf))
  28375. + rt2800_rfcsr_write(rt2x00dev, 30, 0x16);
  28376. + else
  28377. + rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
  28378. +
  28379. + if (!is_11b) {
  28380. + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
  28381. + rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
  28382. + }
  28383. +
  28384. + /* TODO proper frequency adjustment */
  28385. + rt2800_adjust_freq_offset(rt2x00dev);
  28386. +
  28387. + /* TODO merge with others */
  28388. + rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
  28389. + rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
  28390. + rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
  28391. +
  28392. + /* BBP settings */
  28393. + rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  28394. + rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  28395. + rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  28396. +
  28397. + rt2800_bbp_write(rt2x00dev, 79, (rf->channel <= 14) ? 0x1C : 0x18);
  28398. + rt2800_bbp_write(rt2x00dev, 80, (rf->channel <= 14) ? 0x0E : 0x08);
  28399. + rt2800_bbp_write(rt2x00dev, 81, (rf->channel <= 14) ? 0x3A : 0x38);
  28400. + rt2800_bbp_write(rt2x00dev, 82, (rf->channel <= 14) ? 0x62 : 0x92);
  28401. +
  28402. + /* GLRT band configuration */
  28403. + rt2800_bbp_write(rt2x00dev, 195, 128);
  28404. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0xE0 : 0xF0);
  28405. + rt2800_bbp_write(rt2x00dev, 195, 129);
  28406. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x1F : 0x1E);
  28407. + rt2800_bbp_write(rt2x00dev, 195, 130);
  28408. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x38 : 0x28);
  28409. + rt2800_bbp_write(rt2x00dev, 195, 131);
  28410. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x32 : 0x20);
  28411. + rt2800_bbp_write(rt2x00dev, 195, 133);
  28412. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x28 : 0x7F);
  28413. + rt2800_bbp_write(rt2x00dev, 195, 124);
  28414. + rt2800_bbp_write(rt2x00dev, 196, (rf->channel <= 14) ? 0x19 : 0x7F);
  28415. +}
  28416. +
  28417. +static void rt2800_bbp_write_with_rx_chain(struct rt2x00_dev *rt2x00dev,
  28418. + const unsigned int word,
  28419. + const u8 value)
  28420. +{
  28421. + u8 chain, reg;
  28422. +
  28423. + for (chain = 0; chain < rt2x00dev->default_ant.rx_chain_num; chain++) {
  28424. + rt2800_bbp_read(rt2x00dev, 27, &reg);
  28425. + rt2x00_set_field8(&reg, BBP27_RX_CHAIN_SEL, chain);
  28426. + rt2800_bbp_write(rt2x00dev, 27, reg);
  28427. +
  28428. + rt2800_bbp_write(rt2x00dev, word, value);
  28429. + }
  28430. +}
  28431. +
  28432. +static void rt2800_iq_calibrate(struct rt2x00_dev *rt2x00dev, int channel)
  28433. +{
  28434. + u8 cal;
  28435. +
  28436. + /* TX0 IQ Gain */
  28437. + rt2800_bbp_write(rt2x00dev, 158, 0x2c);
  28438. + if (channel <= 14)
  28439. + cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX0_2G);
  28440. + else if (channel >= 36 && channel <= 64)
  28441. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28442. + EEPROM_IQ_GAIN_CAL_TX0_CH36_TO_CH64_5G);
  28443. + else if (channel >= 100 && channel <= 138)
  28444. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28445. + EEPROM_IQ_GAIN_CAL_TX0_CH100_TO_CH138_5G);
  28446. + else if (channel >= 140 && channel <= 165)
  28447. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28448. + EEPROM_IQ_GAIN_CAL_TX0_CH140_TO_CH165_5G);
  28449. + else
  28450. + cal = 0;
  28451. + rt2800_bbp_write(rt2x00dev, 159, cal);
  28452. +
  28453. + /* TX0 IQ Phase */
  28454. + rt2800_bbp_write(rt2x00dev, 158, 0x2d);
  28455. + if (channel <= 14)
  28456. + cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX0_2G);
  28457. + else if (channel >= 36 && channel <= 64)
  28458. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28459. + EEPROM_IQ_PHASE_CAL_TX0_CH36_TO_CH64_5G);
  28460. + else if (channel >= 100 && channel <= 138)
  28461. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28462. + EEPROM_IQ_PHASE_CAL_TX0_CH100_TO_CH138_5G);
  28463. + else if (channel >= 140 && channel <= 165)
  28464. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28465. + EEPROM_IQ_PHASE_CAL_TX0_CH140_TO_CH165_5G);
  28466. + else
  28467. + cal = 0;
  28468. + rt2800_bbp_write(rt2x00dev, 159, cal);
  28469. +
  28470. + /* TX1 IQ Gain */
  28471. + rt2800_bbp_write(rt2x00dev, 158, 0x4a);
  28472. + if (channel <= 14)
  28473. + cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_GAIN_CAL_TX1_2G);
  28474. + else if (channel >= 36 && channel <= 64)
  28475. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28476. + EEPROM_IQ_GAIN_CAL_TX1_CH36_TO_CH64_5G);
  28477. + else if (channel >= 100 && channel <= 138)
  28478. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28479. + EEPROM_IQ_GAIN_CAL_TX1_CH100_TO_CH138_5G);
  28480. + else if (channel >= 140 && channel <= 165)
  28481. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28482. + EEPROM_IQ_GAIN_CAL_TX1_CH140_TO_CH165_5G);
  28483. + else
  28484. + cal = 0;
  28485. + rt2800_bbp_write(rt2x00dev, 159, cal);
  28486. +
  28487. + /* TX1 IQ Phase */
  28488. + rt2800_bbp_write(rt2x00dev, 158, 0x4b);
  28489. + if (channel <= 14)
  28490. + cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_IQ_PHASE_CAL_TX1_2G);
  28491. + else if (channel >= 36 && channel <= 64)
  28492. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28493. + EEPROM_IQ_PHASE_CAL_TX1_CH36_TO_CH64_5G);
  28494. + else if (channel >= 100 && channel <= 138)
  28495. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28496. + EEPROM_IQ_PHASE_CAL_TX1_CH100_TO_CH138_5G);
  28497. + else if (channel >= 140 && channel <= 165)
  28498. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28499. + EEPROM_IQ_PHASE_CAL_TX1_CH140_TO_CH165_5G);
  28500. + else
  28501. + cal = 0;
  28502. + rt2800_bbp_write(rt2x00dev, 159, cal);
  28503. +
  28504. + /* FIXME: possible RX0, RX1 callibration ? */
  28505. +
  28506. + /* RF IQ compensation control */
  28507. + rt2800_bbp_write(rt2x00dev, 158, 0x04);
  28508. + cal = rt2x00_eeprom_byte(rt2x00dev, EEPROM_RF_IQ_COMPENSATION_CONTROL);
  28509. + rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
  28510. +
  28511. + /* RF IQ imbalance compensation control */
  28512. + rt2800_bbp_write(rt2x00dev, 158, 0x03);
  28513. + cal = rt2x00_eeprom_byte(rt2x00dev,
  28514. + EEPROM_RF_IQ_IMBALANCE_COMPENSATION_CONTROL);
  28515. + rt2800_bbp_write(rt2x00dev, 159, cal != 0xff ? cal : 0);
  28516. +}
  28517. +
  28518. +static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
  28519. + struct ieee80211_conf *conf,
  28520. + struct rf_channel *rf,
  28521. + struct channel_info *info)
  28522. +{
  28523. + u32 reg;
  28524. + unsigned int tx_pin;
  28525. + u8 bbp, rfcsr;
  28526. +
  28527. + if (rf->channel <= 14) {
  28528. + info->default_power1 = TXPOWER_G_TO_DEV(info->default_power1);
  28529. + info->default_power2 = TXPOWER_G_TO_DEV(info->default_power2);
  28530. + } else {
  28531. + info->default_power1 = TXPOWER_A_TO_DEV(info->default_power1);
  28532. + info->default_power2 = TXPOWER_A_TO_DEV(info->default_power2);
  28533. + }
  28534. +
  28535. + switch (rt2x00dev->chip.rf) {
  28536. + case RF2020:
  28537. + case RF3020:
  28538. + case RF3021:
  28539. + case RF3022:
  28540. + case RF3320:
  28541. + rt2800_config_channel_rf3xxx(rt2x00dev, conf, rf, info);
  28542. + break;
  28543. + case RF3052:
  28544. + rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
  28545. + break;
  28546. + case RF3290:
  28547. + rt2800_config_channel_rf3290(rt2x00dev, conf, rf, info);
  28548. + break;
  28549. + case RF3322:
  28550. + rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
  28551. + break;
  28552. + case RF5360:
  28553. + case RF5370:
  28554. + case RF5372:
  28555. + case RF5390:
  28556. + case RF5392:
  28557. + rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
  28558. + break;
  28559. + case RF5592:
  28560. + rt2800_config_channel_rf55xx(rt2x00dev, conf, rf, info);
  28561. + break;
  28562. + default:
  28563. + rt2800_config_channel_rf2xxx(rt2x00dev, conf, rf, info);
  28564. + }
  28565. +
  28566. + if (rt2x00_rf(rt2x00dev, RF3290) ||
  28567. + rt2x00_rf(rt2x00dev, RF3322) ||
  28568. + rt2x00_rf(rt2x00dev, RF5360) ||
  28569. + rt2x00_rf(rt2x00dev, RF5370) ||
  28570. + rt2x00_rf(rt2x00dev, RF5372) ||
  28571. + rt2x00_rf(rt2x00dev, RF5390) ||
  28572. + rt2x00_rf(rt2x00dev, RF5392)) {
  28573. + rt2800_rfcsr_read(rt2x00dev, 30, &rfcsr);
  28574. + rt2x00_set_field8(&rfcsr, RFCSR30_TX_H20M, 0);
  28575. + rt2x00_set_field8(&rfcsr, RFCSR30_RX_H20M, 0);
  28576. + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
  28577. +
  28578. + rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
  28579. + rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
  28580. + rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
  28581. + }
  28582. +
  28583. + /*
  28584. + * Change BBP settings
  28585. + */
  28586. + if (rt2x00_rt(rt2x00dev, RT3352)) {
  28587. + rt2800_bbp_write(rt2x00dev, 27, 0x0);
  28588. + rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
  28589. + rt2800_bbp_write(rt2x00dev, 27, 0x20);
  28590. + rt2800_bbp_write(rt2x00dev, 66, 0x26 + rt2x00dev->lna_gain);
  28591. + } else {
  28592. + rt2800_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
  28593. + rt2800_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
  28594. + rt2800_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
  28595. + rt2800_bbp_write(rt2x00dev, 86, 0);
  28596. + }
  28597. +
  28598. + if (rf->channel <= 14) {
  28599. + if (!rt2x00_rt(rt2x00dev, RT5390) &&
  28600. + !rt2x00_rt(rt2x00dev, RT5392)) {
  28601. + if (test_bit(CAPABILITY_EXTERNAL_LNA_BG,
  28602. + &rt2x00dev->cap_flags)) {
  28603. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  28604. + rt2800_bbp_write(rt2x00dev, 75, 0x46);
  28605. + } else {
  28606. + rt2800_bbp_write(rt2x00dev, 82, 0x84);
  28607. + rt2800_bbp_write(rt2x00dev, 75, 0x50);
  28608. + }
  28609. + }
  28610. + } else {
  28611. + if (rt2x00_rt(rt2x00dev, RT3572))
  28612. + rt2800_bbp_write(rt2x00dev, 82, 0x94);
  28613. + else
  28614. + rt2800_bbp_write(rt2x00dev, 82, 0xf2);
  28615. +
  28616. + if (test_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags))
  28617. + rt2800_bbp_write(rt2x00dev, 75, 0x46);
  28618. + else
  28619. + rt2800_bbp_write(rt2x00dev, 75, 0x50);
  28620. + }
  28621. +
  28622. + rt2800_register_read(rt2x00dev, TX_BAND_CFG, &reg);
  28623. + rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_MINUS, conf_is_ht40_minus(conf));
  28624. + rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
  28625. + rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
  28626. + rt2800_register_write(rt2x00dev, TX_BAND_CFG, reg);
  28627. +
  28628. + if (rt2x00_rt(rt2x00dev, RT3572))
  28629. + rt2800_rfcsr_write(rt2x00dev, 8, 0);
  28630. +
  28631. + tx_pin = 0;
  28632. +
  28633. + switch (rt2x00dev->default_ant.tx_chain_num) {
  28634. + case 3:
  28635. + /* Turn on tertiary PAs */
  28636. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN,
  28637. + rf->channel > 14);
  28638. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN,
  28639. + rf->channel <= 14);
  28640. + /* fall-through */
  28641. + case 2:
  28642. + /* Turn on secondary PAs */
  28643. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN,
  28644. + rf->channel > 14);
  28645. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN,
  28646. + rf->channel <= 14);
  28647. + /* fall-through */
  28648. + case 1:
  28649. + /* Turn on primary PAs */
  28650. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN,
  28651. + rf->channel > 14);
  28652. + if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags))
  28653. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
  28654. + else
  28655. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN,
  28656. + rf->channel <= 14);
  28657. + break;
  28658. + }
  28659. +
  28660. + switch (rt2x00dev->default_ant.rx_chain_num) {
  28661. + case 3:
  28662. + /* Turn on tertiary LNAs */
  28663. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A2_EN, 1);
  28664. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G2_EN, 1);
  28665. + /* fall-through */
  28666. + case 2:
  28667. + /* Turn on secondary LNAs */
  28668. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
  28669. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
  28670. + /* fall-through */
  28671. + case 1:
  28672. + /* Turn on primary LNAs */
  28673. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
  28674. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
  28675. + break;
  28676. + }
  28677. +
  28678. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
  28679. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
  28680. +
  28681. + rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  28682. +
  28683. + if (rt2x00_rt(rt2x00dev, RT3572))
  28684. + rt2800_rfcsr_write(rt2x00dev, 8, 0x80);
  28685. +
  28686. + if (rt2x00_rt(rt2x00dev, RT5592)) {
  28687. + rt2800_bbp_write(rt2x00dev, 195, 141);
  28688. + rt2800_bbp_write(rt2x00dev, 196, conf_is_ht40(conf) ? 0x10 : 0x1a);
  28689. +
  28690. + /* AGC init */
  28691. + reg = (rf->channel <= 14 ? 0x1c : 0x24) + 2 * rt2x00dev->lna_gain;
  28692. + rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, reg);
  28693. +
  28694. + rt2800_iq_calibrate(rt2x00dev, rf->channel);
  28695. + }
  28696. +
  28697. + rt2800_bbp_read(rt2x00dev, 4, &bbp);
  28698. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
  28699. + rt2800_bbp_write(rt2x00dev, 4, bbp);
  28700. +
  28701. + rt2800_bbp_read(rt2x00dev, 3, &bbp);
  28702. + rt2x00_set_field8(&bbp, BBP3_HT40_MINUS, conf_is_ht40_minus(conf));
  28703. + rt2800_bbp_write(rt2x00dev, 3, bbp);
  28704. +
  28705. + if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
  28706. + if (conf_is_ht40(conf)) {
  28707. + rt2800_bbp_write(rt2x00dev, 69, 0x1a);
  28708. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  28709. + rt2800_bbp_write(rt2x00dev, 73, 0x16);
  28710. + } else {
  28711. + rt2800_bbp_write(rt2x00dev, 69, 0x16);
  28712. + rt2800_bbp_write(rt2x00dev, 70, 0x08);
  28713. + rt2800_bbp_write(rt2x00dev, 73, 0x11);
  28714. + }
  28715. + }
  28716. +
  28717. + msleep(1);
  28718. +
  28719. + /*
  28720. + * Clear channel statistic counters
  28721. + */
  28722. + rt2800_register_read(rt2x00dev, CH_IDLE_STA, &reg);
  28723. + rt2800_register_read(rt2x00dev, CH_BUSY_STA, &reg);
  28724. + rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &reg);
  28725. +
  28726. + /*
  28727. + * Clear update flag
  28728. + */
  28729. + if (rt2x00_rt(rt2x00dev, RT3352)) {
  28730. + rt2800_bbp_read(rt2x00dev, 49, &bbp);
  28731. + rt2x00_set_field8(&bbp, BBP49_UPDATE_FLAG, 0);
  28732. + rt2800_bbp_write(rt2x00dev, 49, bbp);
  28733. + }
  28734. +}
  28735. +
  28736. +static int rt2800_get_gain_calibration_delta(struct rt2x00_dev *rt2x00dev)
  28737. +{
  28738. + u8 tssi_bounds[9];
  28739. + u8 current_tssi;
  28740. + u16 eeprom;
  28741. + u8 step;
  28742. + int i;
  28743. +
  28744. + /*
  28745. + * First check if temperature compensation is supported.
  28746. + */
  28747. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  28748. + if (!rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC))
  28749. + return 0;
  28750. +
  28751. + /*
  28752. + * Read TSSI boundaries for temperature compensation from
  28753. + * the EEPROM.
  28754. + *
  28755. + * Array idx 0 1 2 3 4 5 6 7 8
  28756. + * Matching Delta value -4 -3 -2 -1 0 +1 +2 +3 +4
  28757. + * Example TSSI bounds 0xF0 0xD0 0xB5 0xA0 0x88 0x45 0x25 0x15 0x00
  28758. + */
  28759. + if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  28760. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG1, &eeprom);
  28761. + tssi_bounds[0] = rt2x00_get_field16(eeprom,
  28762. + EEPROM_TSSI_BOUND_BG1_MINUS4);
  28763. + tssi_bounds[1] = rt2x00_get_field16(eeprom,
  28764. + EEPROM_TSSI_BOUND_BG1_MINUS3);
  28765. +
  28766. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG2, &eeprom);
  28767. + tssi_bounds[2] = rt2x00_get_field16(eeprom,
  28768. + EEPROM_TSSI_BOUND_BG2_MINUS2);
  28769. + tssi_bounds[3] = rt2x00_get_field16(eeprom,
  28770. + EEPROM_TSSI_BOUND_BG2_MINUS1);
  28771. +
  28772. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG3, &eeprom);
  28773. + tssi_bounds[4] = rt2x00_get_field16(eeprom,
  28774. + EEPROM_TSSI_BOUND_BG3_REF);
  28775. + tssi_bounds[5] = rt2x00_get_field16(eeprom,
  28776. + EEPROM_TSSI_BOUND_BG3_PLUS1);
  28777. +
  28778. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG4, &eeprom);
  28779. + tssi_bounds[6] = rt2x00_get_field16(eeprom,
  28780. + EEPROM_TSSI_BOUND_BG4_PLUS2);
  28781. + tssi_bounds[7] = rt2x00_get_field16(eeprom,
  28782. + EEPROM_TSSI_BOUND_BG4_PLUS3);
  28783. +
  28784. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_BG5, &eeprom);
  28785. + tssi_bounds[8] = rt2x00_get_field16(eeprom,
  28786. + EEPROM_TSSI_BOUND_BG5_PLUS4);
  28787. +
  28788. + step = rt2x00_get_field16(eeprom,
  28789. + EEPROM_TSSI_BOUND_BG5_AGC_STEP);
  28790. + } else {
  28791. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A1, &eeprom);
  28792. + tssi_bounds[0] = rt2x00_get_field16(eeprom,
  28793. + EEPROM_TSSI_BOUND_A1_MINUS4);
  28794. + tssi_bounds[1] = rt2x00_get_field16(eeprom,
  28795. + EEPROM_TSSI_BOUND_A1_MINUS3);
  28796. +
  28797. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A2, &eeprom);
  28798. + tssi_bounds[2] = rt2x00_get_field16(eeprom,
  28799. + EEPROM_TSSI_BOUND_A2_MINUS2);
  28800. + tssi_bounds[3] = rt2x00_get_field16(eeprom,
  28801. + EEPROM_TSSI_BOUND_A2_MINUS1);
  28802. +
  28803. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A3, &eeprom);
  28804. + tssi_bounds[4] = rt2x00_get_field16(eeprom,
  28805. + EEPROM_TSSI_BOUND_A3_REF);
  28806. + tssi_bounds[5] = rt2x00_get_field16(eeprom,
  28807. + EEPROM_TSSI_BOUND_A3_PLUS1);
  28808. +
  28809. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A4, &eeprom);
  28810. + tssi_bounds[6] = rt2x00_get_field16(eeprom,
  28811. + EEPROM_TSSI_BOUND_A4_PLUS2);
  28812. + tssi_bounds[7] = rt2x00_get_field16(eeprom,
  28813. + EEPROM_TSSI_BOUND_A4_PLUS3);
  28814. +
  28815. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TSSI_BOUND_A5, &eeprom);
  28816. + tssi_bounds[8] = rt2x00_get_field16(eeprom,
  28817. + EEPROM_TSSI_BOUND_A5_PLUS4);
  28818. +
  28819. + step = rt2x00_get_field16(eeprom,
  28820. + EEPROM_TSSI_BOUND_A5_AGC_STEP);
  28821. + }
  28822. +
  28823. + /*
  28824. + * Check if temperature compensation is supported.
  28825. + */
  28826. + if (tssi_bounds[4] == 0xff || step == 0xff)
  28827. + return 0;
  28828. +
  28829. + /*
  28830. + * Read current TSSI (BBP 49).
  28831. + */
  28832. + rt2800_bbp_read(rt2x00dev, 49, &current_tssi);
  28833. +
  28834. + /*
  28835. + * Compare TSSI value (BBP49) with the compensation boundaries
  28836. + * from the EEPROM and increase or decrease tx power.
  28837. + */
  28838. + for (i = 0; i <= 3; i++) {
  28839. + if (current_tssi > tssi_bounds[i])
  28840. + break;
  28841. + }
  28842. +
  28843. + if (i == 4) {
  28844. + for (i = 8; i >= 5; i--) {
  28845. + if (current_tssi < tssi_bounds[i])
  28846. + break;
  28847. + }
  28848. + }
  28849. +
  28850. + return (i - 4) * step;
  28851. +}
  28852. +
  28853. +static int rt2800_get_txpower_bw_comp(struct rt2x00_dev *rt2x00dev,
  28854. + enum ieee80211_band band)
  28855. +{
  28856. + u16 eeprom;
  28857. + u8 comp_en;
  28858. + u8 comp_type;
  28859. + int comp_value = 0;
  28860. +
  28861. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_DELTA, &eeprom);
  28862. +
  28863. + /*
  28864. + * HT40 compensation not required.
  28865. + */
  28866. + if (eeprom == 0xffff ||
  28867. + !test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  28868. + return 0;
  28869. +
  28870. + if (band == IEEE80211_BAND_2GHZ) {
  28871. + comp_en = rt2x00_get_field16(eeprom,
  28872. + EEPROM_TXPOWER_DELTA_ENABLE_2G);
  28873. + if (comp_en) {
  28874. + comp_type = rt2x00_get_field16(eeprom,
  28875. + EEPROM_TXPOWER_DELTA_TYPE_2G);
  28876. + comp_value = rt2x00_get_field16(eeprom,
  28877. + EEPROM_TXPOWER_DELTA_VALUE_2G);
  28878. + if (!comp_type)
  28879. + comp_value = -comp_value;
  28880. + }
  28881. + } else {
  28882. + comp_en = rt2x00_get_field16(eeprom,
  28883. + EEPROM_TXPOWER_DELTA_ENABLE_5G);
  28884. + if (comp_en) {
  28885. + comp_type = rt2x00_get_field16(eeprom,
  28886. + EEPROM_TXPOWER_DELTA_TYPE_5G);
  28887. + comp_value = rt2x00_get_field16(eeprom,
  28888. + EEPROM_TXPOWER_DELTA_VALUE_5G);
  28889. + if (!comp_type)
  28890. + comp_value = -comp_value;
  28891. + }
  28892. + }
  28893. +
  28894. + return comp_value;
  28895. +}
  28896. +
  28897. +static int rt2800_get_txpower_reg_delta(struct rt2x00_dev *rt2x00dev,
  28898. + int power_level, int max_power)
  28899. +{
  28900. + int delta;
  28901. +
  28902. + if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags))
  28903. + return 0;
  28904. +
  28905. + /*
  28906. + * XXX: We don't know the maximum transmit power of our hardware since
  28907. + * the EEPROM doesn't expose it. We only know that we are calibrated
  28908. + * to 100% tx power.
  28909. + *
  28910. + * Hence, we assume the regulatory limit that cfg80211 calulated for
  28911. + * the current channel is our maximum and if we are requested to lower
  28912. + * the value we just reduce our tx power accordingly.
  28913. + */
  28914. + delta = power_level - max_power;
  28915. + return min(delta, 0);
  28916. +}
  28917. +
  28918. +static u8 rt2800_compensate_txpower(struct rt2x00_dev *rt2x00dev, int is_rate_b,
  28919. + enum ieee80211_band band, int power_level,
  28920. + u8 txpower, int delta)
  28921. +{
  28922. + u16 eeprom;
  28923. + u8 criterion;
  28924. + u8 eirp_txpower;
  28925. + u8 eirp_txpower_criterion;
  28926. + u8 reg_limit;
  28927. +
  28928. + if (test_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags)) {
  28929. + /*
  28930. + * Check if eirp txpower exceed txpower_limit.
  28931. + * We use OFDM 6M as criterion and its eirp txpower
  28932. + * is stored at EEPROM_EIRP_MAX_TX_POWER.
  28933. + * .11b data rate need add additional 4dbm
  28934. + * when calculating eirp txpower.
  28935. + */
  28936. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + 1,
  28937. + &eeprom);
  28938. + criterion = rt2x00_get_field16(eeprom,
  28939. + EEPROM_TXPOWER_BYRATE_RATE0);
  28940. +
  28941. + rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER,
  28942. + &eeprom);
  28943. +
  28944. + if (band == IEEE80211_BAND_2GHZ)
  28945. + eirp_txpower_criterion = rt2x00_get_field16(eeprom,
  28946. + EEPROM_EIRP_MAX_TX_POWER_2GHZ);
  28947. + else
  28948. + eirp_txpower_criterion = rt2x00_get_field16(eeprom,
  28949. + EEPROM_EIRP_MAX_TX_POWER_5GHZ);
  28950. +
  28951. + eirp_txpower = eirp_txpower_criterion + (txpower - criterion) +
  28952. + (is_rate_b ? 4 : 0) + delta;
  28953. +
  28954. + reg_limit = (eirp_txpower > power_level) ?
  28955. + (eirp_txpower - power_level) : 0;
  28956. + } else
  28957. + reg_limit = 0;
  28958. +
  28959. + txpower = max(0, txpower + delta - reg_limit);
  28960. + return min_t(u8, txpower, 0xc);
  28961. +}
  28962. +
  28963. +/*
  28964. + * We configure transmit power using MAC TX_PWR_CFG_{0,...,N} registers and
  28965. + * BBP R1 register. TX_PWR_CFG_X allow to configure per rate TX power values,
  28966. + * 4 bits for each rate (tune from 0 to 15 dBm). BBP_R1 controls transmit power
  28967. + * for all rates, but allow to set only 4 discrete values: -12, -6, 0 and 6 dBm.
  28968. + * Reference per rate transmit power values are located in the EEPROM at
  28969. + * EEPROM_TXPOWER_BYRATE offset. We adjust them and BBP R1 settings according to
  28970. + * current conditions (i.e. band, bandwidth, temperature, user settings).
  28971. + */
  28972. +static void rt2800_config_txpower(struct rt2x00_dev *rt2x00dev,
  28973. + struct ieee80211_channel *chan,
  28974. + int power_level)
  28975. +{
  28976. + u8 txpower, r1;
  28977. + u16 eeprom;
  28978. + u32 reg, offset;
  28979. + int i, is_rate_b, delta, power_ctrl;
  28980. + enum ieee80211_band band = chan->band;
  28981. +
  28982. + /*
  28983. + * Calculate HT40 compensation. For 40MHz we need to add or subtract
  28984. + * value read from EEPROM (different for 2GHz and for 5GHz).
  28985. + */
  28986. + delta = rt2800_get_txpower_bw_comp(rt2x00dev, band);
  28987. +
  28988. + /*
  28989. + * Calculate temperature compensation. Depends on measurement of current
  28990. + * TSSI (Transmitter Signal Strength Indication) we know TX power (due
  28991. + * to temperature or maybe other factors) is smaller or bigger than
  28992. + * expected. We adjust it, based on TSSI reference and boundaries values
  28993. + * provided in EEPROM.
  28994. + */
  28995. + delta += rt2800_get_gain_calibration_delta(rt2x00dev);
  28996. +
  28997. + /*
  28998. + * Decrease power according to user settings, on devices with unknown
  28999. + * maximum tx power. For other devices we take user power_level into
  29000. + * consideration on rt2800_compensate_txpower().
  29001. + */
  29002. + delta += rt2800_get_txpower_reg_delta(rt2x00dev, power_level,
  29003. + chan->max_power);
  29004. +
  29005. + /*
  29006. + * BBP_R1 controls TX power for all rates, it allow to set the following
  29007. + * gains -12, -6, 0, +6 dBm by setting values 2, 1, 0, 3 respectively.
  29008. + *
  29009. + * TODO: we do not use +6 dBm option to do not increase power beyond
  29010. + * regulatory limit, however this could be utilized for devices with
  29011. + * CAPABILITY_POWER_LIMIT.
  29012. + *
  29013. + * TODO: add different temperature compensation code for RT3290 & RT5390
  29014. + * to allow to use BBP_R1 for those chips.
  29015. + */
  29016. + if (!rt2x00_rt(rt2x00dev, RT3290) &&
  29017. + !rt2x00_rt(rt2x00dev, RT5390)) {
  29018. + rt2800_bbp_read(rt2x00dev, 1, &r1);
  29019. + if (delta <= -12) {
  29020. + power_ctrl = 2;
  29021. + delta += 12;
  29022. + } else if (delta <= -6) {
  29023. + power_ctrl = 1;
  29024. + delta += 6;
  29025. + } else {
  29026. + power_ctrl = 0;
  29027. + }
  29028. + rt2x00_set_field8(&r1, BBP1_TX_POWER_CTRL, power_ctrl);
  29029. + rt2800_bbp_write(rt2x00dev, 1, r1);
  29030. + }
  29031. +
  29032. + offset = TX_PWR_CFG_0;
  29033. +
  29034. + for (i = 0; i < EEPROM_TXPOWER_BYRATE_SIZE; i += 2) {
  29035. + /* just to be safe */
  29036. + if (offset > TX_PWR_CFG_4)
  29037. + break;
  29038. +
  29039. + rt2800_register_read(rt2x00dev, offset, &reg);
  29040. +
  29041. + /* read the next four txpower values */
  29042. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i,
  29043. + &eeprom);
  29044. +
  29045. + is_rate_b = i ? 0 : 1;
  29046. + /*
  29047. + * TX_PWR_CFG_0: 1MBS, TX_PWR_CFG_1: 24MBS,
  29048. + * TX_PWR_CFG_2: MCS4, TX_PWR_CFG_3: MCS12,
  29049. + * TX_PWR_CFG_4: unknown
  29050. + */
  29051. + txpower = rt2x00_get_field16(eeprom,
  29052. + EEPROM_TXPOWER_BYRATE_RATE0);
  29053. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29054. + power_level, txpower, delta);
  29055. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE0, txpower);
  29056. +
  29057. + /*
  29058. + * TX_PWR_CFG_0: 2MBS, TX_PWR_CFG_1: 36MBS,
  29059. + * TX_PWR_CFG_2: MCS5, TX_PWR_CFG_3: MCS13,
  29060. + * TX_PWR_CFG_4: unknown
  29061. + */
  29062. + txpower = rt2x00_get_field16(eeprom,
  29063. + EEPROM_TXPOWER_BYRATE_RATE1);
  29064. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29065. + power_level, txpower, delta);
  29066. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE1, txpower);
  29067. +
  29068. + /*
  29069. + * TX_PWR_CFG_0: 5.5MBS, TX_PWR_CFG_1: 48MBS,
  29070. + * TX_PWR_CFG_2: MCS6, TX_PWR_CFG_3: MCS14,
  29071. + * TX_PWR_CFG_4: unknown
  29072. + */
  29073. + txpower = rt2x00_get_field16(eeprom,
  29074. + EEPROM_TXPOWER_BYRATE_RATE2);
  29075. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29076. + power_level, txpower, delta);
  29077. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE2, txpower);
  29078. +
  29079. + /*
  29080. + * TX_PWR_CFG_0: 11MBS, TX_PWR_CFG_1: 54MBS,
  29081. + * TX_PWR_CFG_2: MCS7, TX_PWR_CFG_3: MCS15,
  29082. + * TX_PWR_CFG_4: unknown
  29083. + */
  29084. + txpower = rt2x00_get_field16(eeprom,
  29085. + EEPROM_TXPOWER_BYRATE_RATE3);
  29086. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29087. + power_level, txpower, delta);
  29088. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE3, txpower);
  29089. +
  29090. + /* read the next four txpower values */
  29091. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXPOWER_BYRATE + i + 1,
  29092. + &eeprom);
  29093. +
  29094. + is_rate_b = 0;
  29095. + /*
  29096. + * TX_PWR_CFG_0: 6MBS, TX_PWR_CFG_1: MCS0,
  29097. + * TX_PWR_CFG_2: MCS8, TX_PWR_CFG_3: unknown,
  29098. + * TX_PWR_CFG_4: unknown
  29099. + */
  29100. + txpower = rt2x00_get_field16(eeprom,
  29101. + EEPROM_TXPOWER_BYRATE_RATE0);
  29102. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29103. + power_level, txpower, delta);
  29104. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE4, txpower);
  29105. +
  29106. + /*
  29107. + * TX_PWR_CFG_0: 9MBS, TX_PWR_CFG_1: MCS1,
  29108. + * TX_PWR_CFG_2: MCS9, TX_PWR_CFG_3: unknown,
  29109. + * TX_PWR_CFG_4: unknown
  29110. + */
  29111. + txpower = rt2x00_get_field16(eeprom,
  29112. + EEPROM_TXPOWER_BYRATE_RATE1);
  29113. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29114. + power_level, txpower, delta);
  29115. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE5, txpower);
  29116. +
  29117. + /*
  29118. + * TX_PWR_CFG_0: 12MBS, TX_PWR_CFG_1: MCS2,
  29119. + * TX_PWR_CFG_2: MCS10, TX_PWR_CFG_3: unknown,
  29120. + * TX_PWR_CFG_4: unknown
  29121. + */
  29122. + txpower = rt2x00_get_field16(eeprom,
  29123. + EEPROM_TXPOWER_BYRATE_RATE2);
  29124. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29125. + power_level, txpower, delta);
  29126. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE6, txpower);
  29127. +
  29128. + /*
  29129. + * TX_PWR_CFG_0: 18MBS, TX_PWR_CFG_1: MCS3,
  29130. + * TX_PWR_CFG_2: MCS11, TX_PWR_CFG_3: unknown,
  29131. + * TX_PWR_CFG_4: unknown
  29132. + */
  29133. + txpower = rt2x00_get_field16(eeprom,
  29134. + EEPROM_TXPOWER_BYRATE_RATE3);
  29135. + txpower = rt2800_compensate_txpower(rt2x00dev, is_rate_b, band,
  29136. + power_level, txpower, delta);
  29137. + rt2x00_set_field32(&reg, TX_PWR_CFG_RATE7, txpower);
  29138. +
  29139. + rt2800_register_write(rt2x00dev, offset, reg);
  29140. +
  29141. + /* next TX_PWR_CFG register */
  29142. + offset += 4;
  29143. + }
  29144. +}
  29145. +
  29146. +void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev)
  29147. +{
  29148. + rt2800_config_txpower(rt2x00dev, rt2x00dev->hw->conf.chandef.chan,
  29149. + rt2x00dev->tx_power);
  29150. +}
  29151. +EXPORT_SYMBOL_GPL(rt2800_gain_calibration);
  29152. +
  29153. +void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
  29154. +{
  29155. + u32 tx_pin;
  29156. + u8 rfcsr;
  29157. +
  29158. + /*
  29159. + * A voltage-controlled oscillator(VCO) is an electronic oscillator
  29160. + * designed to be controlled in oscillation frequency by a voltage
  29161. + * input. Maybe the temperature will affect the frequency of
  29162. + * oscillation to be shifted. The VCO calibration will be called
  29163. + * periodically to adjust the frequency to be precision.
  29164. + */
  29165. +
  29166. + rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
  29167. + tx_pin &= TX_PIN_CFG_PA_PE_DISABLE;
  29168. + rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  29169. +
  29170. + switch (rt2x00dev->chip.rf) {
  29171. + case RF2020:
  29172. + case RF3020:
  29173. + case RF3021:
  29174. + case RF3022:
  29175. + case RF3320:
  29176. + case RF3052:
  29177. + rt2800_rfcsr_read(rt2x00dev, 7, &rfcsr);
  29178. + rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
  29179. + rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
  29180. + break;
  29181. + case RF3290:
  29182. + case RF5360:
  29183. + case RF5370:
  29184. + case RF5372:
  29185. + case RF5390:
  29186. + case RF5392:
  29187. + rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
  29188. + rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
  29189. + rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
  29190. + break;
  29191. + default:
  29192. + return;
  29193. + }
  29194. +
  29195. + mdelay(1);
  29196. +
  29197. + rt2800_register_read(rt2x00dev, TX_PIN_CFG, &tx_pin);
  29198. + if (rt2x00dev->rf_channel <= 14) {
  29199. + switch (rt2x00dev->default_ant.tx_chain_num) {
  29200. + case 3:
  29201. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G2_EN, 1);
  29202. + /* fall through */
  29203. + case 2:
  29204. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
  29205. + /* fall through */
  29206. + case 1:
  29207. + default:
  29208. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
  29209. + break;
  29210. + }
  29211. + } else {
  29212. + switch (rt2x00dev->default_ant.tx_chain_num) {
  29213. + case 3:
  29214. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A2_EN, 1);
  29215. + /* fall through */
  29216. + case 2:
  29217. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
  29218. + /* fall through */
  29219. + case 1:
  29220. + default:
  29221. + rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
  29222. + break;
  29223. + }
  29224. + }
  29225. + rt2800_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
  29226. +
  29227. +}
  29228. +EXPORT_SYMBOL_GPL(rt2800_vco_calibration);
  29229. +
  29230. +static void rt2800_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  29231. + struct rt2x00lib_conf *libconf)
  29232. +{
  29233. + u32 reg;
  29234. +
  29235. + rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
  29236. + rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT,
  29237. + libconf->conf->short_frame_max_tx_count);
  29238. + rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT,
  29239. + libconf->conf->long_frame_max_tx_count);
  29240. + rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
  29241. +}
  29242. +
  29243. +static void rt2800_config_ps(struct rt2x00_dev *rt2x00dev,
  29244. + struct rt2x00lib_conf *libconf)
  29245. +{
  29246. + enum dev_state state =
  29247. + (libconf->conf->flags & IEEE80211_CONF_PS) ?
  29248. + STATE_SLEEP : STATE_AWAKE;
  29249. + u32 reg;
  29250. +
  29251. + if (state == STATE_SLEEP) {
  29252. + rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
  29253. +
  29254. + rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  29255. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
  29256. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
  29257. + libconf->conf->listen_interval - 1);
  29258. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 1);
  29259. + rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  29260. +
  29261. + rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  29262. + } else {
  29263. + rt2800_register_read(rt2x00dev, AUTOWAKEUP_CFG, &reg);
  29264. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
  29265. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
  29266. + rt2x00_set_field32(&reg, AUTOWAKEUP_CFG_AUTOWAKE, 0);
  29267. + rt2800_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
  29268. +
  29269. + rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
  29270. + }
  29271. +}
  29272. +
  29273. +void rt2800_config(struct rt2x00_dev *rt2x00dev,
  29274. + struct rt2x00lib_conf *libconf,
  29275. + const unsigned int flags)
  29276. +{
  29277. + /* Always recalculate LNA gain before changing configuration */
  29278. + rt2800_config_lna_gain(rt2x00dev, libconf);
  29279. +
  29280. + if (flags & IEEE80211_CONF_CHANGE_CHANNEL) {
  29281. + rt2800_config_channel(rt2x00dev, libconf->conf,
  29282. + &libconf->rf, &libconf->channel);
  29283. + rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
  29284. + libconf->conf->power_level);
  29285. + }
  29286. + if (flags & IEEE80211_CONF_CHANGE_POWER)
  29287. + rt2800_config_txpower(rt2x00dev, libconf->conf->chandef.chan,
  29288. + libconf->conf->power_level);
  29289. + if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  29290. + rt2800_config_retry_limit(rt2x00dev, libconf);
  29291. + if (flags & IEEE80211_CONF_CHANGE_PS)
  29292. + rt2800_config_ps(rt2x00dev, libconf);
  29293. +}
  29294. +EXPORT_SYMBOL_GPL(rt2800_config);
  29295. +
  29296. +/*
  29297. + * Link tuning
  29298. + */
  29299. +void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
  29300. +{
  29301. + u32 reg;
  29302. +
  29303. + /*
  29304. + * Update FCS error count from register.
  29305. + */
  29306. + rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  29307. + qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
  29308. +}
  29309. +EXPORT_SYMBOL_GPL(rt2800_link_stats);
  29310. +
  29311. +static u8 rt2800_get_default_vgc(struct rt2x00_dev *rt2x00dev)
  29312. +{
  29313. + u8 vgc;
  29314. +
  29315. + if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
  29316. + if (rt2x00_rt(rt2x00dev, RT3070) ||
  29317. + rt2x00_rt(rt2x00dev, RT3071) ||
  29318. + rt2x00_rt(rt2x00dev, RT3090) ||
  29319. + rt2x00_rt(rt2x00dev, RT3290) ||
  29320. + rt2x00_rt(rt2x00dev, RT3390) ||
  29321. + rt2x00_rt(rt2x00dev, RT3572) ||
  29322. + rt2x00_rt(rt2x00dev, RT5390) ||
  29323. + rt2x00_rt(rt2x00dev, RT5392) ||
  29324. + rt2x00_rt(rt2x00dev, RT5592))
  29325. + vgc = 0x1c + (2 * rt2x00dev->lna_gain);
  29326. + else
  29327. + vgc = 0x2e + rt2x00dev->lna_gain;
  29328. + } else { /* 5GHZ band */
  29329. + if (rt2x00_rt(rt2x00dev, RT3572))
  29330. + vgc = 0x22 + (rt2x00dev->lna_gain * 5) / 3;
  29331. + else if (rt2x00_rt(rt2x00dev, RT5592))
  29332. + vgc = 0x24 + (2 * rt2x00dev->lna_gain);
  29333. + else {
  29334. + if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
  29335. + vgc = 0x32 + (rt2x00dev->lna_gain * 5) / 3;
  29336. + else
  29337. + vgc = 0x3a + (rt2x00dev->lna_gain * 5) / 3;
  29338. + }
  29339. + }
  29340. +
  29341. + return vgc;
  29342. +}
  29343. +
  29344. +static inline void rt2800_set_vgc(struct rt2x00_dev *rt2x00dev,
  29345. + struct link_qual *qual, u8 vgc_level)
  29346. +{
  29347. + if (qual->vgc_level != vgc_level) {
  29348. + if (rt2x00_rt(rt2x00dev, RT5592)) {
  29349. + rt2800_bbp_write(rt2x00dev, 83, qual->rssi > -65 ? 0x4a : 0x7a);
  29350. + rt2800_bbp_write_with_rx_chain(rt2x00dev, 66, vgc_level);
  29351. + } else
  29352. + rt2800_bbp_write(rt2x00dev, 66, vgc_level);
  29353. + qual->vgc_level = vgc_level;
  29354. + qual->vgc_level_reg = vgc_level;
  29355. + }
  29356. +}
  29357. +
  29358. +void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual)
  29359. +{
  29360. + rt2800_set_vgc(rt2x00dev, qual, rt2800_get_default_vgc(rt2x00dev));
  29361. +}
  29362. +EXPORT_SYMBOL_GPL(rt2800_reset_tuner);
  29363. +
  29364. +void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
  29365. + const u32 count)
  29366. +{
  29367. + u8 vgc;
  29368. +
  29369. + if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C))
  29370. + return;
  29371. + /*
  29372. + * When RSSI is better then -80 increase VGC level with 0x10, except
  29373. + * for rt5592 chip.
  29374. + */
  29375. +
  29376. + vgc = rt2800_get_default_vgc(rt2x00dev);
  29377. +
  29378. + if (rt2x00_rt(rt2x00dev, RT5592)) {
  29379. + if (qual->rssi > -65)
  29380. + vgc += 0x20;
  29381. + } else {
  29382. + if (qual->rssi > -80)
  29383. + vgc += 0x10;
  29384. + }
  29385. +
  29386. + rt2800_set_vgc(rt2x00dev, qual, vgc);
  29387. +}
  29388. +EXPORT_SYMBOL_GPL(rt2800_link_tuner);
  29389. +
  29390. +/*
  29391. + * Initialization functions.
  29392. + */
  29393. +static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
  29394. +{
  29395. + u32 reg;
  29396. + u16 eeprom;
  29397. + unsigned int i;
  29398. + int ret;
  29399. +
  29400. + rt2800_disable_wpdma(rt2x00dev);
  29401. +
  29402. + ret = rt2800_drv_init_registers(rt2x00dev);
  29403. + if (ret)
  29404. + return ret;
  29405. +
  29406. + rt2800_register_read(rt2x00dev, BCN_OFFSET0, &reg);
  29407. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
  29408. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
  29409. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
  29410. + rt2x00_set_field32(&reg, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
  29411. + rt2800_register_write(rt2x00dev, BCN_OFFSET0, reg);
  29412. +
  29413. + rt2800_register_read(rt2x00dev, BCN_OFFSET1, &reg);
  29414. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
  29415. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
  29416. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
  29417. + rt2x00_set_field32(&reg, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
  29418. + rt2800_register_write(rt2x00dev, BCN_OFFSET1, reg);
  29419. +
  29420. + rt2800_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
  29421. + rt2800_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
  29422. +
  29423. + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
  29424. +
  29425. + rt2800_register_read(rt2x00dev, BCN_TIME_CFG, &reg);
  29426. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_INTERVAL, 1600);
  29427. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_TICKING, 0);
  29428. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TSF_SYNC, 0);
  29429. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TBTT_ENABLE, 0);
  29430. + rt2x00_set_field32(&reg, BCN_TIME_CFG_BEACON_GEN, 0);
  29431. + rt2x00_set_field32(&reg, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
  29432. + rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
  29433. +
  29434. + rt2800_config_filter(rt2x00dev, FIF_ALLMULTI);
  29435. +
  29436. + rt2800_register_read(rt2x00dev, BKOFF_SLOT_CFG, &reg);
  29437. + rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_SLOT_TIME, 9);
  29438. + rt2x00_set_field32(&reg, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
  29439. + rt2800_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
  29440. +
  29441. + if (rt2x00_rt(rt2x00dev, RT3290)) {
  29442. + rt2800_register_read(rt2x00dev, WLAN_FUN_CTRL, &reg);
  29443. + if (rt2x00_get_field32(reg, WLAN_EN) == 1) {
  29444. + rt2x00_set_field32(&reg, PCIE_APP0_CLK_REQ, 1);
  29445. + rt2800_register_write(rt2x00dev, WLAN_FUN_CTRL, reg);
  29446. + }
  29447. +
  29448. + rt2800_register_read(rt2x00dev, CMB_CTRL, &reg);
  29449. + if (!(rt2x00_get_field32(reg, LDO0_EN) == 1)) {
  29450. + rt2x00_set_field32(&reg, LDO0_EN, 1);
  29451. + rt2x00_set_field32(&reg, LDO_BGSEL, 3);
  29452. + rt2800_register_write(rt2x00dev, CMB_CTRL, reg);
  29453. + }
  29454. +
  29455. + rt2800_register_read(rt2x00dev, OSC_CTRL, &reg);
  29456. + rt2x00_set_field32(&reg, OSC_ROSC_EN, 1);
  29457. + rt2x00_set_field32(&reg, OSC_CAL_REQ, 1);
  29458. + rt2x00_set_field32(&reg, OSC_REF_CYCLE, 0x27);
  29459. + rt2800_register_write(rt2x00dev, OSC_CTRL, reg);
  29460. +
  29461. + rt2800_register_read(rt2x00dev, COEX_CFG0, &reg);
  29462. + rt2x00_set_field32(&reg, COEX_CFG_ANT, 0x5e);
  29463. + rt2800_register_write(rt2x00dev, COEX_CFG0, reg);
  29464. +
  29465. + rt2800_register_read(rt2x00dev, COEX_CFG2, &reg);
  29466. + rt2x00_set_field32(&reg, BT_COEX_CFG1, 0x00);
  29467. + rt2x00_set_field32(&reg, BT_COEX_CFG0, 0x17);
  29468. + rt2x00_set_field32(&reg, WL_COEX_CFG1, 0x93);
  29469. + rt2x00_set_field32(&reg, WL_COEX_CFG0, 0x7f);
  29470. + rt2800_register_write(rt2x00dev, COEX_CFG2, reg);
  29471. +
  29472. + rt2800_register_read(rt2x00dev, PLL_CTRL, &reg);
  29473. + rt2x00_set_field32(&reg, PLL_CONTROL, 1);
  29474. + rt2800_register_write(rt2x00dev, PLL_CTRL, reg);
  29475. + }
  29476. +
  29477. + if (rt2x00_rt(rt2x00dev, RT3071) ||
  29478. + rt2x00_rt(rt2x00dev, RT3090) ||
  29479. + rt2x00_rt(rt2x00dev, RT3290) ||
  29480. + rt2x00_rt(rt2x00dev, RT3390)) {
  29481. +
  29482. + if (rt2x00_rt(rt2x00dev, RT3290))
  29483. + rt2800_register_write(rt2x00dev, TX_SW_CFG0,
  29484. + 0x00000404);
  29485. + else
  29486. + rt2800_register_write(rt2x00dev, TX_SW_CFG0,
  29487. + 0x00000400);
  29488. +
  29489. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  29490. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
  29491. + rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
  29492. + rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
  29493. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  29494. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
  29495. + rt2800_register_write(rt2x00dev, TX_SW_CFG2,
  29496. + 0x0000002c);
  29497. + else
  29498. + rt2800_register_write(rt2x00dev, TX_SW_CFG2,
  29499. + 0x0000000f);
  29500. + } else {
  29501. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  29502. + }
  29503. + } else if (rt2x00_rt(rt2x00dev, RT3070)) {
  29504. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  29505. +
  29506. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
  29507. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  29508. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x0000002c);
  29509. + } else {
  29510. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  29511. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  29512. + }
  29513. + } else if (rt2800_is_305x_soc(rt2x00dev)) {
  29514. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  29515. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
  29516. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000030);
  29517. + } else if (rt2x00_rt(rt2x00dev, RT3352)) {
  29518. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000402);
  29519. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  29520. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  29521. + } else if (rt2x00_rt(rt2x00dev, RT3572)) {
  29522. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
  29523. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  29524. + } else if (rt2x00_rt(rt2x00dev, RT5390) ||
  29525. + rt2x00_rt(rt2x00dev, RT5392) ||
  29526. + rt2x00_rt(rt2x00dev, RT5592)) {
  29527. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000404);
  29528. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  29529. + rt2800_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
  29530. + } else {
  29531. + rt2800_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
  29532. + rt2800_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
  29533. + }
  29534. +
  29535. + rt2800_register_read(rt2x00dev, TX_LINK_CFG, &reg);
  29536. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
  29537. + rt2x00_set_field32(&reg, TX_LINK_CFG_MFB_ENABLE, 0);
  29538. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
  29539. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_MRQ_EN, 0);
  29540. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_RDG_EN, 0);
  29541. + rt2x00_set_field32(&reg, TX_LINK_CFG_TX_CF_ACK_EN, 1);
  29542. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFB, 0);
  29543. + rt2x00_set_field32(&reg, TX_LINK_CFG_REMOTE_MFS, 0);
  29544. + rt2800_register_write(rt2x00dev, TX_LINK_CFG, reg);
  29545. +
  29546. + rt2800_register_read(rt2x00dev, TX_TIMEOUT_CFG, &reg);
  29547. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
  29548. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT, 32);
  29549. + rt2x00_set_field32(&reg, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
  29550. + rt2800_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
  29551. +
  29552. + rt2800_register_read(rt2x00dev, MAX_LEN_CFG, &reg);
  29553. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
  29554. + if (rt2x00_rt_rev_gte(rt2x00dev, RT2872, REV_RT2872E) ||
  29555. + rt2x00_rt(rt2x00dev, RT2883) ||
  29556. + rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070E))
  29557. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 2);
  29558. + else
  29559. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MAX_PSDU, 1);
  29560. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_PSDU, 0);
  29561. + rt2x00_set_field32(&reg, MAX_LEN_CFG_MIN_MPDU, 0);
  29562. + rt2800_register_write(rt2x00dev, MAX_LEN_CFG, reg);
  29563. +
  29564. + rt2800_register_read(rt2x00dev, LED_CFG, &reg);
  29565. + rt2x00_set_field32(&reg, LED_CFG_ON_PERIOD, 70);
  29566. + rt2x00_set_field32(&reg, LED_CFG_OFF_PERIOD, 30);
  29567. + rt2x00_set_field32(&reg, LED_CFG_SLOW_BLINK_PERIOD, 3);
  29568. + rt2x00_set_field32(&reg, LED_CFG_R_LED_MODE, 3);
  29569. + rt2x00_set_field32(&reg, LED_CFG_G_LED_MODE, 3);
  29570. + rt2x00_set_field32(&reg, LED_CFG_Y_LED_MODE, 3);
  29571. + rt2x00_set_field32(&reg, LED_CFG_LED_POLAR, 1);
  29572. + rt2800_register_write(rt2x00dev, LED_CFG, reg);
  29573. +
  29574. + rt2800_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
  29575. +
  29576. + rt2800_register_read(rt2x00dev, TX_RTY_CFG, &reg);
  29577. + rt2x00_set_field32(&reg, TX_RTY_CFG_SHORT_RTY_LIMIT, 15);
  29578. + rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_LIMIT, 31);
  29579. + rt2x00_set_field32(&reg, TX_RTY_CFG_LONG_RTY_THRE, 2000);
  29580. + rt2x00_set_field32(&reg, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
  29581. + rt2x00_set_field32(&reg, TX_RTY_CFG_AGG_RTY_MODE, 0);
  29582. + rt2x00_set_field32(&reg, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
  29583. + rt2800_register_write(rt2x00dev, TX_RTY_CFG, reg);
  29584. +
  29585. + rt2800_register_read(rt2x00dev, AUTO_RSP_CFG, &reg);
  29586. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_AUTORESPONDER, 1);
  29587. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_BAC_ACK_POLICY, 1);
  29588. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MMODE, 0);
  29589. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_CTS_40_MREF, 0);
  29590. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_AR_PREAMBLE, 1);
  29591. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
  29592. + rt2x00_set_field32(&reg, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
  29593. + rt2800_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
  29594. +
  29595. + rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  29596. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_RATE, 3);
  29597. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_CTRL, 0);
  29598. + rt2x00_set_field32(&reg, CCK_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29599. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29600. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29601. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29602. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  29603. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29604. + rt2x00_set_field32(&reg, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  29605. + rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, 1);
  29606. + rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  29607. +
  29608. + rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  29609. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_RATE, 3);
  29610. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_CTRL, 0);
  29611. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29612. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29613. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29614. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29615. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  29616. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29617. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  29618. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, 1);
  29619. + rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  29620. +
  29621. + rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  29622. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
  29623. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_CTRL, 0);
  29624. + rt2x00_set_field32(&reg, MM20_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29625. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29626. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29627. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29628. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  29629. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29630. + rt2x00_set_field32(&reg, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  29631. + rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, 0);
  29632. + rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  29633. +
  29634. + rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  29635. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
  29636. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_CTRL, 0);
  29637. + rt2x00_set_field32(&reg, MM40_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29638. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29639. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29640. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29641. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  29642. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29643. + rt2x00_set_field32(&reg, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  29644. + rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, 0);
  29645. + rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  29646. +
  29647. + rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  29648. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
  29649. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_CTRL, 0);
  29650. + rt2x00_set_field32(&reg, GF20_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29651. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29652. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29653. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29654. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
  29655. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29656. + rt2x00_set_field32(&reg, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
  29657. + rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, 0);
  29658. + rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  29659. +
  29660. + rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  29661. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
  29662. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_CTRL, 0);
  29663. + rt2x00_set_field32(&reg, GF40_PROT_CFG_PROTECT_NAV_SHORT, 1);
  29664. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
  29665. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
  29666. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
  29667. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
  29668. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
  29669. + rt2x00_set_field32(&reg, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
  29670. + rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, 0);
  29671. + rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  29672. +
  29673. + if (rt2x00_is_usb(rt2x00dev)) {
  29674. + rt2800_register_write(rt2x00dev, PBF_CFG, 0xf40006);
  29675. +
  29676. + rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  29677. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
  29678. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
  29679. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
  29680. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
  29681. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
  29682. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
  29683. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
  29684. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
  29685. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
  29686. + rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  29687. + }
  29688. +
  29689. + /*
  29690. + * The legacy driver also sets TXOP_CTRL_CFG_RESERVED_TRUN_EN to 1
  29691. + * although it is reserved.
  29692. + */
  29693. + rt2800_register_read(rt2x00dev, TXOP_CTRL_CFG, &reg);
  29694. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TIMEOUT_TRUN_EN, 1);
  29695. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_AC_TRUN_EN, 1);
  29696. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_TXRATEGRP_TRUN_EN, 1);
  29697. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_USER_MODE_TRUN_EN, 1);
  29698. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_MIMO_PS_TRUN_EN, 1);
  29699. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_RESERVED_TRUN_EN, 1);
  29700. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_LSIG_TXOP_EN, 0);
  29701. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_EN, 0);
  29702. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CCA_DLY, 88);
  29703. + rt2x00_set_field32(&reg, TXOP_CTRL_CFG_EXT_CWMIN, 0);
  29704. + rt2800_register_write(rt2x00dev, TXOP_CTRL_CFG, reg);
  29705. +
  29706. + reg = rt2x00_rt(rt2x00dev, RT5592) ? 0x00000082 : 0x00000002;
  29707. + rt2800_register_write(rt2x00dev, TXOP_HLDR_ET, reg);
  29708. +
  29709. + rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  29710. + rt2x00_set_field32(&reg, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
  29711. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES,
  29712. + IEEE80211_MAX_RTS_THRESHOLD);
  29713. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_FBK_EN, 0);
  29714. + rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  29715. +
  29716. + rt2800_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
  29717. +
  29718. + /*
  29719. + * Usually the CCK SIFS time should be set to 10 and the OFDM SIFS
  29720. + * time should be set to 16. However, the original Ralink driver uses
  29721. + * 16 for both and indeed using a value of 10 for CCK SIFS results in
  29722. + * connection problems with 11g + CTS protection. Hence, use the same
  29723. + * defaults as the Ralink driver: 16 for both, CCK and OFDM SIFS.
  29724. + */
  29725. + rt2800_register_read(rt2x00dev, XIFS_TIME_CFG, &reg);
  29726. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_CCKM_SIFS_TIME, 16);
  29727. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_SIFS_TIME, 16);
  29728. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
  29729. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_EIFS, 314);
  29730. + rt2x00_set_field32(&reg, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
  29731. + rt2800_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
  29732. +
  29733. + rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
  29734. +
  29735. + /*
  29736. + * ASIC will keep garbage value after boot, clear encryption keys.
  29737. + */
  29738. + for (i = 0; i < 4; i++)
  29739. + rt2800_register_write(rt2x00dev,
  29740. + SHARED_KEY_MODE_ENTRY(i), 0);
  29741. +
  29742. + for (i = 0; i < 256; i++) {
  29743. + rt2800_config_wcid(rt2x00dev, NULL, i);
  29744. + rt2800_delete_wcid_attr(rt2x00dev, i);
  29745. + rt2800_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
  29746. + }
  29747. +
  29748. + /*
  29749. + * Clear all beacons
  29750. + */
  29751. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE0);
  29752. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE1);
  29753. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE2);
  29754. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE3);
  29755. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE4);
  29756. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE5);
  29757. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE6);
  29758. + rt2800_clear_beacon_register(rt2x00dev, HW_BEACON_BASE7);
  29759. +
  29760. + if (rt2x00_is_usb(rt2x00dev)) {
  29761. + rt2800_register_read(rt2x00dev, US_CYC_CNT, &reg);
  29762. + rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 30);
  29763. + rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
  29764. + } else if (rt2x00_is_pcie(rt2x00dev)) {
  29765. + rt2800_register_read(rt2x00dev, US_CYC_CNT, &reg);
  29766. + rt2x00_set_field32(&reg, US_CYC_CNT_CLOCK_CYCLE, 125);
  29767. + rt2800_register_write(rt2x00dev, US_CYC_CNT, reg);
  29768. + }
  29769. +
  29770. + rt2800_register_read(rt2x00dev, HT_FBK_CFG0, &reg);
  29771. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS0FBK, 0);
  29772. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS1FBK, 0);
  29773. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS2FBK, 1);
  29774. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS3FBK, 2);
  29775. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS4FBK, 3);
  29776. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS5FBK, 4);
  29777. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS6FBK, 5);
  29778. + rt2x00_set_field32(&reg, HT_FBK_CFG0_HTMCS7FBK, 6);
  29779. + rt2800_register_write(rt2x00dev, HT_FBK_CFG0, reg);
  29780. +
  29781. + rt2800_register_read(rt2x00dev, HT_FBK_CFG1, &reg);
  29782. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS8FBK, 8);
  29783. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS9FBK, 8);
  29784. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS10FBK, 9);
  29785. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS11FBK, 10);
  29786. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS12FBK, 11);
  29787. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS13FBK, 12);
  29788. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS14FBK, 13);
  29789. + rt2x00_set_field32(&reg, HT_FBK_CFG1_HTMCS15FBK, 14);
  29790. + rt2800_register_write(rt2x00dev, HT_FBK_CFG1, reg);
  29791. +
  29792. + rt2800_register_read(rt2x00dev, LG_FBK_CFG0, &reg);
  29793. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS0FBK, 8);
  29794. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS1FBK, 8);
  29795. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS2FBK, 9);
  29796. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS3FBK, 10);
  29797. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS4FBK, 11);
  29798. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS5FBK, 12);
  29799. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS6FBK, 13);
  29800. + rt2x00_set_field32(&reg, LG_FBK_CFG0_OFDMMCS7FBK, 14);
  29801. + rt2800_register_write(rt2x00dev, LG_FBK_CFG0, reg);
  29802. +
  29803. + rt2800_register_read(rt2x00dev, LG_FBK_CFG1, &reg);
  29804. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS0FBK, 0);
  29805. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS1FBK, 0);
  29806. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS2FBK, 1);
  29807. + rt2x00_set_field32(&reg, LG_FBK_CFG0_CCKMCS3FBK, 2);
  29808. + rt2800_register_write(rt2x00dev, LG_FBK_CFG1, reg);
  29809. +
  29810. + /*
  29811. + * Do not force the BA window size, we use the TXWI to set it
  29812. + */
  29813. + rt2800_register_read(rt2x00dev, AMPDU_BA_WINSIZE, &reg);
  29814. + rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE_ENABLE, 0);
  29815. + rt2x00_set_field32(&reg, AMPDU_BA_WINSIZE_FORCE_WINSIZE, 0);
  29816. + rt2800_register_write(rt2x00dev, AMPDU_BA_WINSIZE, reg);
  29817. +
  29818. + /*
  29819. + * We must clear the error counters.
  29820. + * These registers are cleared on read,
  29821. + * so we may pass a useless variable to store the value.
  29822. + */
  29823. + rt2800_register_read(rt2x00dev, RX_STA_CNT0, &reg);
  29824. + rt2800_register_read(rt2x00dev, RX_STA_CNT1, &reg);
  29825. + rt2800_register_read(rt2x00dev, RX_STA_CNT2, &reg);
  29826. + rt2800_register_read(rt2x00dev, TX_STA_CNT0, &reg);
  29827. + rt2800_register_read(rt2x00dev, TX_STA_CNT1, &reg);
  29828. + rt2800_register_read(rt2x00dev, TX_STA_CNT2, &reg);
  29829. +
  29830. + /*
  29831. + * Setup leadtime for pre tbtt interrupt to 6ms
  29832. + */
  29833. + rt2800_register_read(rt2x00dev, INT_TIMER_CFG, &reg);
  29834. + rt2x00_set_field32(&reg, INT_TIMER_CFG_PRE_TBTT_TIMER, 6 << 4);
  29835. + rt2800_register_write(rt2x00dev, INT_TIMER_CFG, reg);
  29836. +
  29837. + /*
  29838. + * Set up channel statistics timer
  29839. + */
  29840. + rt2800_register_read(rt2x00dev, CH_TIME_CFG, &reg);
  29841. + rt2x00_set_field32(&reg, CH_TIME_CFG_EIFS_BUSY, 1);
  29842. + rt2x00_set_field32(&reg, CH_TIME_CFG_NAV_BUSY, 1);
  29843. + rt2x00_set_field32(&reg, CH_TIME_CFG_RX_BUSY, 1);
  29844. + rt2x00_set_field32(&reg, CH_TIME_CFG_TX_BUSY, 1);
  29845. + rt2x00_set_field32(&reg, CH_TIME_CFG_TMR_EN, 1);
  29846. + rt2800_register_write(rt2x00dev, CH_TIME_CFG, reg);
  29847. +
  29848. + return 0;
  29849. +}
  29850. +
  29851. +static int rt2800_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
  29852. +{
  29853. + unsigned int i;
  29854. + u32 reg;
  29855. +
  29856. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  29857. + rt2800_register_read(rt2x00dev, MAC_STATUS_CFG, &reg);
  29858. + if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
  29859. + return 0;
  29860. +
  29861. + udelay(REGISTER_BUSY_DELAY);
  29862. + }
  29863. +
  29864. + rt2x00_err(rt2x00dev, "BBP/RF register access failed, aborting\n");
  29865. + return -EACCES;
  29866. +}
  29867. +
  29868. +static int rt2800_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  29869. +{
  29870. + unsigned int i;
  29871. + u8 value;
  29872. +
  29873. + /*
  29874. + * BBP was enabled after firmware was loaded,
  29875. + * but we need to reactivate it now.
  29876. + */
  29877. + rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  29878. + rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  29879. + msleep(1);
  29880. +
  29881. + for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  29882. + rt2800_bbp_read(rt2x00dev, 0, &value);
  29883. + if ((value != 0xff) && (value != 0x00))
  29884. + return 0;
  29885. + udelay(REGISTER_BUSY_DELAY);
  29886. + }
  29887. +
  29888. + rt2x00_err(rt2x00dev, "BBP register access failed, aborting\n");
  29889. + return -EACCES;
  29890. +}
  29891. +
  29892. +static void rt2800_bbp4_mac_if_ctrl(struct rt2x00_dev *rt2x00dev)
  29893. +{
  29894. + u8 value;
  29895. +
  29896. + rt2800_bbp_read(rt2x00dev, 4, &value);
  29897. + rt2x00_set_field8(&value, BBP4_MAC_IF_CTRL, 1);
  29898. + rt2800_bbp_write(rt2x00dev, 4, value);
  29899. +}
  29900. +
  29901. +static void rt2800_init_freq_calibration(struct rt2x00_dev *rt2x00dev)
  29902. +{
  29903. + rt2800_bbp_write(rt2x00dev, 142, 1);
  29904. + rt2800_bbp_write(rt2x00dev, 143, 57);
  29905. +}
  29906. +
  29907. +static void rt2800_init_bbp_5592_glrt(struct rt2x00_dev *rt2x00dev)
  29908. +{
  29909. + const u8 glrt_table[] = {
  29910. + 0xE0, 0x1F, 0X38, 0x32, 0x08, 0x28, 0x19, 0x0A, 0xFF, 0x00, /* 128 ~ 137 */
  29911. + 0x16, 0x10, 0x10, 0x0B, 0x36, 0x2C, 0x26, 0x24, 0x42, 0x36, /* 138 ~ 147 */
  29912. + 0x30, 0x2D, 0x4C, 0x46, 0x3D, 0x40, 0x3E, 0x42, 0x3D, 0x40, /* 148 ~ 157 */
  29913. + 0X3C, 0x34, 0x2C, 0x2F, 0x3C, 0x35, 0x2E, 0x2A, 0x49, 0x41, /* 158 ~ 167 */
  29914. + 0x36, 0x31, 0x30, 0x30, 0x0E, 0x0D, 0x28, 0x21, 0x1C, 0x16, /* 168 ~ 177 */
  29915. + 0x50, 0x4A, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, /* 178 ~ 187 */
  29916. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 188 ~ 197 */
  29917. + 0x00, 0x00, 0x7D, 0x14, 0x32, 0x2C, 0x36, 0x4C, 0x43, 0x2C, /* 198 ~ 207 */
  29918. + 0x2E, 0x36, 0x30, 0x6E, /* 208 ~ 211 */
  29919. + };
  29920. + int i;
  29921. +
  29922. + for (i = 0; i < ARRAY_SIZE(glrt_table); i++) {
  29923. + rt2800_bbp_write(rt2x00dev, 195, 128 + i);
  29924. + rt2800_bbp_write(rt2x00dev, 196, glrt_table[i]);
  29925. + }
  29926. +};
  29927. +
  29928. +static void rt2800_init_bbp_early(struct rt2x00_dev *rt2x00dev)
  29929. +{
  29930. + rt2800_bbp_write(rt2x00dev, 65, 0x2C);
  29931. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  29932. + rt2800_bbp_write(rt2x00dev, 68, 0x0B);
  29933. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  29934. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  29935. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  29936. + rt2800_bbp_write(rt2x00dev, 81, 0x37);
  29937. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  29938. + rt2800_bbp_write(rt2x00dev, 83, 0x6A);
  29939. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  29940. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  29941. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  29942. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  29943. + rt2800_bbp_write(rt2x00dev, 103, 0x00);
  29944. + rt2800_bbp_write(rt2x00dev, 105, 0x05);
  29945. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  29946. +}
  29947. +
  29948. +static void rt2800_disable_unused_dac_adc(struct rt2x00_dev *rt2x00dev)
  29949. +{
  29950. + u16 eeprom;
  29951. + u8 value;
  29952. +
  29953. + rt2800_bbp_read(rt2x00dev, 138, &value);
  29954. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
  29955. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
  29956. + value |= 0x20;
  29957. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
  29958. + value &= ~0x02;
  29959. + rt2800_bbp_write(rt2x00dev, 138, value);
  29960. +}
  29961. +
  29962. +static void rt2800_init_bbp_305x_soc(struct rt2x00_dev *rt2x00dev)
  29963. +{
  29964. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  29965. +
  29966. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  29967. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  29968. +
  29969. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  29970. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  29971. +
  29972. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  29973. +
  29974. + rt2800_bbp_write(rt2x00dev, 78, 0x0e);
  29975. + rt2800_bbp_write(rt2x00dev, 80, 0x08);
  29976. +
  29977. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  29978. +
  29979. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  29980. +
  29981. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  29982. +
  29983. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  29984. +
  29985. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  29986. +
  29987. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  29988. +
  29989. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  29990. +
  29991. + rt2800_bbp_write(rt2x00dev, 105, 0x01);
  29992. +
  29993. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  29994. +}
  29995. +
  29996. +static void rt2800_init_bbp_28xx(struct rt2x00_dev *rt2x00dev)
  29997. +{
  29998. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  29999. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30000. +
  30001. + if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860C)) {
  30002. + rt2800_bbp_write(rt2x00dev, 69, 0x16);
  30003. + rt2800_bbp_write(rt2x00dev, 73, 0x12);
  30004. + } else {
  30005. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30006. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  30007. + }
  30008. +
  30009. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30010. +
  30011. + rt2800_bbp_write(rt2x00dev, 81, 0x37);
  30012. +
  30013. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30014. +
  30015. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  30016. +
  30017. + if (rt2x00_rt_rev(rt2x00dev, RT2860, REV_RT2860D))
  30018. + rt2800_bbp_write(rt2x00dev, 84, 0x19);
  30019. + else
  30020. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  30021. +
  30022. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  30023. +
  30024. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30025. +
  30026. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  30027. +
  30028. + rt2800_bbp_write(rt2x00dev, 103, 0x00);
  30029. +
  30030. + rt2800_bbp_write(rt2x00dev, 105, 0x05);
  30031. +
  30032. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  30033. +}
  30034. +
  30035. +static void rt2800_init_bbp_30xx(struct rt2x00_dev *rt2x00dev)
  30036. +{
  30037. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30038. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30039. +
  30040. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30041. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  30042. +
  30043. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30044. +
  30045. + rt2800_bbp_write(rt2x00dev, 79, 0x13);
  30046. + rt2800_bbp_write(rt2x00dev, 80, 0x05);
  30047. + rt2800_bbp_write(rt2x00dev, 81, 0x33);
  30048. +
  30049. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30050. +
  30051. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  30052. +
  30053. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  30054. +
  30055. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  30056. +
  30057. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30058. +
  30059. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  30060. +
  30061. + if (rt2x00_rt_rev_gte(rt2x00dev, RT3070, REV_RT3070F) ||
  30062. + rt2x00_rt_rev_gte(rt2x00dev, RT3071, REV_RT3071E) ||
  30063. + rt2x00_rt_rev_gte(rt2x00dev, RT3090, REV_RT3090E))
  30064. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30065. + else
  30066. + rt2800_bbp_write(rt2x00dev, 103, 0x00);
  30067. +
  30068. + rt2800_bbp_write(rt2x00dev, 105, 0x05);
  30069. +
  30070. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  30071. +
  30072. + if (rt2x00_rt(rt2x00dev, RT3071) ||
  30073. + rt2x00_rt(rt2x00dev, RT3090))
  30074. + rt2800_disable_unused_dac_adc(rt2x00dev);
  30075. +}
  30076. +
  30077. +static void rt2800_init_bbp_3290(struct rt2x00_dev *rt2x00dev)
  30078. +{
  30079. + u8 value;
  30080. +
  30081. + rt2800_bbp4_mac_if_ctrl(rt2x00dev);
  30082. +
  30083. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  30084. +
  30085. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30086. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30087. +
  30088. + rt2800_bbp_write(rt2x00dev, 68, 0x0b);
  30089. +
  30090. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30091. + rt2800_bbp_write(rt2x00dev, 73, 0x13);
  30092. + rt2800_bbp_write(rt2x00dev, 75, 0x46);
  30093. + rt2800_bbp_write(rt2x00dev, 76, 0x28);
  30094. +
  30095. + rt2800_bbp_write(rt2x00dev, 77, 0x58);
  30096. +
  30097. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30098. +
  30099. + rt2800_bbp_write(rt2x00dev, 74, 0x0b);
  30100. + rt2800_bbp_write(rt2x00dev, 79, 0x18);
  30101. + rt2800_bbp_write(rt2x00dev, 80, 0x09);
  30102. + rt2800_bbp_write(rt2x00dev, 81, 0x33);
  30103. +
  30104. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30105. +
  30106. + rt2800_bbp_write(rt2x00dev, 83, 0x7a);
  30107. +
  30108. + rt2800_bbp_write(rt2x00dev, 84, 0x9a);
  30109. +
  30110. + rt2800_bbp_write(rt2x00dev, 86, 0x38);
  30111. +
  30112. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30113. +
  30114. + rt2800_bbp_write(rt2x00dev, 92, 0x02);
  30115. +
  30116. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30117. +
  30118. + rt2800_bbp_write(rt2x00dev, 104, 0x92);
  30119. +
  30120. + rt2800_bbp_write(rt2x00dev, 105, 0x1c);
  30121. +
  30122. + rt2800_bbp_write(rt2x00dev, 106, 0x03);
  30123. +
  30124. + rt2800_bbp_write(rt2x00dev, 128, 0x12);
  30125. +
  30126. + rt2800_bbp_write(rt2x00dev, 67, 0x24);
  30127. + rt2800_bbp_write(rt2x00dev, 143, 0x04);
  30128. + rt2800_bbp_write(rt2x00dev, 142, 0x99);
  30129. + rt2800_bbp_write(rt2x00dev, 150, 0x30);
  30130. + rt2800_bbp_write(rt2x00dev, 151, 0x2e);
  30131. + rt2800_bbp_write(rt2x00dev, 152, 0x20);
  30132. + rt2800_bbp_write(rt2x00dev, 153, 0x34);
  30133. + rt2800_bbp_write(rt2x00dev, 154, 0x40);
  30134. + rt2800_bbp_write(rt2x00dev, 155, 0x3b);
  30135. + rt2800_bbp_write(rt2x00dev, 253, 0x04);
  30136. +
  30137. + rt2800_bbp_read(rt2x00dev, 47, &value);
  30138. + rt2x00_set_field8(&value, BBP47_TSSI_ADC6, 1);
  30139. + rt2800_bbp_write(rt2x00dev, 47, value);
  30140. +
  30141. + /* Use 5-bit ADC for Acquisition and 8-bit ADC for data */
  30142. + rt2800_bbp_read(rt2x00dev, 3, &value);
  30143. + rt2x00_set_field8(&value, BBP3_ADC_MODE_SWITCH, 1);
  30144. + rt2x00_set_field8(&value, BBP3_ADC_INIT_MODE, 1);
  30145. + rt2800_bbp_write(rt2x00dev, 3, value);
  30146. +}
  30147. +
  30148. +static void rt2800_init_bbp_3352(struct rt2x00_dev *rt2x00dev)
  30149. +{
  30150. + rt2800_bbp_write(rt2x00dev, 3, 0x00);
  30151. + rt2800_bbp_write(rt2x00dev, 4, 0x50);
  30152. +
  30153. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  30154. +
  30155. + rt2800_bbp_write(rt2x00dev, 47, 0x48);
  30156. +
  30157. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30158. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30159. +
  30160. + rt2800_bbp_write(rt2x00dev, 68, 0x0b);
  30161. +
  30162. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30163. + rt2800_bbp_write(rt2x00dev, 73, 0x13);
  30164. + rt2800_bbp_write(rt2x00dev, 75, 0x46);
  30165. + rt2800_bbp_write(rt2x00dev, 76, 0x28);
  30166. +
  30167. + rt2800_bbp_write(rt2x00dev, 77, 0x59);
  30168. +
  30169. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30170. +
  30171. + rt2800_bbp_write(rt2x00dev, 78, 0x0e);
  30172. + rt2800_bbp_write(rt2x00dev, 80, 0x08);
  30173. + rt2800_bbp_write(rt2x00dev, 81, 0x37);
  30174. +
  30175. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30176. +
  30177. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  30178. +
  30179. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  30180. +
  30181. + rt2800_bbp_write(rt2x00dev, 86, 0x38);
  30182. +
  30183. + rt2800_bbp_write(rt2x00dev, 88, 0x90);
  30184. +
  30185. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30186. +
  30187. + rt2800_bbp_write(rt2x00dev, 92, 0x02);
  30188. +
  30189. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30190. +
  30191. + rt2800_bbp_write(rt2x00dev, 104, 0x92);
  30192. +
  30193. + rt2800_bbp_write(rt2x00dev, 105, 0x34);
  30194. +
  30195. + rt2800_bbp_write(rt2x00dev, 106, 0x05);
  30196. +
  30197. + rt2800_bbp_write(rt2x00dev, 120, 0x50);
  30198. +
  30199. + rt2800_bbp_write(rt2x00dev, 137, 0x0f);
  30200. +
  30201. + rt2800_bbp_write(rt2x00dev, 163, 0xbd);
  30202. + /* Set ITxBF timeout to 0x9c40=1000msec */
  30203. + rt2800_bbp_write(rt2x00dev, 179, 0x02);
  30204. + rt2800_bbp_write(rt2x00dev, 180, 0x00);
  30205. + rt2800_bbp_write(rt2x00dev, 182, 0x40);
  30206. + rt2800_bbp_write(rt2x00dev, 180, 0x01);
  30207. + rt2800_bbp_write(rt2x00dev, 182, 0x9c);
  30208. + rt2800_bbp_write(rt2x00dev, 179, 0x00);
  30209. + /* Reprogram the inband interface to put right values in RXWI */
  30210. + rt2800_bbp_write(rt2x00dev, 142, 0x04);
  30211. + rt2800_bbp_write(rt2x00dev, 143, 0x3b);
  30212. + rt2800_bbp_write(rt2x00dev, 142, 0x06);
  30213. + rt2800_bbp_write(rt2x00dev, 143, 0xa0);
  30214. + rt2800_bbp_write(rt2x00dev, 142, 0x07);
  30215. + rt2800_bbp_write(rt2x00dev, 143, 0xa1);
  30216. + rt2800_bbp_write(rt2x00dev, 142, 0x08);
  30217. + rt2800_bbp_write(rt2x00dev, 143, 0xa2);
  30218. +
  30219. + rt2800_bbp_write(rt2x00dev, 148, 0xc8);
  30220. +}
  30221. +
  30222. +static void rt2800_init_bbp_3390(struct rt2x00_dev *rt2x00dev)
  30223. +{
  30224. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30225. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30226. +
  30227. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30228. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  30229. +
  30230. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30231. +
  30232. + rt2800_bbp_write(rt2x00dev, 79, 0x13);
  30233. + rt2800_bbp_write(rt2x00dev, 80, 0x05);
  30234. + rt2800_bbp_write(rt2x00dev, 81, 0x33);
  30235. +
  30236. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30237. +
  30238. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  30239. +
  30240. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  30241. +
  30242. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  30243. +
  30244. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30245. +
  30246. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  30247. +
  30248. + if (rt2x00_rt_rev_gte(rt2x00dev, RT3390, REV_RT3390E))
  30249. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30250. + else
  30251. + rt2800_bbp_write(rt2x00dev, 103, 0x00);
  30252. +
  30253. + rt2800_bbp_write(rt2x00dev, 105, 0x05);
  30254. +
  30255. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  30256. +
  30257. + rt2800_disable_unused_dac_adc(rt2x00dev);
  30258. +}
  30259. +
  30260. +static void rt2800_init_bbp_3572(struct rt2x00_dev *rt2x00dev)
  30261. +{
  30262. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  30263. +
  30264. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30265. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30266. +
  30267. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30268. + rt2800_bbp_write(rt2x00dev, 73, 0x10);
  30269. +
  30270. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30271. +
  30272. + rt2800_bbp_write(rt2x00dev, 79, 0x13);
  30273. + rt2800_bbp_write(rt2x00dev, 80, 0x05);
  30274. + rt2800_bbp_write(rt2x00dev, 81, 0x33);
  30275. +
  30276. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30277. +
  30278. + rt2800_bbp_write(rt2x00dev, 83, 0x6a);
  30279. +
  30280. + rt2800_bbp_write(rt2x00dev, 84, 0x99);
  30281. +
  30282. + rt2800_bbp_write(rt2x00dev, 86, 0x00);
  30283. +
  30284. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30285. +
  30286. + rt2800_bbp_write(rt2x00dev, 92, 0x00);
  30287. +
  30288. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30289. +
  30290. + rt2800_bbp_write(rt2x00dev, 105, 0x05);
  30291. +
  30292. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  30293. +
  30294. + rt2800_disable_unused_dac_adc(rt2x00dev);
  30295. +}
  30296. +
  30297. +static void rt2800_init_bbp_53xx(struct rt2x00_dev *rt2x00dev)
  30298. +{
  30299. + int ant, div_mode;
  30300. + u16 eeprom;
  30301. + u8 value;
  30302. +
  30303. + rt2800_bbp4_mac_if_ctrl(rt2x00dev);
  30304. +
  30305. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  30306. +
  30307. + rt2800_bbp_write(rt2x00dev, 65, 0x2c);
  30308. + rt2800_bbp_write(rt2x00dev, 66, 0x38);
  30309. +
  30310. + rt2800_bbp_write(rt2x00dev, 68, 0x0b);
  30311. +
  30312. + rt2800_bbp_write(rt2x00dev, 69, 0x12);
  30313. + rt2800_bbp_write(rt2x00dev, 73, 0x13);
  30314. + rt2800_bbp_write(rt2x00dev, 75, 0x46);
  30315. + rt2800_bbp_write(rt2x00dev, 76, 0x28);
  30316. +
  30317. + rt2800_bbp_write(rt2x00dev, 77, 0x59);
  30318. +
  30319. + rt2800_bbp_write(rt2x00dev, 70, 0x0a);
  30320. +
  30321. + rt2800_bbp_write(rt2x00dev, 79, 0x13);
  30322. + rt2800_bbp_write(rt2x00dev, 80, 0x05);
  30323. + rt2800_bbp_write(rt2x00dev, 81, 0x33);
  30324. +
  30325. + rt2800_bbp_write(rt2x00dev, 82, 0x62);
  30326. +
  30327. + rt2800_bbp_write(rt2x00dev, 83, 0x7a);
  30328. +
  30329. + rt2800_bbp_write(rt2x00dev, 84, 0x9a);
  30330. +
  30331. + rt2800_bbp_write(rt2x00dev, 86, 0x38);
  30332. +
  30333. + if (rt2x00_rt(rt2x00dev, RT5392))
  30334. + rt2800_bbp_write(rt2x00dev, 88, 0x90);
  30335. +
  30336. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30337. +
  30338. + rt2800_bbp_write(rt2x00dev, 92, 0x02);
  30339. +
  30340. + if (rt2x00_rt(rt2x00dev, RT5392)) {
  30341. + rt2800_bbp_write(rt2x00dev, 95, 0x9a);
  30342. + rt2800_bbp_write(rt2x00dev, 98, 0x12);
  30343. + }
  30344. +
  30345. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30346. +
  30347. + rt2800_bbp_write(rt2x00dev, 104, 0x92);
  30348. +
  30349. + rt2800_bbp_write(rt2x00dev, 105, 0x3c);
  30350. +
  30351. + if (rt2x00_rt(rt2x00dev, RT5390))
  30352. + rt2800_bbp_write(rt2x00dev, 106, 0x03);
  30353. + else if (rt2x00_rt(rt2x00dev, RT5392))
  30354. + rt2800_bbp_write(rt2x00dev, 106, 0x12);
  30355. + else
  30356. + WARN_ON(1);
  30357. +
  30358. + rt2800_bbp_write(rt2x00dev, 128, 0x12);
  30359. +
  30360. + if (rt2x00_rt(rt2x00dev, RT5392)) {
  30361. + rt2800_bbp_write(rt2x00dev, 134, 0xd0);
  30362. + rt2800_bbp_write(rt2x00dev, 135, 0xf6);
  30363. + }
  30364. +
  30365. + rt2800_disable_unused_dac_adc(rt2x00dev);
  30366. +
  30367. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  30368. + div_mode = rt2x00_get_field16(eeprom,
  30369. + EEPROM_NIC_CONF1_ANT_DIVERSITY);
  30370. + ant = (div_mode == 3) ? 1 : 0;
  30371. +
  30372. + /* check if this is a Bluetooth combo card */
  30373. + if (test_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags)) {
  30374. + u32 reg;
  30375. +
  30376. + rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
  30377. + rt2x00_set_field32(&reg, GPIO_CTRL_DIR3, 0);
  30378. + rt2x00_set_field32(&reg, GPIO_CTRL_DIR6, 0);
  30379. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 0);
  30380. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 0);
  30381. + if (ant == 0)
  30382. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL3, 1);
  30383. + else if (ant == 1)
  30384. + rt2x00_set_field32(&reg, GPIO_CTRL_VAL6, 1);
  30385. + rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
  30386. + }
  30387. +
  30388. + /* This chip has hardware antenna diversity*/
  30389. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
  30390. + rt2800_bbp_write(rt2x00dev, 150, 0); /* Disable Antenna Software OFDM */
  30391. + rt2800_bbp_write(rt2x00dev, 151, 0); /* Disable Antenna Software CCK */
  30392. + rt2800_bbp_write(rt2x00dev, 154, 0); /* Clear previously selected antenna */
  30393. + }
  30394. +
  30395. + rt2800_bbp_read(rt2x00dev, 152, &value);
  30396. + if (ant == 0)
  30397. + rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
  30398. + else
  30399. + rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
  30400. + rt2800_bbp_write(rt2x00dev, 152, value);
  30401. +
  30402. + rt2800_init_freq_calibration(rt2x00dev);
  30403. +}
  30404. +
  30405. +static void rt2800_init_bbp_5592(struct rt2x00_dev *rt2x00dev)
  30406. +{
  30407. + int ant, div_mode;
  30408. + u16 eeprom;
  30409. + u8 value;
  30410. +
  30411. + rt2800_init_bbp_early(rt2x00dev);
  30412. +
  30413. + rt2800_bbp_read(rt2x00dev, 105, &value);
  30414. + rt2x00_set_field8(&value, BBP105_MLD,
  30415. + rt2x00dev->default_ant.rx_chain_num == 2);
  30416. + rt2800_bbp_write(rt2x00dev, 105, value);
  30417. +
  30418. + rt2800_bbp4_mac_if_ctrl(rt2x00dev);
  30419. +
  30420. + rt2800_bbp_write(rt2x00dev, 20, 0x06);
  30421. + rt2800_bbp_write(rt2x00dev, 31, 0x08);
  30422. + rt2800_bbp_write(rt2x00dev, 65, 0x2C);
  30423. + rt2800_bbp_write(rt2x00dev, 68, 0xDD);
  30424. + rt2800_bbp_write(rt2x00dev, 69, 0x1A);
  30425. + rt2800_bbp_write(rt2x00dev, 70, 0x05);
  30426. + rt2800_bbp_write(rt2x00dev, 73, 0x13);
  30427. + rt2800_bbp_write(rt2x00dev, 74, 0x0F);
  30428. + rt2800_bbp_write(rt2x00dev, 75, 0x4F);
  30429. + rt2800_bbp_write(rt2x00dev, 76, 0x28);
  30430. + rt2800_bbp_write(rt2x00dev, 77, 0x59);
  30431. + rt2800_bbp_write(rt2x00dev, 84, 0x9A);
  30432. + rt2800_bbp_write(rt2x00dev, 86, 0x38);
  30433. + rt2800_bbp_write(rt2x00dev, 88, 0x90);
  30434. + rt2800_bbp_write(rt2x00dev, 91, 0x04);
  30435. + rt2800_bbp_write(rt2x00dev, 92, 0x02);
  30436. + rt2800_bbp_write(rt2x00dev, 95, 0x9a);
  30437. + rt2800_bbp_write(rt2x00dev, 98, 0x12);
  30438. + rt2800_bbp_write(rt2x00dev, 103, 0xC0);
  30439. + rt2800_bbp_write(rt2x00dev, 104, 0x92);
  30440. + /* FIXME BBP105 owerwrite */
  30441. + rt2800_bbp_write(rt2x00dev, 105, 0x3C);
  30442. + rt2800_bbp_write(rt2x00dev, 106, 0x35);
  30443. + rt2800_bbp_write(rt2x00dev, 128, 0x12);
  30444. + rt2800_bbp_write(rt2x00dev, 134, 0xD0);
  30445. + rt2800_bbp_write(rt2x00dev, 135, 0xF6);
  30446. + rt2800_bbp_write(rt2x00dev, 137, 0x0F);
  30447. +
  30448. + /* Initialize GLRT (Generalized Likehood Radio Test) */
  30449. + rt2800_init_bbp_5592_glrt(rt2x00dev);
  30450. +
  30451. + rt2800_bbp4_mac_if_ctrl(rt2x00dev);
  30452. +
  30453. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  30454. + div_mode = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_ANT_DIVERSITY);
  30455. + ant = (div_mode == 3) ? 1 : 0;
  30456. + rt2800_bbp_read(rt2x00dev, 152, &value);
  30457. + if (ant == 0) {
  30458. + /* Main antenna */
  30459. + rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 1);
  30460. + } else {
  30461. + /* Auxiliary antenna */
  30462. + rt2x00_set_field8(&value, BBP152_RX_DEFAULT_ANT, 0);
  30463. + }
  30464. + rt2800_bbp_write(rt2x00dev, 152, value);
  30465. +
  30466. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C)) {
  30467. + rt2800_bbp_read(rt2x00dev, 254, &value);
  30468. + rt2x00_set_field8(&value, BBP254_BIT7, 1);
  30469. + rt2800_bbp_write(rt2x00dev, 254, value);
  30470. + }
  30471. +
  30472. + rt2800_init_freq_calibration(rt2x00dev);
  30473. +
  30474. + rt2800_bbp_write(rt2x00dev, 84, 0x19);
  30475. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
  30476. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  30477. +}
  30478. +
  30479. +static void rt2800_init_bbp(struct rt2x00_dev *rt2x00dev)
  30480. +{
  30481. + unsigned int i;
  30482. + u16 eeprom;
  30483. + u8 reg_id;
  30484. + u8 value;
  30485. +
  30486. + if (rt2800_is_305x_soc(rt2x00dev))
  30487. + rt2800_init_bbp_305x_soc(rt2x00dev);
  30488. +
  30489. + switch (rt2x00dev->chip.rt) {
  30490. + case RT2860:
  30491. + case RT2872:
  30492. + case RT2883:
  30493. + rt2800_init_bbp_28xx(rt2x00dev);
  30494. + break;
  30495. + case RT3070:
  30496. + case RT3071:
  30497. + case RT3090:
  30498. + rt2800_init_bbp_30xx(rt2x00dev);
  30499. + break;
  30500. + case RT3290:
  30501. + rt2800_init_bbp_3290(rt2x00dev);
  30502. + break;
  30503. + case RT3352:
  30504. + rt2800_init_bbp_3352(rt2x00dev);
  30505. + break;
  30506. + case RT3390:
  30507. + rt2800_init_bbp_3390(rt2x00dev);
  30508. + break;
  30509. + case RT3572:
  30510. + rt2800_init_bbp_3572(rt2x00dev);
  30511. + break;
  30512. + case RT5390:
  30513. + case RT5392:
  30514. + rt2800_init_bbp_53xx(rt2x00dev);
  30515. + break;
  30516. + case RT5592:
  30517. + rt2800_init_bbp_5592(rt2x00dev);
  30518. + return;
  30519. + }
  30520. +
  30521. + for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  30522. + rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  30523. +
  30524. + if (eeprom != 0xffff && eeprom != 0x0000) {
  30525. + reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  30526. + value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  30527. + rt2800_bbp_write(rt2x00dev, reg_id, value);
  30528. + }
  30529. + }
  30530. +}
  30531. +
  30532. +static void rt2800_led_open_drain_enable(struct rt2x00_dev *rt2x00dev)
  30533. +{
  30534. + u32 reg;
  30535. +
  30536. + rt2800_register_read(rt2x00dev, OPT_14_CSR, &reg);
  30537. + rt2x00_set_field32(&reg, OPT_14_CSR_BIT0, 1);
  30538. + rt2800_register_write(rt2x00dev, OPT_14_CSR, reg);
  30539. +}
  30540. +
  30541. +static u8 rt2800_init_rx_filter(struct rt2x00_dev *rt2x00dev, bool bw40,
  30542. + u8 filter_target)
  30543. +{
  30544. + unsigned int i;
  30545. + u8 bbp;
  30546. + u8 rfcsr;
  30547. + u8 passband;
  30548. + u8 stopband;
  30549. + u8 overtuned = 0;
  30550. + u8 rfcsr24 = (bw40) ? 0x27 : 0x07;
  30551. +
  30552. + rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  30553. +
  30554. + rt2800_bbp_read(rt2x00dev, 4, &bbp);
  30555. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
  30556. + rt2800_bbp_write(rt2x00dev, 4, bbp);
  30557. +
  30558. + rt2800_rfcsr_read(rt2x00dev, 31, &rfcsr);
  30559. + rt2x00_set_field8(&rfcsr, RFCSR31_RX_H20M, bw40);
  30560. + rt2800_rfcsr_write(rt2x00dev, 31, rfcsr);
  30561. +
  30562. + rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  30563. + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
  30564. + rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  30565. +
  30566. + /*
  30567. + * Set power & frequency of passband test tone
  30568. + */
  30569. + rt2800_bbp_write(rt2x00dev, 24, 0);
  30570. +
  30571. + for (i = 0; i < 100; i++) {
  30572. + rt2800_bbp_write(rt2x00dev, 25, 0x90);
  30573. + msleep(1);
  30574. +
  30575. + rt2800_bbp_read(rt2x00dev, 55, &passband);
  30576. + if (passband)
  30577. + break;
  30578. + }
  30579. +
  30580. + /*
  30581. + * Set power & frequency of stopband test tone
  30582. + */
  30583. + rt2800_bbp_write(rt2x00dev, 24, 0x06);
  30584. +
  30585. + for (i = 0; i < 100; i++) {
  30586. + rt2800_bbp_write(rt2x00dev, 25, 0x90);
  30587. + msleep(1);
  30588. +
  30589. + rt2800_bbp_read(rt2x00dev, 55, &stopband);
  30590. +
  30591. + if ((passband - stopband) <= filter_target) {
  30592. + rfcsr24++;
  30593. + overtuned += ((passband - stopband) == filter_target);
  30594. + } else
  30595. + break;
  30596. +
  30597. + rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  30598. + }
  30599. +
  30600. + rfcsr24 -= !!overtuned;
  30601. +
  30602. + rt2800_rfcsr_write(rt2x00dev, 24, rfcsr24);
  30603. + return rfcsr24;
  30604. +}
  30605. +
  30606. +static void rt2800_rf_init_calibration(struct rt2x00_dev *rt2x00dev,
  30607. + const unsigned int rf_reg)
  30608. +{
  30609. + u8 rfcsr;
  30610. +
  30611. + rt2800_rfcsr_read(rt2x00dev, rf_reg, &rfcsr);
  30612. + rt2x00_set_field8(&rfcsr, FIELD8(0x80), 1);
  30613. + rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
  30614. + msleep(1);
  30615. + rt2x00_set_field8(&rfcsr, FIELD8(0x80), 0);
  30616. + rt2800_rfcsr_write(rt2x00dev, rf_reg, rfcsr);
  30617. +}
  30618. +
  30619. +static void rt2800_rx_filter_calibration(struct rt2x00_dev *rt2x00dev)
  30620. +{
  30621. + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
  30622. + u8 filter_tgt_bw20;
  30623. + u8 filter_tgt_bw40;
  30624. + u8 rfcsr, bbp;
  30625. +
  30626. + /*
  30627. + * TODO: sync filter_tgt values with vendor driver
  30628. + */
  30629. + if (rt2x00_rt(rt2x00dev, RT3070)) {
  30630. + filter_tgt_bw20 = 0x16;
  30631. + filter_tgt_bw40 = 0x19;
  30632. + } else {
  30633. + filter_tgt_bw20 = 0x13;
  30634. + filter_tgt_bw40 = 0x15;
  30635. + }
  30636. +
  30637. + drv_data->calibration_bw20 =
  30638. + rt2800_init_rx_filter(rt2x00dev, false, filter_tgt_bw20);
  30639. + drv_data->calibration_bw40 =
  30640. + rt2800_init_rx_filter(rt2x00dev, true, filter_tgt_bw40);
  30641. +
  30642. + /*
  30643. + * Save BBP 25 & 26 values for later use in channel switching (for 3052)
  30644. + */
  30645. + rt2800_bbp_read(rt2x00dev, 25, &drv_data->bbp25);
  30646. + rt2800_bbp_read(rt2x00dev, 26, &drv_data->bbp26);
  30647. +
  30648. + /*
  30649. + * Set back to initial state
  30650. + */
  30651. + rt2800_bbp_write(rt2x00dev, 24, 0);
  30652. +
  30653. + rt2800_rfcsr_read(rt2x00dev, 22, &rfcsr);
  30654. + rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
  30655. + rt2800_rfcsr_write(rt2x00dev, 22, rfcsr);
  30656. +
  30657. + /*
  30658. + * Set BBP back to BW20
  30659. + */
  30660. + rt2800_bbp_read(rt2x00dev, 4, &bbp);
  30661. + rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
  30662. + rt2800_bbp_write(rt2x00dev, 4, bbp);
  30663. +}
  30664. +
  30665. +static void rt2800_normal_mode_setup_3xxx(struct rt2x00_dev *rt2x00dev)
  30666. +{
  30667. + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
  30668. + u8 min_gain, rfcsr, bbp;
  30669. + u16 eeprom;
  30670. +
  30671. + rt2800_rfcsr_read(rt2x00dev, 17, &rfcsr);
  30672. +
  30673. + rt2x00_set_field8(&rfcsr, RFCSR17_TX_LO1_EN, 0);
  30674. + if (rt2x00_rt(rt2x00dev, RT3070) ||
  30675. + rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
  30676. + rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E) ||
  30677. + rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E)) {
  30678. + if (!test_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags))
  30679. + rt2x00_set_field8(&rfcsr, RFCSR17_R, 1);
  30680. + }
  30681. +
  30682. + min_gain = rt2x00_rt(rt2x00dev, RT3070) ? 1 : 2;
  30683. + if (drv_data->txmixer_gain_24g >= min_gain) {
  30684. + rt2x00_set_field8(&rfcsr, RFCSR17_TXMIXER_GAIN,
  30685. + drv_data->txmixer_gain_24g);
  30686. + }
  30687. +
  30688. + rt2800_rfcsr_write(rt2x00dev, 17, rfcsr);
  30689. +
  30690. + if (rt2x00_rt(rt2x00dev, RT3090)) {
  30691. + /* Turn off unused DAC1 and ADC1 to reduce power consumption */
  30692. + rt2800_bbp_read(rt2x00dev, 138, &bbp);
  30693. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
  30694. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
  30695. + rt2x00_set_field8(&bbp, BBP138_RX_ADC1, 0);
  30696. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
  30697. + rt2x00_set_field8(&bbp, BBP138_TX_DAC1, 1);
  30698. + rt2800_bbp_write(rt2x00dev, 138, bbp);
  30699. + }
  30700. +
  30701. + if (rt2x00_rt(rt2x00dev, RT3070)) {
  30702. + rt2800_rfcsr_read(rt2x00dev, 27, &rfcsr);
  30703. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F))
  30704. + rt2x00_set_field8(&rfcsr, RFCSR27_R1, 3);
  30705. + else
  30706. + rt2x00_set_field8(&rfcsr, RFCSR27_R1, 0);
  30707. + rt2x00_set_field8(&rfcsr, RFCSR27_R2, 0);
  30708. + rt2x00_set_field8(&rfcsr, RFCSR27_R3, 0);
  30709. + rt2x00_set_field8(&rfcsr, RFCSR27_R4, 0);
  30710. + rt2800_rfcsr_write(rt2x00dev, 27, rfcsr);
  30711. + } else if (rt2x00_rt(rt2x00dev, RT3071) ||
  30712. + rt2x00_rt(rt2x00dev, RT3090) ||
  30713. + rt2x00_rt(rt2x00dev, RT3390)) {
  30714. + rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
  30715. + rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
  30716. + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
  30717. + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
  30718. + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
  30719. + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
  30720. + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
  30721. +
  30722. + rt2800_rfcsr_read(rt2x00dev, 15, &rfcsr);
  30723. + rt2x00_set_field8(&rfcsr, RFCSR15_TX_LO2_EN, 0);
  30724. + rt2800_rfcsr_write(rt2x00dev, 15, rfcsr);
  30725. +
  30726. + rt2800_rfcsr_read(rt2x00dev, 20, &rfcsr);
  30727. + rt2x00_set_field8(&rfcsr, RFCSR20_RX_LO1_EN, 0);
  30728. + rt2800_rfcsr_write(rt2x00dev, 20, rfcsr);
  30729. +
  30730. + rt2800_rfcsr_read(rt2x00dev, 21, &rfcsr);
  30731. + rt2x00_set_field8(&rfcsr, RFCSR21_RX_LO2_EN, 0);
  30732. + rt2800_rfcsr_write(rt2x00dev, 21, rfcsr);
  30733. + }
  30734. +}
  30735. +
  30736. +static void rt2800_normal_mode_setup_5xxx(struct rt2x00_dev *rt2x00dev)
  30737. +{
  30738. + u8 reg;
  30739. + u16 eeprom;
  30740. +
  30741. + /* Turn off unused DAC1 and ADC1 to reduce power consumption */
  30742. + rt2800_bbp_read(rt2x00dev, 138, &reg);
  30743. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
  30744. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) == 1)
  30745. + rt2x00_set_field8(&reg, BBP138_RX_ADC1, 0);
  30746. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) == 1)
  30747. + rt2x00_set_field8(&reg, BBP138_TX_DAC1, 1);
  30748. + rt2800_bbp_write(rt2x00dev, 138, reg);
  30749. +
  30750. + rt2800_rfcsr_read(rt2x00dev, 38, &reg);
  30751. + rt2x00_set_field8(&reg, RFCSR38_RX_LO1_EN, 0);
  30752. + rt2800_rfcsr_write(rt2x00dev, 38, reg);
  30753. +
  30754. + rt2800_rfcsr_read(rt2x00dev, 39, &reg);
  30755. + rt2x00_set_field8(&reg, RFCSR39_RX_LO2_EN, 0);
  30756. + rt2800_rfcsr_write(rt2x00dev, 39, reg);
  30757. +
  30758. + rt2800_bbp4_mac_if_ctrl(rt2x00dev);
  30759. +
  30760. + rt2800_rfcsr_read(rt2x00dev, 30, &reg);
  30761. + rt2x00_set_field8(&reg, RFCSR30_RX_VCM, 2);
  30762. + rt2800_rfcsr_write(rt2x00dev, 30, reg);
  30763. +}
  30764. +
  30765. +static void rt2800_init_rfcsr_305x_soc(struct rt2x00_dev *rt2x00dev)
  30766. +{
  30767. + rt2800_rf_init_calibration(rt2x00dev, 30);
  30768. +
  30769. + rt2800_rfcsr_write(rt2x00dev, 0, 0x50);
  30770. + rt2800_rfcsr_write(rt2x00dev, 1, 0x01);
  30771. + rt2800_rfcsr_write(rt2x00dev, 2, 0xf7);
  30772. + rt2800_rfcsr_write(rt2x00dev, 3, 0x75);
  30773. + rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  30774. + rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
  30775. + rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
  30776. + rt2800_rfcsr_write(rt2x00dev, 7, 0x50);
  30777. + rt2800_rfcsr_write(rt2x00dev, 8, 0x39);
  30778. + rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
  30779. + rt2800_rfcsr_write(rt2x00dev, 10, 0x60);
  30780. + rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  30781. + rt2800_rfcsr_write(rt2x00dev, 12, 0x75);
  30782. + rt2800_rfcsr_write(rt2x00dev, 13, 0x75);
  30783. + rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  30784. + rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
  30785. + rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
  30786. + rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
  30787. + rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
  30788. + rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  30789. + rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
  30790. + rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
  30791. + rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
  30792. + rt2800_rfcsr_write(rt2x00dev, 23, 0x31);
  30793. + rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
  30794. + rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  30795. + rt2800_rfcsr_write(rt2x00dev, 26, 0x25);
  30796. + rt2800_rfcsr_write(rt2x00dev, 27, 0x23);
  30797. + rt2800_rfcsr_write(rt2x00dev, 28, 0x13);
  30798. + rt2800_rfcsr_write(rt2x00dev, 29, 0x83);
  30799. + rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
  30800. + rt2800_rfcsr_write(rt2x00dev, 31, 0x00);
  30801. +}
  30802. +
  30803. +static void rt2800_init_rfcsr_30xx(struct rt2x00_dev *rt2x00dev)
  30804. +{
  30805. + u8 rfcsr;
  30806. + u16 eeprom;
  30807. + u32 reg;
  30808. +
  30809. + /* XXX vendor driver do this only for 3070 */
  30810. + rt2800_rf_init_calibration(rt2x00dev, 30);
  30811. +
  30812. + rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  30813. + rt2800_rfcsr_write(rt2x00dev, 5, 0x03);
  30814. + rt2800_rfcsr_write(rt2x00dev, 6, 0x02);
  30815. + rt2800_rfcsr_write(rt2x00dev, 7, 0x60);
  30816. + rt2800_rfcsr_write(rt2x00dev, 9, 0x0f);
  30817. + rt2800_rfcsr_write(rt2x00dev, 10, 0x41);
  30818. + rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  30819. + rt2800_rfcsr_write(rt2x00dev, 12, 0x7b);
  30820. + rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  30821. + rt2800_rfcsr_write(rt2x00dev, 15, 0x58);
  30822. + rt2800_rfcsr_write(rt2x00dev, 16, 0xb3);
  30823. + rt2800_rfcsr_write(rt2x00dev, 17, 0x92);
  30824. + rt2800_rfcsr_write(rt2x00dev, 18, 0x2c);
  30825. + rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  30826. + rt2800_rfcsr_write(rt2x00dev, 20, 0xba);
  30827. + rt2800_rfcsr_write(rt2x00dev, 21, 0xdb);
  30828. + rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
  30829. + rt2800_rfcsr_write(rt2x00dev, 25, 0x01);
  30830. + rt2800_rfcsr_write(rt2x00dev, 29, 0x1f);
  30831. +
  30832. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F)) {
  30833. + rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
  30834. + rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
  30835. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
  30836. + rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
  30837. + } else if (rt2x00_rt(rt2x00dev, RT3071) ||
  30838. + rt2x00_rt(rt2x00dev, RT3090)) {
  30839. + rt2800_rfcsr_write(rt2x00dev, 31, 0x14);
  30840. +
  30841. + rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
  30842. + rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
  30843. + rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
  30844. +
  30845. + rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
  30846. + rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
  30847. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
  30848. + rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E)) {
  30849. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  30850. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_DAC_TEST))
  30851. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
  30852. + else
  30853. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
  30854. + }
  30855. + rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
  30856. +
  30857. + rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
  30858. + rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
  30859. + rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
  30860. + }
  30861. +
  30862. + rt2800_rx_filter_calibration(rt2x00dev);
  30863. +
  30864. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3070, REV_RT3070F) ||
  30865. + rt2x00_rt_rev_lt(rt2x00dev, RT3071, REV_RT3071E) ||
  30866. + rt2x00_rt_rev_lt(rt2x00dev, RT3090, REV_RT3090E))
  30867. + rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  30868. +
  30869. + rt2800_led_open_drain_enable(rt2x00dev);
  30870. + rt2800_normal_mode_setup_3xxx(rt2x00dev);
  30871. +}
  30872. +
  30873. +static void rt2800_init_rfcsr_3290(struct rt2x00_dev *rt2x00dev)
  30874. +{
  30875. + u8 rfcsr;
  30876. +
  30877. + rt2800_rf_init_calibration(rt2x00dev, 2);
  30878. +
  30879. + rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
  30880. + rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
  30881. + rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
  30882. + rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
  30883. + rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
  30884. + rt2800_rfcsr_write(rt2x00dev, 8, 0xf3);
  30885. + rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
  30886. + rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
  30887. + rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
  30888. + rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
  30889. + rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
  30890. + rt2800_rfcsr_write(rt2x00dev, 18, 0x02);
  30891. + rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
  30892. + rt2800_rfcsr_write(rt2x00dev, 25, 0x83);
  30893. + rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
  30894. + rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
  30895. + rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
  30896. + rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
  30897. + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
  30898. + rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
  30899. + rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
  30900. + rt2800_rfcsr_write(rt2x00dev, 34, 0x05);
  30901. + rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
  30902. + rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
  30903. + rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
  30904. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
  30905. + rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
  30906. + rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
  30907. + rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
  30908. + rt2800_rfcsr_write(rt2x00dev, 43, 0x7b);
  30909. + rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
  30910. + rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
  30911. + rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
  30912. + rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
  30913. + rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
  30914. + rt2800_rfcsr_write(rt2x00dev, 49, 0x98);
  30915. + rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
  30916. + rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
  30917. + rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
  30918. + rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
  30919. + rt2800_rfcsr_write(rt2x00dev, 56, 0x02);
  30920. + rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
  30921. + rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
  30922. + rt2800_rfcsr_write(rt2x00dev, 59, 0x09);
  30923. + rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
  30924. + rt2800_rfcsr_write(rt2x00dev, 61, 0xc1);
  30925. +
  30926. + rt2800_rfcsr_read(rt2x00dev, 29, &rfcsr);
  30927. + rt2x00_set_field8(&rfcsr, RFCSR29_RSSI_GAIN, 3);
  30928. + rt2800_rfcsr_write(rt2x00dev, 29, rfcsr);
  30929. +
  30930. + rt2800_led_open_drain_enable(rt2x00dev);
  30931. + rt2800_normal_mode_setup_3xxx(rt2x00dev);
  30932. +}
  30933. +
  30934. +static void rt2800_init_rfcsr_3352(struct rt2x00_dev *rt2x00dev)
  30935. +{
  30936. + rt2800_rf_init_calibration(rt2x00dev, 30);
  30937. +
  30938. + rt2800_rfcsr_write(rt2x00dev, 0, 0xf0);
  30939. + rt2800_rfcsr_write(rt2x00dev, 1, 0x23);
  30940. + rt2800_rfcsr_write(rt2x00dev, 2, 0x50);
  30941. + rt2800_rfcsr_write(rt2x00dev, 3, 0x18);
  30942. + rt2800_rfcsr_write(rt2x00dev, 4, 0x00);
  30943. + rt2800_rfcsr_write(rt2x00dev, 5, 0x00);
  30944. + rt2800_rfcsr_write(rt2x00dev, 6, 0x33);
  30945. + rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
  30946. + rt2800_rfcsr_write(rt2x00dev, 8, 0xf1);
  30947. + rt2800_rfcsr_write(rt2x00dev, 9, 0x02);
  30948. + rt2800_rfcsr_write(rt2x00dev, 10, 0xd2);
  30949. + rt2800_rfcsr_write(rt2x00dev, 11, 0x42);
  30950. + rt2800_rfcsr_write(rt2x00dev, 12, 0x1c);
  30951. + rt2800_rfcsr_write(rt2x00dev, 13, 0x00);
  30952. + rt2800_rfcsr_write(rt2x00dev, 14, 0x5a);
  30953. + rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
  30954. + rt2800_rfcsr_write(rt2x00dev, 16, 0x01);
  30955. + rt2800_rfcsr_write(rt2x00dev, 18, 0x45);
  30956. + rt2800_rfcsr_write(rt2x00dev, 19, 0x02);
  30957. + rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
  30958. + rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
  30959. + rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
  30960. + rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
  30961. + rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
  30962. + rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
  30963. + rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
  30964. + rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  30965. + rt2800_rfcsr_write(rt2x00dev, 28, 0x03);
  30966. + rt2800_rfcsr_write(rt2x00dev, 29, 0x00);
  30967. + rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
  30968. + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
  30969. + rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
  30970. + rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
  30971. + rt2800_rfcsr_write(rt2x00dev, 34, 0x01);
  30972. + rt2800_rfcsr_write(rt2x00dev, 35, 0x03);
  30973. + rt2800_rfcsr_write(rt2x00dev, 36, 0xbd);
  30974. + rt2800_rfcsr_write(rt2x00dev, 37, 0x3c);
  30975. + rt2800_rfcsr_write(rt2x00dev, 38, 0x5f);
  30976. + rt2800_rfcsr_write(rt2x00dev, 39, 0xc5);
  30977. + rt2800_rfcsr_write(rt2x00dev, 40, 0x33);
  30978. + rt2800_rfcsr_write(rt2x00dev, 41, 0x5b);
  30979. + rt2800_rfcsr_write(rt2x00dev, 42, 0x5b);
  30980. + rt2800_rfcsr_write(rt2x00dev, 43, 0xdb);
  30981. + rt2800_rfcsr_write(rt2x00dev, 44, 0xdb);
  30982. + rt2800_rfcsr_write(rt2x00dev, 45, 0xdb);
  30983. + rt2800_rfcsr_write(rt2x00dev, 46, 0xdd);
  30984. + rt2800_rfcsr_write(rt2x00dev, 47, 0x0d);
  30985. + rt2800_rfcsr_write(rt2x00dev, 48, 0x14);
  30986. + rt2800_rfcsr_write(rt2x00dev, 49, 0x00);
  30987. + rt2800_rfcsr_write(rt2x00dev, 50, 0x2d);
  30988. + rt2800_rfcsr_write(rt2x00dev, 51, 0x7f);
  30989. + rt2800_rfcsr_write(rt2x00dev, 52, 0x00);
  30990. + rt2800_rfcsr_write(rt2x00dev, 53, 0x52);
  30991. + rt2800_rfcsr_write(rt2x00dev, 54, 0x1b);
  30992. + rt2800_rfcsr_write(rt2x00dev, 55, 0x7f);
  30993. + rt2800_rfcsr_write(rt2x00dev, 56, 0x00);
  30994. + rt2800_rfcsr_write(rt2x00dev, 57, 0x52);
  30995. + rt2800_rfcsr_write(rt2x00dev, 58, 0x1b);
  30996. + rt2800_rfcsr_write(rt2x00dev, 59, 0x00);
  30997. + rt2800_rfcsr_write(rt2x00dev, 60, 0x00);
  30998. + rt2800_rfcsr_write(rt2x00dev, 61, 0x00);
  30999. + rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
  31000. + rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
  31001. +
  31002. + rt2800_rx_filter_calibration(rt2x00dev);
  31003. + rt2800_led_open_drain_enable(rt2x00dev);
  31004. + rt2800_normal_mode_setup_3xxx(rt2x00dev);
  31005. +}
  31006. +
  31007. +static void rt2800_init_rfcsr_3390(struct rt2x00_dev *rt2x00dev)
  31008. +{
  31009. + u32 reg;
  31010. +
  31011. + rt2800_rf_init_calibration(rt2x00dev, 30);
  31012. +
  31013. + rt2800_rfcsr_write(rt2x00dev, 0, 0xa0);
  31014. + rt2800_rfcsr_write(rt2x00dev, 1, 0xe1);
  31015. + rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
  31016. + rt2800_rfcsr_write(rt2x00dev, 3, 0x62);
  31017. + rt2800_rfcsr_write(rt2x00dev, 4, 0x40);
  31018. + rt2800_rfcsr_write(rt2x00dev, 5, 0x8b);
  31019. + rt2800_rfcsr_write(rt2x00dev, 6, 0x42);
  31020. + rt2800_rfcsr_write(rt2x00dev, 7, 0x34);
  31021. + rt2800_rfcsr_write(rt2x00dev, 8, 0x00);
  31022. + rt2800_rfcsr_write(rt2x00dev, 9, 0xc0);
  31023. + rt2800_rfcsr_write(rt2x00dev, 10, 0x61);
  31024. + rt2800_rfcsr_write(rt2x00dev, 11, 0x21);
  31025. + rt2800_rfcsr_write(rt2x00dev, 12, 0x3b);
  31026. + rt2800_rfcsr_write(rt2x00dev, 13, 0xe0);
  31027. + rt2800_rfcsr_write(rt2x00dev, 14, 0x90);
  31028. + rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
  31029. + rt2800_rfcsr_write(rt2x00dev, 16, 0xe0);
  31030. + rt2800_rfcsr_write(rt2x00dev, 17, 0x94);
  31031. + rt2800_rfcsr_write(rt2x00dev, 18, 0x5c);
  31032. + rt2800_rfcsr_write(rt2x00dev, 19, 0x4a);
  31033. + rt2800_rfcsr_write(rt2x00dev, 20, 0xb2);
  31034. + rt2800_rfcsr_write(rt2x00dev, 21, 0xf6);
  31035. + rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
  31036. + rt2800_rfcsr_write(rt2x00dev, 23, 0x14);
  31037. + rt2800_rfcsr_write(rt2x00dev, 24, 0x08);
  31038. + rt2800_rfcsr_write(rt2x00dev, 25, 0x3d);
  31039. + rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
  31040. + rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
  31041. + rt2800_rfcsr_write(rt2x00dev, 28, 0x41);
  31042. + rt2800_rfcsr_write(rt2x00dev, 29, 0x8f);
  31043. + rt2800_rfcsr_write(rt2x00dev, 30, 0x20);
  31044. + rt2800_rfcsr_write(rt2x00dev, 31, 0x0f);
  31045. +
  31046. + rt2800_register_read(rt2x00dev, GPIO_SWITCH, &reg);
  31047. + rt2x00_set_field32(&reg, GPIO_SWITCH_5, 0);
  31048. + rt2800_register_write(rt2x00dev, GPIO_SWITCH, reg);
  31049. +
  31050. + rt2800_rx_filter_calibration(rt2x00dev);
  31051. +
  31052. + if (rt2x00_rt_rev_lt(rt2x00dev, RT3390, REV_RT3390E))
  31053. + rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  31054. +
  31055. + rt2800_led_open_drain_enable(rt2x00dev);
  31056. + rt2800_normal_mode_setup_3xxx(rt2x00dev);
  31057. +}
  31058. +
  31059. +static void rt2800_init_rfcsr_3572(struct rt2x00_dev *rt2x00dev)
  31060. +{
  31061. + u8 rfcsr;
  31062. + u32 reg;
  31063. +
  31064. + rt2800_rf_init_calibration(rt2x00dev, 30);
  31065. +
  31066. + rt2800_rfcsr_write(rt2x00dev, 0, 0x70);
  31067. + rt2800_rfcsr_write(rt2x00dev, 1, 0x81);
  31068. + rt2800_rfcsr_write(rt2x00dev, 2, 0xf1);
  31069. + rt2800_rfcsr_write(rt2x00dev, 3, 0x02);
  31070. + rt2800_rfcsr_write(rt2x00dev, 4, 0x4c);
  31071. + rt2800_rfcsr_write(rt2x00dev, 5, 0x05);
  31072. + rt2800_rfcsr_write(rt2x00dev, 6, 0x4a);
  31073. + rt2800_rfcsr_write(rt2x00dev, 7, 0xd8);
  31074. + rt2800_rfcsr_write(rt2x00dev, 9, 0xc3);
  31075. + rt2800_rfcsr_write(rt2x00dev, 10, 0xf1);
  31076. + rt2800_rfcsr_write(rt2x00dev, 11, 0xb9);
  31077. + rt2800_rfcsr_write(rt2x00dev, 12, 0x70);
  31078. + rt2800_rfcsr_write(rt2x00dev, 13, 0x65);
  31079. + rt2800_rfcsr_write(rt2x00dev, 14, 0xa0);
  31080. + rt2800_rfcsr_write(rt2x00dev, 15, 0x53);
  31081. + rt2800_rfcsr_write(rt2x00dev, 16, 0x4c);
  31082. + rt2800_rfcsr_write(rt2x00dev, 17, 0x23);
  31083. + rt2800_rfcsr_write(rt2x00dev, 18, 0xac);
  31084. + rt2800_rfcsr_write(rt2x00dev, 19, 0x93);
  31085. + rt2800_rfcsr_write(rt2x00dev, 20, 0xb3);
  31086. + rt2800_rfcsr_write(rt2x00dev, 21, 0xd0);
  31087. + rt2800_rfcsr_write(rt2x00dev, 22, 0x00);
  31088. + rt2800_rfcsr_write(rt2x00dev, 23, 0x3c);
  31089. + rt2800_rfcsr_write(rt2x00dev, 24, 0x16);
  31090. + rt2800_rfcsr_write(rt2x00dev, 25, 0x15);
  31091. + rt2800_rfcsr_write(rt2x00dev, 26, 0x85);
  31092. + rt2800_rfcsr_write(rt2x00dev, 27, 0x00);
  31093. + rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
  31094. + rt2800_rfcsr_write(rt2x00dev, 29, 0x9b);
  31095. + rt2800_rfcsr_write(rt2x00dev, 30, 0x09);
  31096. + rt2800_rfcsr_write(rt2x00dev, 31, 0x10);
  31097. +
  31098. + rt2800_rfcsr_read(rt2x00dev, 6, &rfcsr);
  31099. + rt2x00_set_field8(&rfcsr, RFCSR6_R2, 1);
  31100. + rt2800_rfcsr_write(rt2x00dev, 6, rfcsr);
  31101. +
  31102. + rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
  31103. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 3);
  31104. + rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
  31105. + rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
  31106. + msleep(1);
  31107. + rt2800_register_read(rt2x00dev, LDO_CFG0, &reg);
  31108. + rt2x00_set_field32(&reg, LDO_CFG0_LDO_CORE_VLEVEL, 0);
  31109. + rt2x00_set_field32(&reg, LDO_CFG0_BGSEL, 1);
  31110. + rt2800_register_write(rt2x00dev, LDO_CFG0, reg);
  31111. +
  31112. + rt2800_rx_filter_calibration(rt2x00dev);
  31113. + rt2800_led_open_drain_enable(rt2x00dev);
  31114. + rt2800_normal_mode_setup_3xxx(rt2x00dev);
  31115. +}
  31116. +
  31117. +static void rt2800_init_rfcsr_5390(struct rt2x00_dev *rt2x00dev)
  31118. +{
  31119. + rt2800_rf_init_calibration(rt2x00dev, 2);
  31120. +
  31121. + rt2800_rfcsr_write(rt2x00dev, 1, 0x0f);
  31122. + rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
  31123. + rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
  31124. + rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
  31125. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31126. + rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
  31127. + else
  31128. + rt2800_rfcsr_write(rt2x00dev, 6, 0xa0);
  31129. + rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
  31130. + rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
  31131. + rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
  31132. + rt2800_rfcsr_write(rt2x00dev, 12, 0xc6);
  31133. + rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
  31134. + rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
  31135. + rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
  31136. + rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
  31137. + rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
  31138. + rt2800_rfcsr_write(rt2x00dev, 19, 0x00);
  31139. +
  31140. + rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
  31141. + rt2800_rfcsr_write(rt2x00dev, 21, 0x00);
  31142. + rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
  31143. + rt2800_rfcsr_write(rt2x00dev, 23, 0x00);
  31144. + rt2800_rfcsr_write(rt2x00dev, 24, 0x00);
  31145. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31146. + rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
  31147. + else
  31148. + rt2800_rfcsr_write(rt2x00dev, 25, 0xc0);
  31149. + rt2800_rfcsr_write(rt2x00dev, 26, 0x00);
  31150. + rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
  31151. + rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
  31152. + rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
  31153. +
  31154. + rt2800_rfcsr_write(rt2x00dev, 30, 0x00);
  31155. + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
  31156. + rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
  31157. + rt2800_rfcsr_write(rt2x00dev, 33, 0x00);
  31158. + rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
  31159. + rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
  31160. + rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
  31161. + rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
  31162. + rt2800_rfcsr_write(rt2x00dev, 38, 0x85);
  31163. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
  31164. +
  31165. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31166. + rt2800_rfcsr_write(rt2x00dev, 40, 0x0b);
  31167. + else
  31168. + rt2800_rfcsr_write(rt2x00dev, 40, 0x4b);
  31169. + rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
  31170. + rt2800_rfcsr_write(rt2x00dev, 42, 0xd2);
  31171. + rt2800_rfcsr_write(rt2x00dev, 43, 0x9a);
  31172. + rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
  31173. + rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
  31174. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31175. + rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
  31176. + else
  31177. + rt2800_rfcsr_write(rt2x00dev, 46, 0x7b);
  31178. + rt2800_rfcsr_write(rt2x00dev, 47, 0x00);
  31179. + rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
  31180. + rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
  31181. +
  31182. + rt2800_rfcsr_write(rt2x00dev, 52, 0x38);
  31183. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31184. + rt2800_rfcsr_write(rt2x00dev, 53, 0x00);
  31185. + else
  31186. + rt2800_rfcsr_write(rt2x00dev, 53, 0x84);
  31187. + rt2800_rfcsr_write(rt2x00dev, 54, 0x78);
  31188. + rt2800_rfcsr_write(rt2x00dev, 55, 0x44);
  31189. + rt2800_rfcsr_write(rt2x00dev, 56, 0x22);
  31190. + rt2800_rfcsr_write(rt2x00dev, 57, 0x80);
  31191. + rt2800_rfcsr_write(rt2x00dev, 58, 0x7f);
  31192. + rt2800_rfcsr_write(rt2x00dev, 59, 0x63);
  31193. +
  31194. + rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
  31195. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390F))
  31196. + rt2800_rfcsr_write(rt2x00dev, 61, 0xd1);
  31197. + else
  31198. + rt2800_rfcsr_write(rt2x00dev, 61, 0xdd);
  31199. + rt2800_rfcsr_write(rt2x00dev, 62, 0x00);
  31200. + rt2800_rfcsr_write(rt2x00dev, 63, 0x00);
  31201. +
  31202. + rt2800_normal_mode_setup_5xxx(rt2x00dev);
  31203. +
  31204. + rt2800_led_open_drain_enable(rt2x00dev);
  31205. +}
  31206. +
  31207. +static void rt2800_init_rfcsr_5392(struct rt2x00_dev *rt2x00dev)
  31208. +{
  31209. + rt2800_rf_init_calibration(rt2x00dev, 2);
  31210. +
  31211. + rt2800_rfcsr_write(rt2x00dev, 1, 0x17);
  31212. + rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
  31213. + rt2800_rfcsr_write(rt2x00dev, 3, 0x88);
  31214. + rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
  31215. + rt2800_rfcsr_write(rt2x00dev, 6, 0xe0);
  31216. + rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
  31217. + rt2800_rfcsr_write(rt2x00dev, 10, 0x53);
  31218. + rt2800_rfcsr_write(rt2x00dev, 11, 0x4a);
  31219. + rt2800_rfcsr_write(rt2x00dev, 12, 0x46);
  31220. + rt2800_rfcsr_write(rt2x00dev, 13, 0x9f);
  31221. + rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
  31222. + rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
  31223. + rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
  31224. + rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
  31225. + rt2800_rfcsr_write(rt2x00dev, 19, 0x4d);
  31226. + rt2800_rfcsr_write(rt2x00dev, 20, 0x00);
  31227. + rt2800_rfcsr_write(rt2x00dev, 21, 0x8d);
  31228. + rt2800_rfcsr_write(rt2x00dev, 22, 0x20);
  31229. + rt2800_rfcsr_write(rt2x00dev, 23, 0x0b);
  31230. + rt2800_rfcsr_write(rt2x00dev, 24, 0x44);
  31231. + rt2800_rfcsr_write(rt2x00dev, 25, 0x80);
  31232. + rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
  31233. + rt2800_rfcsr_write(rt2x00dev, 27, 0x09);
  31234. + rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
  31235. + rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
  31236. + rt2800_rfcsr_write(rt2x00dev, 30, 0x10);
  31237. + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
  31238. + rt2800_rfcsr_write(rt2x00dev, 32, 0x20);
  31239. + rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
  31240. + rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
  31241. + rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
  31242. + rt2800_rfcsr_write(rt2x00dev, 36, 0x00);
  31243. + rt2800_rfcsr_write(rt2x00dev, 37, 0x08);
  31244. + rt2800_rfcsr_write(rt2x00dev, 38, 0x89);
  31245. + rt2800_rfcsr_write(rt2x00dev, 39, 0x1b);
  31246. + rt2800_rfcsr_write(rt2x00dev, 40, 0x0f);
  31247. + rt2800_rfcsr_write(rt2x00dev, 41, 0xbb);
  31248. + rt2800_rfcsr_write(rt2x00dev, 42, 0xd5);
  31249. + rt2800_rfcsr_write(rt2x00dev, 43, 0x9b);
  31250. + rt2800_rfcsr_write(rt2x00dev, 44, 0x0e);
  31251. + rt2800_rfcsr_write(rt2x00dev, 45, 0xa2);
  31252. + rt2800_rfcsr_write(rt2x00dev, 46, 0x73);
  31253. + rt2800_rfcsr_write(rt2x00dev, 47, 0x0c);
  31254. + rt2800_rfcsr_write(rt2x00dev, 48, 0x10);
  31255. + rt2800_rfcsr_write(rt2x00dev, 49, 0x94);
  31256. + rt2800_rfcsr_write(rt2x00dev, 50, 0x94);
  31257. + rt2800_rfcsr_write(rt2x00dev, 51, 0x3a);
  31258. + rt2800_rfcsr_write(rt2x00dev, 52, 0x48);
  31259. + rt2800_rfcsr_write(rt2x00dev, 53, 0x44);
  31260. + rt2800_rfcsr_write(rt2x00dev, 54, 0x38);
  31261. + rt2800_rfcsr_write(rt2x00dev, 55, 0x43);
  31262. + rt2800_rfcsr_write(rt2x00dev, 56, 0xa1);
  31263. + rt2800_rfcsr_write(rt2x00dev, 57, 0x00);
  31264. + rt2800_rfcsr_write(rt2x00dev, 58, 0x39);
  31265. + rt2800_rfcsr_write(rt2x00dev, 59, 0x07);
  31266. + rt2800_rfcsr_write(rt2x00dev, 60, 0x45);
  31267. + rt2800_rfcsr_write(rt2x00dev, 61, 0x91);
  31268. + rt2800_rfcsr_write(rt2x00dev, 62, 0x39);
  31269. + rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
  31270. +
  31271. + rt2800_normal_mode_setup_5xxx(rt2x00dev);
  31272. +
  31273. + rt2800_led_open_drain_enable(rt2x00dev);
  31274. +}
  31275. +
  31276. +static void rt2800_init_rfcsr_5592(struct rt2x00_dev *rt2x00dev)
  31277. +{
  31278. + rt2800_rf_init_calibration(rt2x00dev, 30);
  31279. +
  31280. + rt2800_rfcsr_write(rt2x00dev, 1, 0x3F);
  31281. + rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
  31282. + rt2800_rfcsr_write(rt2x00dev, 3, 0x08);
  31283. + rt2800_rfcsr_write(rt2x00dev, 5, 0x10);
  31284. + rt2800_rfcsr_write(rt2x00dev, 6, 0xE4);
  31285. + rt2800_rfcsr_write(rt2x00dev, 7, 0x00);
  31286. + rt2800_rfcsr_write(rt2x00dev, 14, 0x00);
  31287. + rt2800_rfcsr_write(rt2x00dev, 15, 0x00);
  31288. + rt2800_rfcsr_write(rt2x00dev, 16, 0x00);
  31289. + rt2800_rfcsr_write(rt2x00dev, 18, 0x03);
  31290. + rt2800_rfcsr_write(rt2x00dev, 19, 0x4D);
  31291. + rt2800_rfcsr_write(rt2x00dev, 20, 0x10);
  31292. + rt2800_rfcsr_write(rt2x00dev, 21, 0x8D);
  31293. + rt2800_rfcsr_write(rt2x00dev, 26, 0x82);
  31294. + rt2800_rfcsr_write(rt2x00dev, 28, 0x00);
  31295. + rt2800_rfcsr_write(rt2x00dev, 29, 0x10);
  31296. + rt2800_rfcsr_write(rt2x00dev, 33, 0xC0);
  31297. + rt2800_rfcsr_write(rt2x00dev, 34, 0x07);
  31298. + rt2800_rfcsr_write(rt2x00dev, 35, 0x12);
  31299. + rt2800_rfcsr_write(rt2x00dev, 47, 0x0C);
  31300. + rt2800_rfcsr_write(rt2x00dev, 53, 0x22);
  31301. + rt2800_rfcsr_write(rt2x00dev, 63, 0x07);
  31302. +
  31303. + rt2800_rfcsr_write(rt2x00dev, 2, 0x80);
  31304. + msleep(1);
  31305. +
  31306. + rt2800_adjust_freq_offset(rt2x00dev);
  31307. +
  31308. + /* Enable DC filter */
  31309. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5592, REV_RT5592C))
  31310. + rt2800_bbp_write(rt2x00dev, 103, 0xc0);
  31311. +
  31312. + rt2800_normal_mode_setup_5xxx(rt2x00dev);
  31313. +
  31314. + if (rt2x00_rt_rev_lt(rt2x00dev, RT5592, REV_RT5592C))
  31315. + rt2800_rfcsr_write(rt2x00dev, 27, 0x03);
  31316. +
  31317. + rt2800_led_open_drain_enable(rt2x00dev);
  31318. +}
  31319. +
  31320. +static void rt2800_init_rfcsr(struct rt2x00_dev *rt2x00dev)
  31321. +{
  31322. + if (rt2800_is_305x_soc(rt2x00dev)) {
  31323. + rt2800_init_rfcsr_305x_soc(rt2x00dev);
  31324. + return;
  31325. + }
  31326. +
  31327. + switch (rt2x00dev->chip.rt) {
  31328. + case RT3070:
  31329. + case RT3071:
  31330. + case RT3090:
  31331. + rt2800_init_rfcsr_30xx(rt2x00dev);
  31332. + break;
  31333. + case RT3290:
  31334. + rt2800_init_rfcsr_3290(rt2x00dev);
  31335. + break;
  31336. + case RT3352:
  31337. + rt2800_init_rfcsr_3352(rt2x00dev);
  31338. + break;
  31339. + case RT3390:
  31340. + rt2800_init_rfcsr_3390(rt2x00dev);
  31341. + break;
  31342. + case RT3572:
  31343. + rt2800_init_rfcsr_3572(rt2x00dev);
  31344. + break;
  31345. + case RT5390:
  31346. + rt2800_init_rfcsr_5390(rt2x00dev);
  31347. + break;
  31348. + case RT5392:
  31349. + rt2800_init_rfcsr_5392(rt2x00dev);
  31350. + break;
  31351. + case RT5592:
  31352. + rt2800_init_rfcsr_5592(rt2x00dev);
  31353. + break;
  31354. + }
  31355. +}
  31356. +
  31357. +int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev)
  31358. +{
  31359. + u32 reg;
  31360. + u16 word;
  31361. +
  31362. + /*
  31363. + * Initialize all registers.
  31364. + */
  31365. + if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
  31366. + rt2800_init_registers(rt2x00dev)))
  31367. + return -EIO;
  31368. +
  31369. + if (unlikely(rt2800_wait_bbp_rf_ready(rt2x00dev)))
  31370. + return -EIO;
  31371. +
  31372. + /*
  31373. + * Send signal to firmware during boot time.
  31374. + */
  31375. + rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
  31376. + rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  31377. + if (rt2x00_is_usb(rt2x00dev))
  31378. + rt2800_register_write(rt2x00dev, H2M_INT_SRC, 0);
  31379. + rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0, 0, 0);
  31380. + msleep(1);
  31381. +
  31382. + if (unlikely(rt2800_wait_bbp_ready(rt2x00dev)))
  31383. + return -EIO;
  31384. +
  31385. + rt2800_init_bbp(rt2x00dev);
  31386. + rt2800_init_rfcsr(rt2x00dev);
  31387. +
  31388. + if (rt2x00_is_usb(rt2x00dev) &&
  31389. + (rt2x00_rt(rt2x00dev, RT3070) ||
  31390. + rt2x00_rt(rt2x00dev, RT3071) ||
  31391. + rt2x00_rt(rt2x00dev, RT3572))) {
  31392. + udelay(200);
  31393. + rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
  31394. + udelay(10);
  31395. + }
  31396. +
  31397. + /*
  31398. + * Enable RX.
  31399. + */
  31400. + rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  31401. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  31402. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
  31403. + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  31404. +
  31405. + udelay(50);
  31406. +
  31407. + rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
  31408. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
  31409. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
  31410. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 2);
  31411. + rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
  31412. + rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
  31413. +
  31414. + rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  31415. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 1);
  31416. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 1);
  31417. + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  31418. +
  31419. + /*
  31420. + * Initialize LED control
  31421. + */
  31422. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_AG_CONF, &word);
  31423. + rt2800_mcu_request(rt2x00dev, MCU_LED_AG_CONF, 0xff,
  31424. + word & 0xff, (word >> 8) & 0xff);
  31425. +
  31426. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_ACT_CONF, &word);
  31427. + rt2800_mcu_request(rt2x00dev, MCU_LED_ACT_CONF, 0xff,
  31428. + word & 0xff, (word >> 8) & 0xff);
  31429. +
  31430. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LED_POLARITY, &word);
  31431. + rt2800_mcu_request(rt2x00dev, MCU_LED_LED_POLARITY, 0xff,
  31432. + word & 0xff, (word >> 8) & 0xff);
  31433. +
  31434. + return 0;
  31435. +}
  31436. +EXPORT_SYMBOL_GPL(rt2800_enable_radio);
  31437. +
  31438. +void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
  31439. +{
  31440. + u32 reg;
  31441. +
  31442. + rt2800_disable_wpdma(rt2x00dev);
  31443. +
  31444. + /* Wait for DMA, ignore error */
  31445. + rt2800_wait_wpdma_ready(rt2x00dev);
  31446. +
  31447. + rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, &reg);
  31448. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_TX, 0);
  31449. + rt2x00_set_field32(&reg, MAC_SYS_CTRL_ENABLE_RX, 0);
  31450. + rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
  31451. +}
  31452. +EXPORT_SYMBOL_GPL(rt2800_disable_radio);
  31453. +
  31454. +int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
  31455. +{
  31456. + u32 reg;
  31457. + u16 efuse_ctrl_reg;
  31458. +
  31459. + if (rt2x00_rt(rt2x00dev, RT3290))
  31460. + efuse_ctrl_reg = EFUSE_CTRL_3290;
  31461. + else
  31462. + efuse_ctrl_reg = EFUSE_CTRL;
  31463. +
  31464. + rt2800_register_read(rt2x00dev, efuse_ctrl_reg, &reg);
  31465. + return rt2x00_get_field32(reg, EFUSE_CTRL_PRESENT);
  31466. +}
  31467. +EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
  31468. +
  31469. +static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
  31470. +{
  31471. + u32 reg;
  31472. + u16 efuse_ctrl_reg;
  31473. + u16 efuse_data0_reg;
  31474. + u16 efuse_data1_reg;
  31475. + u16 efuse_data2_reg;
  31476. + u16 efuse_data3_reg;
  31477. +
  31478. + if (rt2x00_rt(rt2x00dev, RT3290)) {
  31479. + efuse_ctrl_reg = EFUSE_CTRL_3290;
  31480. + efuse_data0_reg = EFUSE_DATA0_3290;
  31481. + efuse_data1_reg = EFUSE_DATA1_3290;
  31482. + efuse_data2_reg = EFUSE_DATA2_3290;
  31483. + efuse_data3_reg = EFUSE_DATA3_3290;
  31484. + } else {
  31485. + efuse_ctrl_reg = EFUSE_CTRL;
  31486. + efuse_data0_reg = EFUSE_DATA0;
  31487. + efuse_data1_reg = EFUSE_DATA1;
  31488. + efuse_data2_reg = EFUSE_DATA2;
  31489. + efuse_data3_reg = EFUSE_DATA3;
  31490. + }
  31491. + mutex_lock(&rt2x00dev->csr_mutex);
  31492. +
  31493. + rt2800_register_read_lock(rt2x00dev, efuse_ctrl_reg, &reg);
  31494. + rt2x00_set_field32(&reg, EFUSE_CTRL_ADDRESS_IN, i);
  31495. + rt2x00_set_field32(&reg, EFUSE_CTRL_MODE, 0);
  31496. + rt2x00_set_field32(&reg, EFUSE_CTRL_KICK, 1);
  31497. + rt2800_register_write_lock(rt2x00dev, efuse_ctrl_reg, reg);
  31498. +
  31499. + /* Wait until the EEPROM has been loaded */
  31500. + rt2800_regbusy_read(rt2x00dev, efuse_ctrl_reg, EFUSE_CTRL_KICK, &reg);
  31501. + /* Apparently the data is read from end to start */
  31502. + rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, &reg);
  31503. + /* The returned value is in CPU order, but eeprom is le */
  31504. + *(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
  31505. + rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, &reg);
  31506. + *(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
  31507. + rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, &reg);
  31508. + *(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
  31509. + rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, &reg);
  31510. + *(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
  31511. +
  31512. + mutex_unlock(&rt2x00dev->csr_mutex);
  31513. +}
  31514. +
  31515. +int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
  31516. +{
  31517. + unsigned int i;
  31518. +
  31519. + for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
  31520. + rt2800_efuse_read(rt2x00dev, i);
  31521. +
  31522. + return 0;
  31523. +}
  31524. +EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
  31525. +
  31526. +static int rt2800_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  31527. +{
  31528. + struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
  31529. + u16 word;
  31530. + u8 *mac;
  31531. + u8 default_lna_gain;
  31532. + int retval;
  31533. +
  31534. + /*
  31535. + * Read the EEPROM.
  31536. + */
  31537. + retval = rt2800_read_eeprom(rt2x00dev);
  31538. + if (retval)
  31539. + return retval;
  31540. +
  31541. + /*
  31542. + * Start validation of the data that has been read.
  31543. + */
  31544. + mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  31545. + if (!is_valid_ether_addr(mac)) {
  31546. + eth_random_addr(mac);
  31547. + rt2x00_eeprom_dbg(rt2x00dev, "MAC: %pM\n", mac);
  31548. + }
  31549. +
  31550. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &word);
  31551. + if (word == 0xffff) {
  31552. + rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
  31553. + rt2x00_set_field16(&word, EEPROM_NIC_CONF0_TXPATH, 1);
  31554. + rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RF_TYPE, RF2820);
  31555. + rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
  31556. + rt2x00_eeprom_dbg(rt2x00dev, "Antenna: 0x%04x\n", word);
  31557. + } else if (rt2x00_rt(rt2x00dev, RT2860) ||
  31558. + rt2x00_rt(rt2x00dev, RT2872)) {
  31559. + /*
  31560. + * There is a max of 2 RX streams for RT28x0 series
  31561. + */
  31562. + if (rt2x00_get_field16(word, EEPROM_NIC_CONF0_RXPATH) > 2)
  31563. + rt2x00_set_field16(&word, EEPROM_NIC_CONF0_RXPATH, 2);
  31564. + rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF0, word);
  31565. + }
  31566. +
  31567. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &word);
  31568. + if (word == 0xffff) {
  31569. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_HW_RADIO, 0);
  31570. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_TX_ALC, 0);
  31571. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G, 0);
  31572. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G, 0);
  31573. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_CARDBUS_ACCEL, 0);
  31574. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_2G, 0);
  31575. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_SB_5G, 0);
  31576. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_WPS_PBC, 0);
  31577. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_2G, 0);
  31578. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BW40M_5G, 0);
  31579. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BROADBAND_EXT_LNA, 0);
  31580. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_ANT_DIVERSITY, 0);
  31581. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_INTERNAL_TX_ALC, 0);
  31582. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_BT_COEXIST, 0);
  31583. + rt2x00_set_field16(&word, EEPROM_NIC_CONF1_DAC_TEST, 0);
  31584. + rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC_CONF1, word);
  31585. + rt2x00_eeprom_dbg(rt2x00dev, "NIC: 0x%04x\n", word);
  31586. + }
  31587. +
  31588. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  31589. + if ((word & 0x00ff) == 0x00ff) {
  31590. + rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  31591. + rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  31592. + rt2x00_eeprom_dbg(rt2x00dev, "Freq: 0x%04x\n", word);
  31593. + }
  31594. + if ((word & 0xff00) == 0xff00) {
  31595. + rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
  31596. + LED_MODE_TXRX_ACTIVITY);
  31597. + rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
  31598. + rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  31599. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_AG_CONF, 0x5555);
  31600. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_ACT_CONF, 0x2221);
  31601. + rt2x00_eeprom_write(rt2x00dev, EEPROM_LED_POLARITY, 0xa9f8);
  31602. + rt2x00_eeprom_dbg(rt2x00dev, "Led Mode: 0x%04x\n", word);
  31603. + }
  31604. +
  31605. + /*
  31606. + * During the LNA validation we are going to use
  31607. + * lna0 as correct value. Note that EEPROM_LNA
  31608. + * is never validated.
  31609. + */
  31610. + rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
  31611. + default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
  31612. +
  31613. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
  31614. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
  31615. + rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
  31616. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
  31617. + rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
  31618. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
  31619. +
  31620. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_BG, &word);
  31621. + if ((word & 0x00ff) != 0x00ff) {
  31622. + drv_data->txmixer_gain_24g =
  31623. + rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_BG_VAL);
  31624. + } else {
  31625. + drv_data->txmixer_gain_24g = 0;
  31626. + }
  31627. +
  31628. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
  31629. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
  31630. + rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
  31631. + if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
  31632. + rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
  31633. + rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
  31634. + default_lna_gain);
  31635. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
  31636. +
  31637. + rt2x00_eeprom_read(rt2x00dev, EEPROM_TXMIXER_GAIN_A, &word);
  31638. + if ((word & 0x00ff) != 0x00ff) {
  31639. + drv_data->txmixer_gain_5g =
  31640. + rt2x00_get_field16(word, EEPROM_TXMIXER_GAIN_A_VAL);
  31641. + } else {
  31642. + drv_data->txmixer_gain_5g = 0;
  31643. + }
  31644. +
  31645. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
  31646. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
  31647. + rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
  31648. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
  31649. + rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
  31650. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
  31651. +
  31652. + rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
  31653. + if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
  31654. + rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
  31655. + if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
  31656. + rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
  31657. + rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
  31658. + default_lna_gain);
  31659. + rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
  31660. +
  31661. + return 0;
  31662. +}
  31663. +
  31664. +static int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
  31665. +{
  31666. + u16 value;
  31667. + u16 eeprom;
  31668. + u16 rf;
  31669. +
  31670. + /*
  31671. + * Read EEPROM word for configuration.
  31672. + */
  31673. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
  31674. +
  31675. + /*
  31676. + * Identify RF chipset by EEPROM value
  31677. + * RT28xx/RT30xx: defined in "EEPROM_NIC_CONF0_RF_TYPE" field
  31678. + * RT53xx: defined in "EEPROM_CHIP_ID" field
  31679. + */
  31680. + if (rt2x00_rt(rt2x00dev, RT3290) ||
  31681. + rt2x00_rt(rt2x00dev, RT5390) ||
  31682. + rt2x00_rt(rt2x00dev, RT5392))
  31683. + rt2x00_eeprom_read(rt2x00dev, EEPROM_CHIP_ID, &rf);
  31684. + else
  31685. + rf = rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RF_TYPE);
  31686. +
  31687. + switch (rf) {
  31688. + case RF2820:
  31689. + case RF2850:
  31690. + case RF2720:
  31691. + case RF2750:
  31692. + case RF3020:
  31693. + case RF2020:
  31694. + case RF3021:
  31695. + case RF3022:
  31696. + case RF3052:
  31697. + case RF3290:
  31698. + case RF3320:
  31699. + case RF3322:
  31700. + case RF5360:
  31701. + case RF5370:
  31702. + case RF5372:
  31703. + case RF5390:
  31704. + case RF5392:
  31705. + case RF5592:
  31706. + break;
  31707. + default:
  31708. + rt2x00_err(rt2x00dev, "Invalid RF chipset 0x%04x detected\n",
  31709. + rf);
  31710. + return -ENODEV;
  31711. + }
  31712. +
  31713. + rt2x00_set_rf(rt2x00dev, rf);
  31714. +
  31715. + /*
  31716. + * Identify default antenna configuration.
  31717. + */
  31718. + rt2x00dev->default_ant.tx_chain_num =
  31719. + rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH);
  31720. + rt2x00dev->default_ant.rx_chain_num =
  31721. + rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH);
  31722. +
  31723. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF1, &eeprom);
  31724. +
  31725. + if (rt2x00_rt(rt2x00dev, RT3070) ||
  31726. + rt2x00_rt(rt2x00dev, RT3090) ||
  31727. + rt2x00_rt(rt2x00dev, RT3352) ||
  31728. + rt2x00_rt(rt2x00dev, RT3390)) {
  31729. + value = rt2x00_get_field16(eeprom,
  31730. + EEPROM_NIC_CONF1_ANT_DIVERSITY);
  31731. + switch (value) {
  31732. + case 0:
  31733. + case 1:
  31734. + case 2:
  31735. + rt2x00dev->default_ant.tx = ANTENNA_A;
  31736. + rt2x00dev->default_ant.rx = ANTENNA_A;
  31737. + break;
  31738. + case 3:
  31739. + rt2x00dev->default_ant.tx = ANTENNA_A;
  31740. + rt2x00dev->default_ant.rx = ANTENNA_B;
  31741. + break;
  31742. + }
  31743. + } else {
  31744. + rt2x00dev->default_ant.tx = ANTENNA_A;
  31745. + rt2x00dev->default_ant.rx = ANTENNA_A;
  31746. + }
  31747. +
  31748. + if (rt2x00_rt_rev_gte(rt2x00dev, RT5390, REV_RT5390R)) {
  31749. + rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY; /* Unused */
  31750. + rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY; /* Unused */
  31751. + }
  31752. +
  31753. + /*
  31754. + * Determine external LNA informations.
  31755. + */
  31756. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_5G))
  31757. + __set_bit(CAPABILITY_EXTERNAL_LNA_A, &rt2x00dev->cap_flags);
  31758. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_EXTERNAL_LNA_2G))
  31759. + __set_bit(CAPABILITY_EXTERNAL_LNA_BG, &rt2x00dev->cap_flags);
  31760. +
  31761. + /*
  31762. + * Detect if this device has an hardware controlled radio.
  31763. + */
  31764. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_HW_RADIO))
  31765. + __set_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags);
  31766. +
  31767. + /*
  31768. + * Detect if this device has Bluetooth co-existence.
  31769. + */
  31770. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF1_BT_COEXIST))
  31771. + __set_bit(CAPABILITY_BT_COEXIST, &rt2x00dev->cap_flags);
  31772. +
  31773. + /*
  31774. + * Read frequency offset and RF programming sequence.
  31775. + */
  31776. + rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  31777. + rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  31778. +
  31779. + /*
  31780. + * Store led settings, for correct led behaviour.
  31781. + */
  31782. +#ifdef CONFIG_RT2X00_LIB_LEDS
  31783. + rt2800_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  31784. + rt2800_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  31785. + rt2800_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
  31786. +
  31787. + rt2x00dev->led_mcu_reg = eeprom;
  31788. +#endif /* CONFIG_RT2X00_LIB_LEDS */
  31789. +
  31790. + /*
  31791. + * Check if support EIRP tx power limit feature.
  31792. + */
  31793. + rt2x00_eeprom_read(rt2x00dev, EEPROM_EIRP_MAX_TX_POWER, &eeprom);
  31794. +
  31795. + if (rt2x00_get_field16(eeprom, EEPROM_EIRP_MAX_TX_POWER_2GHZ) <
  31796. + EIRP_MAX_TX_POWER_LIMIT)
  31797. + __set_bit(CAPABILITY_POWER_LIMIT, &rt2x00dev->cap_flags);
  31798. +
  31799. + return 0;
  31800. +}
  31801. +
  31802. +/*
  31803. + * RF value list for rt28xx
  31804. + * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
  31805. + */
  31806. +static const struct rf_channel rf_vals[] = {
  31807. + { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
  31808. + { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
  31809. + { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
  31810. + { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
  31811. + { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
  31812. + { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
  31813. + { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
  31814. + { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
  31815. + { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
  31816. + { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
  31817. + { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
  31818. + { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
  31819. + { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
  31820. + { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
  31821. +
  31822. + /* 802.11 UNI / HyperLan 2 */
  31823. + { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
  31824. + { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
  31825. + { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
  31826. + { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
  31827. + { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
  31828. + { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
  31829. + { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
  31830. + { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
  31831. + { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
  31832. + { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
  31833. + { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
  31834. + { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
  31835. +
  31836. + /* 802.11 HyperLan 2 */
  31837. + { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
  31838. + { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
  31839. + { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
  31840. + { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
  31841. + { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
  31842. + { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
  31843. + { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
  31844. + { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
  31845. + { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
  31846. + { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
  31847. + { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
  31848. + { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
  31849. + { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
  31850. + { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
  31851. + { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
  31852. + { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
  31853. +
  31854. + /* 802.11 UNII */
  31855. + { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
  31856. + { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
  31857. + { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
  31858. + { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
  31859. + { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
  31860. + { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
  31861. + { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
  31862. + { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
  31863. + { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
  31864. + { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
  31865. + { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
  31866. +
  31867. + /* 802.11 Japan */
  31868. + { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
  31869. + { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
  31870. + { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
  31871. + { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
  31872. + { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
  31873. + { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
  31874. + { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
  31875. +};
  31876. +
  31877. +/*
  31878. + * RF value list for rt3xxx
  31879. + * Supports: 2.4 GHz (all) & 5.2 GHz (RF3052)
  31880. + */
  31881. +static const struct rf_channel rf_vals_3x[] = {
  31882. + {1, 241, 2, 2 },
  31883. + {2, 241, 2, 7 },
  31884. + {3, 242, 2, 2 },
  31885. + {4, 242, 2, 7 },
  31886. + {5, 243, 2, 2 },
  31887. + {6, 243, 2, 7 },
  31888. + {7, 244, 2, 2 },
  31889. + {8, 244, 2, 7 },
  31890. + {9, 245, 2, 2 },
  31891. + {10, 245, 2, 7 },
  31892. + {11, 246, 2, 2 },
  31893. + {12, 246, 2, 7 },
  31894. + {13, 247, 2, 2 },
  31895. + {14, 248, 2, 4 },
  31896. +
  31897. + /* 802.11 UNI / HyperLan 2 */
  31898. + {36, 0x56, 0, 4},
  31899. + {38, 0x56, 0, 6},
  31900. + {40, 0x56, 0, 8},
  31901. + {44, 0x57, 0, 0},
  31902. + {46, 0x57, 0, 2},
  31903. + {48, 0x57, 0, 4},
  31904. + {52, 0x57, 0, 8},
  31905. + {54, 0x57, 0, 10},
  31906. + {56, 0x58, 0, 0},
  31907. + {60, 0x58, 0, 4},
  31908. + {62, 0x58, 0, 6},
  31909. + {64, 0x58, 0, 8},
  31910. +
  31911. + /* 802.11 HyperLan 2 */
  31912. + {100, 0x5b, 0, 8},
  31913. + {102, 0x5b, 0, 10},
  31914. + {104, 0x5c, 0, 0},
  31915. + {108, 0x5c, 0, 4},
  31916. + {110, 0x5c, 0, 6},
  31917. + {112, 0x5c, 0, 8},
  31918. + {116, 0x5d, 0, 0},
  31919. + {118, 0x5d, 0, 2},
  31920. + {120, 0x5d, 0, 4},
  31921. + {124, 0x5d, 0, 8},
  31922. + {126, 0x5d, 0, 10},
  31923. + {128, 0x5e, 0, 0},
  31924. + {132, 0x5e, 0, 4},
  31925. + {134, 0x5e, 0, 6},
  31926. + {136, 0x5e, 0, 8},
  31927. + {140, 0x5f, 0, 0},
  31928. +
  31929. + /* 802.11 UNII */
  31930. + {149, 0x5f, 0, 9},
  31931. + {151, 0x5f, 0, 11},
  31932. + {153, 0x60, 0, 1},
  31933. + {157, 0x60, 0, 5},
  31934. + {159, 0x60, 0, 7},
  31935. + {161, 0x60, 0, 9},
  31936. + {165, 0x61, 0, 1},
  31937. + {167, 0x61, 0, 3},
  31938. + {169, 0x61, 0, 5},
  31939. + {171, 0x61, 0, 7},
  31940. + {173, 0x61, 0, 9},
  31941. +};
  31942. +
  31943. +static const struct rf_channel rf_vals_5592_xtal20[] = {
  31944. + /* Channel, N, K, mod, R */
  31945. + {1, 482, 4, 10, 3},
  31946. + {2, 483, 4, 10, 3},
  31947. + {3, 484, 4, 10, 3},
  31948. + {4, 485, 4, 10, 3},
  31949. + {5, 486, 4, 10, 3},
  31950. + {6, 487, 4, 10, 3},
  31951. + {7, 488, 4, 10, 3},
  31952. + {8, 489, 4, 10, 3},
  31953. + {9, 490, 4, 10, 3},
  31954. + {10, 491, 4, 10, 3},
  31955. + {11, 492, 4, 10, 3},
  31956. + {12, 493, 4, 10, 3},
  31957. + {13, 494, 4, 10, 3},
  31958. + {14, 496, 8, 10, 3},
  31959. + {36, 172, 8, 12, 1},
  31960. + {38, 173, 0, 12, 1},
  31961. + {40, 173, 4, 12, 1},
  31962. + {42, 173, 8, 12, 1},
  31963. + {44, 174, 0, 12, 1},
  31964. + {46, 174, 4, 12, 1},
  31965. + {48, 174, 8, 12, 1},
  31966. + {50, 175, 0, 12, 1},
  31967. + {52, 175, 4, 12, 1},
  31968. + {54, 175, 8, 12, 1},
  31969. + {56, 176, 0, 12, 1},
  31970. + {58, 176, 4, 12, 1},
  31971. + {60, 176, 8, 12, 1},
  31972. + {62, 177, 0, 12, 1},
  31973. + {64, 177, 4, 12, 1},
  31974. + {100, 183, 4, 12, 1},
  31975. + {102, 183, 8, 12, 1},
  31976. + {104, 184, 0, 12, 1},
  31977. + {106, 184, 4, 12, 1},
  31978. + {108, 184, 8, 12, 1},
  31979. + {110, 185, 0, 12, 1},
  31980. + {112, 185, 4, 12, 1},
  31981. + {114, 185, 8, 12, 1},
  31982. + {116, 186, 0, 12, 1},
  31983. + {118, 186, 4, 12, 1},
  31984. + {120, 186, 8, 12, 1},
  31985. + {122, 187, 0, 12, 1},
  31986. + {124, 187, 4, 12, 1},
  31987. + {126, 187, 8, 12, 1},
  31988. + {128, 188, 0, 12, 1},
  31989. + {130, 188, 4, 12, 1},
  31990. + {132, 188, 8, 12, 1},
  31991. + {134, 189, 0, 12, 1},
  31992. + {136, 189, 4, 12, 1},
  31993. + {138, 189, 8, 12, 1},
  31994. + {140, 190, 0, 12, 1},
  31995. + {149, 191, 6, 12, 1},
  31996. + {151, 191, 10, 12, 1},
  31997. + {153, 192, 2, 12, 1},
  31998. + {155, 192, 6, 12, 1},
  31999. + {157, 192, 10, 12, 1},
  32000. + {159, 193, 2, 12, 1},
  32001. + {161, 193, 6, 12, 1},
  32002. + {165, 194, 2, 12, 1},
  32003. + {184, 164, 0, 12, 1},
  32004. + {188, 164, 4, 12, 1},
  32005. + {192, 165, 8, 12, 1},
  32006. + {196, 166, 0, 12, 1},
  32007. +};
  32008. +
  32009. +static const struct rf_channel rf_vals_5592_xtal40[] = {
  32010. + /* Channel, N, K, mod, R */
  32011. + {1, 241, 2, 10, 3},
  32012. + {2, 241, 7, 10, 3},
  32013. + {3, 242, 2, 10, 3},
  32014. + {4, 242, 7, 10, 3},
  32015. + {5, 243, 2, 10, 3},
  32016. + {6, 243, 7, 10, 3},
  32017. + {7, 244, 2, 10, 3},
  32018. + {8, 244, 7, 10, 3},
  32019. + {9, 245, 2, 10, 3},
  32020. + {10, 245, 7, 10, 3},
  32021. + {11, 246, 2, 10, 3},
  32022. + {12, 246, 7, 10, 3},
  32023. + {13, 247, 2, 10, 3},
  32024. + {14, 248, 4, 10, 3},
  32025. + {36, 86, 4, 12, 1},
  32026. + {38, 86, 6, 12, 1},
  32027. + {40, 86, 8, 12, 1},
  32028. + {42, 86, 10, 12, 1},
  32029. + {44, 87, 0, 12, 1},
  32030. + {46, 87, 2, 12, 1},
  32031. + {48, 87, 4, 12, 1},
  32032. + {50, 87, 6, 12, 1},
  32033. + {52, 87, 8, 12, 1},
  32034. + {54, 87, 10, 12, 1},
  32035. + {56, 88, 0, 12, 1},
  32036. + {58, 88, 2, 12, 1},
  32037. + {60, 88, 4, 12, 1},
  32038. + {62, 88, 6, 12, 1},
  32039. + {64, 88, 8, 12, 1},
  32040. + {100, 91, 8, 12, 1},
  32041. + {102, 91, 10, 12, 1},
  32042. + {104, 92, 0, 12, 1},
  32043. + {106, 92, 2, 12, 1},
  32044. + {108, 92, 4, 12, 1},
  32045. + {110, 92, 6, 12, 1},
  32046. + {112, 92, 8, 12, 1},
  32047. + {114, 92, 10, 12, 1},
  32048. + {116, 93, 0, 12, 1},
  32049. + {118, 93, 2, 12, 1},
  32050. + {120, 93, 4, 12, 1},
  32051. + {122, 93, 6, 12, 1},
  32052. + {124, 93, 8, 12, 1},
  32053. + {126, 93, 10, 12, 1},
  32054. + {128, 94, 0, 12, 1},
  32055. + {130, 94, 2, 12, 1},
  32056. + {132, 94, 4, 12, 1},
  32057. + {134, 94, 6, 12, 1},
  32058. + {136, 94, 8, 12, 1},
  32059. + {138, 94, 10, 12, 1},
  32060. + {140, 95, 0, 12, 1},
  32061. + {149, 95, 9, 12, 1},
  32062. + {151, 95, 11, 12, 1},
  32063. + {153, 96, 1, 12, 1},
  32064. + {155, 96, 3, 12, 1},
  32065. + {157, 96, 5, 12, 1},
  32066. + {159, 96, 7, 12, 1},
  32067. + {161, 96, 9, 12, 1},
  32068. + {165, 97, 1, 12, 1},
  32069. + {184, 82, 0, 12, 1},
  32070. + {188, 82, 4, 12, 1},
  32071. + {192, 82, 8, 12, 1},
  32072. + {196, 83, 0, 12, 1},
  32073. +};
  32074. +
  32075. +static int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  32076. +{
  32077. + struct hw_mode_spec *spec = &rt2x00dev->spec;
  32078. + struct channel_info *info;
  32079. + char *default_power1;
  32080. + char *default_power2;
  32081. + unsigned int i;
  32082. + u16 eeprom;
  32083. + u32 reg;
  32084. +
  32085. + /*
  32086. + * Disable powersaving as default on PCI devices.
  32087. + */
  32088. + if (rt2x00_is_pci(rt2x00dev) || rt2x00_is_soc(rt2x00dev))
  32089. + rt2x00dev->hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  32090. +
  32091. + /*
  32092. + * Initialize all hw fields.
  32093. + */
  32094. + rt2x00dev->hw->flags =
  32095. + IEEE80211_HW_SIGNAL_DBM |
  32096. + IEEE80211_HW_SUPPORTS_PS |
  32097. + IEEE80211_HW_PS_NULLFUNC_STACK |
  32098. + IEEE80211_HW_AMPDU_AGGREGATION |
  32099. + IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  32100. + IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
  32101. +
  32102. + /*
  32103. + * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
  32104. + * unless we are capable of sending the buffered frames out after the
  32105. + * DTIM transmission using rt2x00lib_beacondone. This will send out
  32106. + * multicast and broadcast traffic immediately instead of buffering it
  32107. + * infinitly and thus dropping it after some time.
  32108. + */
  32109. + if (!rt2x00_is_usb(rt2x00dev))
  32110. + rt2x00dev->hw->flags |=
  32111. + IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  32112. +
  32113. + SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  32114. + SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  32115. + rt2x00_eeprom_addr(rt2x00dev,
  32116. + EEPROM_MAC_ADDR_0));
  32117. +
  32118. + /*
  32119. + * As rt2800 has a global fallback table we cannot specify
  32120. + * more then one tx rate per frame but since the hw will
  32121. + * try several rates (based on the fallback table) we should
  32122. + * initialize max_report_rates to the maximum number of rates
  32123. + * we are going to try. Otherwise mac80211 will truncate our
  32124. + * reported tx rates and the rc algortihm will end up with
  32125. + * incorrect data.
  32126. + */
  32127. + rt2x00dev->hw->max_rates = 1;
  32128. + rt2x00dev->hw->max_report_rates = 7;
  32129. + rt2x00dev->hw->max_rate_tries = 1;
  32130. +
  32131. + rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC_CONF0, &eeprom);
  32132. +
  32133. + /*
  32134. + * Initialize hw_mode information.
  32135. + */
  32136. + spec->supported_bands = SUPPORT_BAND_2GHZ;
  32137. + spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  32138. +
  32139. + if (rt2x00_rf(rt2x00dev, RF2820) ||
  32140. + rt2x00_rf(rt2x00dev, RF2720)) {
  32141. + spec->num_channels = 14;
  32142. + spec->channels = rf_vals;
  32143. + } else if (rt2x00_rf(rt2x00dev, RF2850) ||
  32144. + rt2x00_rf(rt2x00dev, RF2750)) {
  32145. + spec->supported_bands |= SUPPORT_BAND_5GHZ;
  32146. + spec->num_channels = ARRAY_SIZE(rf_vals);
  32147. + spec->channels = rf_vals;
  32148. + } else if (rt2x00_rf(rt2x00dev, RF3020) ||
  32149. + rt2x00_rf(rt2x00dev, RF2020) ||
  32150. + rt2x00_rf(rt2x00dev, RF3021) ||
  32151. + rt2x00_rf(rt2x00dev, RF3022) ||
  32152. + rt2x00_rf(rt2x00dev, RF3290) ||
  32153. + rt2x00_rf(rt2x00dev, RF3320) ||
  32154. + rt2x00_rf(rt2x00dev, RF3322) ||
  32155. + rt2x00_rf(rt2x00dev, RF5360) ||
  32156. + rt2x00_rf(rt2x00dev, RF5370) ||
  32157. + rt2x00_rf(rt2x00dev, RF5372) ||
  32158. + rt2x00_rf(rt2x00dev, RF5390) ||
  32159. + rt2x00_rf(rt2x00dev, RF5392)) {
  32160. + spec->num_channels = 14;
  32161. + spec->channels = rf_vals_3x;
  32162. + } else if (rt2x00_rf(rt2x00dev, RF3052)) {
  32163. + spec->supported_bands |= SUPPORT_BAND_5GHZ;
  32164. + spec->num_channels = ARRAY_SIZE(rf_vals_3x);
  32165. + spec->channels = rf_vals_3x;
  32166. + } else if (rt2x00_rf(rt2x00dev, RF5592)) {
  32167. + spec->supported_bands |= SUPPORT_BAND_5GHZ;
  32168. +
  32169. + rt2800_register_read(rt2x00dev, MAC_DEBUG_INDEX, &reg);
  32170. + if (rt2x00_get_field32(reg, MAC_DEBUG_INDEX_XTAL)) {
  32171. + spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal40);
  32172. + spec->channels = rf_vals_5592_xtal40;
  32173. + } else {
  32174. + spec->num_channels = ARRAY_SIZE(rf_vals_5592_xtal20);
  32175. + spec->channels = rf_vals_5592_xtal20;
  32176. + }
  32177. + }
  32178. +
  32179. + if (WARN_ON_ONCE(!spec->channels))
  32180. + return -ENODEV;
  32181. +
  32182. + /*
  32183. + * Initialize HT information.
  32184. + */
  32185. + if (!rt2x00_rf(rt2x00dev, RF2020))
  32186. + spec->ht.ht_supported = true;
  32187. + else
  32188. + spec->ht.ht_supported = false;
  32189. +
  32190. + spec->ht.cap =
  32191. + IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  32192. + IEEE80211_HT_CAP_GRN_FLD |
  32193. + IEEE80211_HT_CAP_SGI_20 |
  32194. + IEEE80211_HT_CAP_SGI_40;
  32195. +
  32196. + if (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) >= 2)
  32197. + spec->ht.cap |= IEEE80211_HT_CAP_TX_STBC;
  32198. +
  32199. + spec->ht.cap |=
  32200. + rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH) <<
  32201. + IEEE80211_HT_CAP_RX_STBC_SHIFT;
  32202. +
  32203. + spec->ht.ampdu_factor = 3;
  32204. + spec->ht.ampdu_density = 4;
  32205. + spec->ht.mcs.tx_params =
  32206. + IEEE80211_HT_MCS_TX_DEFINED |
  32207. + IEEE80211_HT_MCS_TX_RX_DIFF |
  32208. + ((rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_TXPATH) - 1) <<
  32209. + IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  32210. +
  32211. + switch (rt2x00_get_field16(eeprom, EEPROM_NIC_CONF0_RXPATH)) {
  32212. + case 3:
  32213. + spec->ht.mcs.rx_mask[2] = 0xff;
  32214. + case 2:
  32215. + spec->ht.mcs.rx_mask[1] = 0xff;
  32216. + case 1:
  32217. + spec->ht.mcs.rx_mask[0] = 0xff;
  32218. + spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
  32219. + break;
  32220. + }
  32221. +
  32222. + /*
  32223. + * Create channel information array
  32224. + */
  32225. + info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
  32226. + if (!info)
  32227. + return -ENOMEM;
  32228. +
  32229. + spec->channels_info = info;
  32230. +
  32231. + default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
  32232. + default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
  32233. +
  32234. + for (i = 0; i < 14; i++) {
  32235. + info[i].default_power1 = default_power1[i];
  32236. + info[i].default_power2 = default_power2[i];
  32237. + }
  32238. +
  32239. + if (spec->num_channels > 14) {
  32240. + default_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
  32241. + default_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
  32242. +
  32243. + for (i = 14; i < spec->num_channels; i++) {
  32244. + info[i].default_power1 = default_power1[i - 14];
  32245. + info[i].default_power2 = default_power2[i - 14];
  32246. + }
  32247. + }
  32248. +
  32249. + switch (rt2x00dev->chip.rf) {
  32250. + case RF2020:
  32251. + case RF3020:
  32252. + case RF3021:
  32253. + case RF3022:
  32254. + case RF3320:
  32255. + case RF3052:
  32256. + case RF3290:
  32257. + case RF5360:
  32258. + case RF5370:
  32259. + case RF5372:
  32260. + case RF5390:
  32261. + case RF5392:
  32262. + __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
  32263. + break;
  32264. + }
  32265. +
  32266. + return 0;
  32267. +}
  32268. +
  32269. +static int rt2800_probe_rt(struct rt2x00_dev *rt2x00dev)
  32270. +{
  32271. + u32 reg;
  32272. + u32 rt;
  32273. + u32 rev;
  32274. +
  32275. + if (rt2x00_rt(rt2x00dev, RT3290))
  32276. + rt2800_register_read(rt2x00dev, MAC_CSR0_3290, &reg);
  32277. + else
  32278. + rt2800_register_read(rt2x00dev, MAC_CSR0, &reg);
  32279. +
  32280. + rt = rt2x00_get_field32(reg, MAC_CSR0_CHIPSET);
  32281. + rev = rt2x00_get_field32(reg, MAC_CSR0_REVISION);
  32282. +
  32283. + switch (rt) {
  32284. + case RT2860:
  32285. + case RT2872:
  32286. + case RT2883:
  32287. + case RT3070:
  32288. + case RT3071:
  32289. + case RT3090:
  32290. + case RT3290:
  32291. + case RT3352:
  32292. + case RT3390:
  32293. + case RT3572:
  32294. + case RT5390:
  32295. + case RT5392:
  32296. + case RT5592:
  32297. + break;
  32298. + default:
  32299. + rt2x00_err(rt2x00dev, "Invalid RT chipset 0x%04x, rev %04x detected\n",
  32300. + rt, rev);
  32301. + return -ENODEV;
  32302. + }
  32303. +
  32304. + rt2x00_set_rt(rt2x00dev, rt, rev);
  32305. +
  32306. + return 0;
  32307. +}
  32308. +
  32309. +int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev)
  32310. +{
  32311. + int retval;
  32312. + u32 reg;
  32313. +
  32314. + retval = rt2800_probe_rt(rt2x00dev);
  32315. + if (retval)
  32316. + return retval;
  32317. +
  32318. + /*
  32319. + * Allocate eeprom data.
  32320. + */
  32321. + retval = rt2800_validate_eeprom(rt2x00dev);
  32322. + if (retval)
  32323. + return retval;
  32324. +
  32325. + retval = rt2800_init_eeprom(rt2x00dev);
  32326. + if (retval)
  32327. + return retval;
  32328. +
  32329. + /*
  32330. + * Enable rfkill polling by setting GPIO direction of the
  32331. + * rfkill switch GPIO pin correctly.
  32332. + */
  32333. + rt2800_register_read(rt2x00dev, GPIO_CTRL, &reg);
  32334. + rt2x00_set_field32(&reg, GPIO_CTRL_DIR2, 1);
  32335. + rt2800_register_write(rt2x00dev, GPIO_CTRL, reg);
  32336. +
  32337. + /*
  32338. + * Initialize hw specifications.
  32339. + */
  32340. + retval = rt2800_probe_hw_mode(rt2x00dev);
  32341. + if (retval)
  32342. + return retval;
  32343. +
  32344. + /*
  32345. + * Set device capabilities.
  32346. + */
  32347. + __set_bit(CAPABILITY_CONTROL_FILTERS, &rt2x00dev->cap_flags);
  32348. + __set_bit(CAPABILITY_CONTROL_FILTER_PSPOLL, &rt2x00dev->cap_flags);
  32349. + if (!rt2x00_is_usb(rt2x00dev))
  32350. + __set_bit(CAPABILITY_PRE_TBTT_INTERRUPT, &rt2x00dev->cap_flags);
  32351. +
  32352. + /*
  32353. + * Set device requirements.
  32354. + */
  32355. + if (!rt2x00_is_soc(rt2x00dev))
  32356. + __set_bit(REQUIRE_FIRMWARE, &rt2x00dev->cap_flags);
  32357. + __set_bit(REQUIRE_L2PAD, &rt2x00dev->cap_flags);
  32358. + __set_bit(REQUIRE_TXSTATUS_FIFO, &rt2x00dev->cap_flags);
  32359. + if (!rt2800_hwcrypt_disabled(rt2x00dev))
  32360. + __set_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags);
  32361. + __set_bit(CAPABILITY_LINK_TUNING, &rt2x00dev->cap_flags);
  32362. + __set_bit(REQUIRE_HT_TX_DESC, &rt2x00dev->cap_flags);
  32363. + if (rt2x00_is_usb(rt2x00dev))
  32364. + __set_bit(REQUIRE_PS_AUTOWAKE, &rt2x00dev->cap_flags);
  32365. + else {
  32366. + __set_bit(REQUIRE_DMA, &rt2x00dev->cap_flags);
  32367. + __set_bit(REQUIRE_TASKLET_CONTEXT, &rt2x00dev->cap_flags);
  32368. + }
  32369. +
  32370. + /*
  32371. + * Set the rssi offset.
  32372. + */
  32373. + rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  32374. +
  32375. + return 0;
  32376. +}
  32377. +EXPORT_SYMBOL_GPL(rt2800_probe_hw);
  32378. +
  32379. +/*
  32380. + * IEEE80211 stack callback functions.
  32381. + */
  32382. +void rt2800_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx, u32 *iv32,
  32383. + u16 *iv16)
  32384. +{
  32385. + struct rt2x00_dev *rt2x00dev = hw->priv;
  32386. + struct mac_iveiv_entry iveiv_entry;
  32387. + u32 offset;
  32388. +
  32389. + offset = MAC_IVEIV_ENTRY(hw_key_idx);
  32390. + rt2800_register_multiread(rt2x00dev, offset,
  32391. + &iveiv_entry, sizeof(iveiv_entry));
  32392. +
  32393. + memcpy(iv16, &iveiv_entry.iv[0], sizeof(*iv16));
  32394. + memcpy(iv32, &iveiv_entry.iv[4], sizeof(*iv32));
  32395. +}
  32396. +EXPORT_SYMBOL_GPL(rt2800_get_tkip_seq);
  32397. +
  32398. +int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  32399. +{
  32400. + struct rt2x00_dev *rt2x00dev = hw->priv;
  32401. + u32 reg;
  32402. + bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
  32403. +
  32404. + rt2800_register_read(rt2x00dev, TX_RTS_CFG, &reg);
  32405. + rt2x00_set_field32(&reg, TX_RTS_CFG_RTS_THRES, value);
  32406. + rt2800_register_write(rt2x00dev, TX_RTS_CFG, reg);
  32407. +
  32408. + rt2800_register_read(rt2x00dev, CCK_PROT_CFG, &reg);
  32409. + rt2x00_set_field32(&reg, CCK_PROT_CFG_RTS_TH_EN, enabled);
  32410. + rt2800_register_write(rt2x00dev, CCK_PROT_CFG, reg);
  32411. +
  32412. + rt2800_register_read(rt2x00dev, OFDM_PROT_CFG, &reg);
  32413. + rt2x00_set_field32(&reg, OFDM_PROT_CFG_RTS_TH_EN, enabled);
  32414. + rt2800_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
  32415. +
  32416. + rt2800_register_read(rt2x00dev, MM20_PROT_CFG, &reg);
  32417. + rt2x00_set_field32(&reg, MM20_PROT_CFG_RTS_TH_EN, enabled);
  32418. + rt2800_register_write(rt2x00dev, MM20_PROT_CFG, reg);
  32419. +
  32420. + rt2800_register_read(rt2x00dev, MM40_PROT_CFG, &reg);
  32421. + rt2x00_set_field32(&reg, MM40_PROT_CFG_RTS_TH_EN, enabled);
  32422. + rt2800_register_write(rt2x00dev, MM40_PROT_CFG, reg);
  32423. +
  32424. + rt2800_register_read(rt2x00dev, GF20_PROT_CFG, &reg);
  32425. + rt2x00_set_field32(&reg, GF20_PROT_CFG_RTS_TH_EN, enabled);
  32426. + rt2800_register_write(rt2x00dev, GF20_PROT_CFG, reg);
  32427. +
  32428. + rt2800_register_read(rt2x00dev, GF40_PROT_CFG, &reg);
  32429. + rt2x00_set_field32(&reg, GF40_PROT_CFG_RTS_TH_EN, enabled);
  32430. + rt2800_register_write(rt2x00dev, GF40_PROT_CFG, reg);
  32431. +
  32432. + return 0;
  32433. +}
  32434. +EXPORT_SYMBOL_GPL(rt2800_set_rts_threshold);
  32435. +
  32436. +int rt2800_conf_tx(struct ieee80211_hw *hw,
  32437. + struct ieee80211_vif *vif, u16 queue_idx,
  32438. + const struct ieee80211_tx_queue_params *params)
  32439. +{
  32440. + struct rt2x00_dev *rt2x00dev = hw->priv;
  32441. + struct data_queue *queue;
  32442. + struct rt2x00_field32 field;
  32443. + int retval;
  32444. + u32 reg;
  32445. + u32 offset;
  32446. +
  32447. + /*
  32448. + * First pass the configuration through rt2x00lib, that will
  32449. + * update the queue settings and validate the input. After that
  32450. + * we are free to update the registers based on the value
  32451. + * in the queue parameter.
  32452. + */
  32453. + retval = rt2x00mac_conf_tx(hw, vif, queue_idx, params);
  32454. + if (retval)
  32455. + return retval;
  32456. +
  32457. + /*
  32458. + * We only need to perform additional register initialization
  32459. + * for WMM queues/
  32460. + */
  32461. + if (queue_idx >= 4)
  32462. + return 0;
  32463. +
  32464. + queue = rt2x00queue_get_tx_queue(rt2x00dev, queue_idx);
  32465. +
  32466. + /* Update WMM TXOP register */
  32467. + offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
  32468. + field.bit_offset = (queue_idx & 1) * 16;
  32469. + field.bit_mask = 0xffff << field.bit_offset;
  32470. +
  32471. + rt2800_register_read(rt2x00dev, offset, &reg);
  32472. + rt2x00_set_field32(&reg, field, queue->txop);
  32473. + rt2800_register_write(rt2x00dev, offset, reg);
  32474. +
  32475. + /* Update WMM registers */
  32476. + field.bit_offset = queue_idx * 4;
  32477. + field.bit_mask = 0xf << field.bit_offset;
  32478. +
  32479. + rt2800_register_read(rt2x00dev, WMM_AIFSN_CFG, &reg);
  32480. + rt2x00_set_field32(&reg, field, queue->aifs);
  32481. + rt2800_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
  32482. +
  32483. + rt2800_register_read(rt2x00dev, WMM_CWMIN_CFG, &reg);
  32484. + rt2x00_set_field32(&reg, field, queue->cw_min);
  32485. + rt2800_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
  32486. +
  32487. + rt2800_register_read(rt2x00dev, WMM_CWMAX_CFG, &reg);
  32488. + rt2x00_set_field32(&reg, field, queue->cw_max);
  32489. + rt2800_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
  32490. +
  32491. + /* Update EDCA registers */
  32492. + offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
  32493. +
  32494. + rt2800_register_read(rt2x00dev, offset, &reg);
  32495. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_TX_OP, queue->txop);
  32496. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_AIFSN, queue->aifs);
  32497. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMIN, queue->cw_min);
  32498. + rt2x00_set_field32(&reg, EDCA_AC0_CFG_CWMAX, queue->cw_max);
  32499. + rt2800_register_write(rt2x00dev, offset, reg);
  32500. +
  32501. + return 0;
  32502. +}
  32503. +EXPORT_SYMBOL_GPL(rt2800_conf_tx);
  32504. +
  32505. +u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  32506. +{
  32507. + struct rt2x00_dev *rt2x00dev = hw->priv;
  32508. + u64 tsf;
  32509. + u32 reg;
  32510. +
  32511. + rt2800_register_read(rt2x00dev, TSF_TIMER_DW1, &reg);
  32512. + tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
  32513. + rt2800_register_read(rt2x00dev, TSF_TIMER_DW0, &reg);
  32514. + tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
  32515. +
  32516. + return tsf;
  32517. +}
  32518. +EXPORT_SYMBOL_GPL(rt2800_get_tsf);
  32519. +
  32520. +int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  32521. + enum ieee80211_ampdu_mlme_action action,
  32522. + struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  32523. + u8 buf_size)
  32524. +{
  32525. + struct rt2x00_sta *sta_priv = (struct rt2x00_sta *)sta->drv_priv;
  32526. + int ret = 0;
  32527. +
  32528. + /*
  32529. + * Don't allow aggregation for stations the hardware isn't aware
  32530. + * of because tx status reports for frames to an unknown station
  32531. + * always contain wcid=255 and thus we can't distinguish between
  32532. + * multiple stations which leads to unwanted situations when the
  32533. + * hw reorders frames due to aggregation.
  32534. + */
  32535. + if (sta_priv->wcid < 0)
  32536. + return 1;
  32537. +
  32538. + switch (action) {
  32539. + case IEEE80211_AMPDU_RX_START:
  32540. + case IEEE80211_AMPDU_RX_STOP:
  32541. + /*
  32542. + * The hw itself takes care of setting up BlockAck mechanisms.
  32543. + * So, we only have to allow mac80211 to nagotiate a BlockAck
  32544. + * agreement. Once that is done, the hw will BlockAck incoming
  32545. + * AMPDUs without further setup.
  32546. + */
  32547. + break;
  32548. + case IEEE80211_AMPDU_TX_START:
  32549. + ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  32550. + break;
  32551. + case IEEE80211_AMPDU_TX_STOP_CONT:
  32552. + case IEEE80211_AMPDU_TX_STOP_FLUSH:
  32553. + case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  32554. + ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  32555. + break;
  32556. + case IEEE80211_AMPDU_TX_OPERATIONAL:
  32557. + break;
  32558. + default:
  32559. + rt2x00_warn((struct rt2x00_dev *)hw->priv,
  32560. + "Unknown AMPDU action\n");
  32561. + }
  32562. +
  32563. + return ret;
  32564. +}
  32565. +EXPORT_SYMBOL_GPL(rt2800_ampdu_action);
  32566. +
  32567. +int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
  32568. + struct survey_info *survey)
  32569. +{
  32570. + struct rt2x00_dev *rt2x00dev = hw->priv;
  32571. + struct ieee80211_conf *conf = &hw->conf;
  32572. + u32 idle, busy, busy_ext;
  32573. +
  32574. + if (idx != 0)
  32575. + return -ENOENT;
  32576. +
  32577. + survey->channel = conf->chandef.chan;
  32578. +
  32579. + rt2800_register_read(rt2x00dev, CH_IDLE_STA, &idle);
  32580. + rt2800_register_read(rt2x00dev, CH_BUSY_STA, &busy);
  32581. + rt2800_register_read(rt2x00dev, CH_BUSY_STA_SEC, &busy_ext);
  32582. +
  32583. + if (idle || busy) {
  32584. + survey->filled = SURVEY_INFO_CHANNEL_TIME |
  32585. + SURVEY_INFO_CHANNEL_TIME_BUSY |
  32586. + SURVEY_INFO_CHANNEL_TIME_EXT_BUSY;
  32587. +
  32588. + survey->channel_time = (idle + busy) / 1000;
  32589. + survey->channel_time_busy = busy / 1000;
  32590. + survey->channel_time_ext_busy = busy_ext / 1000;
  32591. + }
  32592. +
  32593. + if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL))
  32594. + survey->filled |= SURVEY_INFO_IN_USE;
  32595. +
  32596. + return 0;
  32597. +
  32598. +}
  32599. +EXPORT_SYMBOL_GPL(rt2800_get_survey);
  32600. +
  32601. +MODULE_AUTHOR(DRV_PROJECT ", Bartlomiej Zolnierkiewicz");
  32602. +MODULE_VERSION(DRV_VERSION);
  32603. +MODULE_DESCRIPTION("Ralink RT2800 library");
  32604. +MODULE_LICENSE("GPL");
  32605. diff -Nur linux-3.11.10.orig/drivers/spi/Kconfig linux-3.11.10/drivers/spi/Kconfig
  32606. --- linux-3.11.10.orig/drivers/spi/Kconfig 2013-11-29 19:42:37.000000000 +0100
  32607. +++ linux-3.11.10/drivers/spi/Kconfig 2014-02-07 19:57:29.000000000 +0100
  32608. @@ -86,6 +86,14 @@
  32609. is for the regular SPI controller. Slave mode operation is not also
  32610. not supported.
  32611. +config SPI_BCM2708
  32612. + tristate "BCM2708 SPI controller driver (SPI0)"
  32613. + depends on MACH_BCM2708
  32614. + help
  32615. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  32616. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  32617. + device.
  32618. +
  32619. config SPI_BFIN5XX
  32620. tristate "SPI controller driver for ADI Blackfin5xx"
  32621. depends on BLACKFIN
  32622. diff -Nur linux-3.11.10.orig/drivers/spi/Makefile linux-3.11.10/drivers/spi/Makefile
  32623. --- linux-3.11.10.orig/drivers/spi/Makefile 2013-11-29 19:42:37.000000000 +0100
  32624. +++ linux-3.11.10/drivers/spi/Makefile 2014-02-07 19:57:29.000000000 +0100
  32625. @@ -17,6 +17,7 @@
  32626. obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o
  32627. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  32628. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  32629. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  32630. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  32631. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  32632. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  32633. diff -Nur linux-3.11.10.orig/drivers/spi/spi-bcm2708.c linux-3.11.10/drivers/spi/spi-bcm2708.c
  32634. --- linux-3.11.10.orig/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  32635. +++ linux-3.11.10/drivers/spi/spi-bcm2708.c 2014-02-07 19:57:29.000000000 +0100
  32636. @@ -0,0 +1,626 @@
  32637. +/*
  32638. + * Driver for Broadcom BCM2708 SPI Controllers
  32639. + *
  32640. + * Copyright (C) 2012 Chris Boot
  32641. + *
  32642. + * This driver is inspired by:
  32643. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  32644. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  32645. + *
  32646. + * This program is free software; you can redistribute it and/or modify
  32647. + * it under the terms of the GNU General Public License as published by
  32648. + * the Free Software Foundation; either version 2 of the License, or
  32649. + * (at your option) any later version.
  32650. + *
  32651. + * This program is distributed in the hope that it will be useful,
  32652. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32653. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32654. + * GNU General Public License for more details.
  32655. + *
  32656. + * You should have received a copy of the GNU General Public License
  32657. + * along with this program; if not, write to the Free Software
  32658. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32659. + */
  32660. +
  32661. +#include <linux/kernel.h>
  32662. +#include <linux/module.h>
  32663. +#include <linux/spinlock.h>
  32664. +#include <linux/clk.h>
  32665. +#include <linux/err.h>
  32666. +#include <linux/platform_device.h>
  32667. +#include <linux/io.h>
  32668. +#include <linux/spi/spi.h>
  32669. +#include <linux/interrupt.h>
  32670. +#include <linux/delay.h>
  32671. +#include <linux/log2.h>
  32672. +#include <linux/sched.h>
  32673. +#include <linux/wait.h>
  32674. +
  32675. +/* SPI register offsets */
  32676. +#define SPI_CS 0x00
  32677. +#define SPI_FIFO 0x04
  32678. +#define SPI_CLK 0x08
  32679. +#define SPI_DLEN 0x0c
  32680. +#define SPI_LTOH 0x10
  32681. +#define SPI_DC 0x14
  32682. +
  32683. +/* Bitfields in CS */
  32684. +#define SPI_CS_LEN_LONG 0x02000000
  32685. +#define SPI_CS_DMA_LEN 0x01000000
  32686. +#define SPI_CS_CSPOL2 0x00800000
  32687. +#define SPI_CS_CSPOL1 0x00400000
  32688. +#define SPI_CS_CSPOL0 0x00200000
  32689. +#define SPI_CS_RXF 0x00100000
  32690. +#define SPI_CS_RXR 0x00080000
  32691. +#define SPI_CS_TXD 0x00040000
  32692. +#define SPI_CS_RXD 0x00020000
  32693. +#define SPI_CS_DONE 0x00010000
  32694. +#define SPI_CS_LEN 0x00002000
  32695. +#define SPI_CS_REN 0x00001000
  32696. +#define SPI_CS_ADCS 0x00000800
  32697. +#define SPI_CS_INTR 0x00000400
  32698. +#define SPI_CS_INTD 0x00000200
  32699. +#define SPI_CS_DMAEN 0x00000100
  32700. +#define SPI_CS_TA 0x00000080
  32701. +#define SPI_CS_CSPOL 0x00000040
  32702. +#define SPI_CS_CLEAR_RX 0x00000020
  32703. +#define SPI_CS_CLEAR_TX 0x00000010
  32704. +#define SPI_CS_CPOL 0x00000008
  32705. +#define SPI_CS_CPHA 0x00000004
  32706. +#define SPI_CS_CS_10 0x00000002
  32707. +#define SPI_CS_CS_01 0x00000001
  32708. +
  32709. +#define SPI_TIMEOUT_MS 150
  32710. +
  32711. +#define DRV_NAME "bcm2708_spi"
  32712. +
  32713. +struct bcm2708_spi {
  32714. + spinlock_t lock;
  32715. + void __iomem *base;
  32716. + int irq;
  32717. + struct clk *clk;
  32718. + bool stopping;
  32719. +
  32720. + struct list_head queue;
  32721. + struct workqueue_struct *workq;
  32722. + struct work_struct work;
  32723. + struct completion done;
  32724. +
  32725. + const u8 *tx_buf;
  32726. + u8 *rx_buf;
  32727. + int len;
  32728. +};
  32729. +
  32730. +struct bcm2708_spi_state {
  32731. + u32 cs;
  32732. + u16 cdiv;
  32733. +};
  32734. +
  32735. +/*
  32736. + * This function sets the ALT mode on the SPI pins so that we can use them with
  32737. + * the SPI hardware.
  32738. + *
  32739. + * FIXME: This is a hack. Use pinmux / pinctrl.
  32740. + */
  32741. +static void bcm2708_init_pinmode(void)
  32742. +{
  32743. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  32744. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  32745. +
  32746. + int pin;
  32747. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  32748. +
  32749. + /* SPI is on GPIO 7..11 */
  32750. + for (pin = 7; pin <= 11; pin++) {
  32751. + INP_GPIO(pin); /* set mode to GPIO input first */
  32752. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  32753. + }
  32754. +
  32755. + iounmap(gpio);
  32756. +
  32757. +#undef INP_GPIO
  32758. +#undef SET_GPIO_ALT
  32759. +}
  32760. +
  32761. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  32762. +{
  32763. + return readl(bs->base + reg);
  32764. +}
  32765. +
  32766. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  32767. +{
  32768. + writel(val, bs->base + reg);
  32769. +}
  32770. +
  32771. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  32772. +{
  32773. + u8 byte;
  32774. +
  32775. + while (len--) {
  32776. + byte = bcm2708_rd(bs, SPI_FIFO);
  32777. + if (bs->rx_buf)
  32778. + *bs->rx_buf++ = byte;
  32779. + }
  32780. +}
  32781. +
  32782. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  32783. +{
  32784. + u8 byte;
  32785. + u16 val;
  32786. +
  32787. + if (len > bs->len)
  32788. + len = bs->len;
  32789. +
  32790. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  32791. + /* LoSSI mode */
  32792. + if (unlikely(len % 2)) {
  32793. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  32794. + bs->len = 0;
  32795. + return;
  32796. + }
  32797. + while (len) {
  32798. + if (bs->tx_buf) {
  32799. + val = *(const u16 *)bs->tx_buf;
  32800. + bs->tx_buf += 2;
  32801. + } else
  32802. + val = 0;
  32803. + bcm2708_wr(bs, SPI_FIFO, val);
  32804. + bs->len -= 2;
  32805. + len -= 2;
  32806. + }
  32807. + return;
  32808. + }
  32809. +
  32810. + while (len--) {
  32811. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  32812. + bcm2708_wr(bs, SPI_FIFO, byte);
  32813. + bs->len--;
  32814. + }
  32815. +}
  32816. +
  32817. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  32818. +{
  32819. + struct spi_master *master = dev_id;
  32820. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32821. + u32 cs;
  32822. +
  32823. + spin_lock(&bs->lock);
  32824. +
  32825. + cs = bcm2708_rd(bs, SPI_CS);
  32826. +
  32827. + if (cs & SPI_CS_DONE) {
  32828. + if (bs->len) { /* first interrupt in a transfer */
  32829. + /* fill the TX fifo with up to 16 bytes */
  32830. + bcm2708_wr_fifo(bs, 16);
  32831. + } else { /* transfer complete */
  32832. + /* disable interrupts */
  32833. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  32834. + bcm2708_wr(bs, SPI_CS, cs);
  32835. +
  32836. + /* drain RX FIFO */
  32837. + while (cs & SPI_CS_RXD) {
  32838. + bcm2708_rd_fifo(bs, 1);
  32839. + cs = bcm2708_rd(bs, SPI_CS);
  32840. + }
  32841. +
  32842. + /* wake up our bh */
  32843. + complete(&bs->done);
  32844. + }
  32845. + } else if (cs & SPI_CS_RXR) {
  32846. + /* read 12 bytes of data */
  32847. + bcm2708_rd_fifo(bs, 12);
  32848. +
  32849. + /* write up to 12 bytes */
  32850. + bcm2708_wr_fifo(bs, 12);
  32851. + }
  32852. +
  32853. + spin_unlock(&bs->lock);
  32854. +
  32855. + return IRQ_HANDLED;
  32856. +}
  32857. +
  32858. +static int bcm2708_setup_state(struct spi_master *master,
  32859. + struct device *dev, struct bcm2708_spi_state *state,
  32860. + u32 hz, u8 csel, u8 mode, u8 bpw)
  32861. +{
  32862. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32863. + int cdiv;
  32864. + unsigned long bus_hz;
  32865. + u32 cs = 0;
  32866. +
  32867. + bus_hz = clk_get_rate(bs->clk);
  32868. +
  32869. + if (hz >= bus_hz) {
  32870. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  32871. + } else if (hz) {
  32872. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  32873. +
  32874. + /* CDIV must be a power of 2, so round up */
  32875. + cdiv = roundup_pow_of_two(cdiv);
  32876. +
  32877. + if (cdiv > 65536) {
  32878. + dev_dbg(dev,
  32879. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  32880. + hz, cdiv, bus_hz / 65536);
  32881. + return -EINVAL;
  32882. + } else if (cdiv == 65536) {
  32883. + cdiv = 0;
  32884. + } else if (cdiv == 1) {
  32885. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  32886. + }
  32887. + } else {
  32888. + cdiv = 0;
  32889. + }
  32890. +
  32891. + switch (bpw) {
  32892. + case 8:
  32893. + break;
  32894. + case 9:
  32895. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  32896. + cs |= SPI_CS_LEN;
  32897. + break;
  32898. + default:
  32899. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  32900. + bpw);
  32901. + return -EINVAL;
  32902. + }
  32903. +
  32904. + if (mode & SPI_CPOL)
  32905. + cs |= SPI_CS_CPOL;
  32906. + if (mode & SPI_CPHA)
  32907. + cs |= SPI_CS_CPHA;
  32908. +
  32909. + if (!(mode & SPI_NO_CS)) {
  32910. + if (mode & SPI_CS_HIGH) {
  32911. + cs |= SPI_CS_CSPOL;
  32912. + cs |= SPI_CS_CSPOL0 << csel;
  32913. + }
  32914. +
  32915. + cs |= csel;
  32916. + } else {
  32917. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  32918. + }
  32919. +
  32920. + if (state) {
  32921. + state->cs = cs;
  32922. + state->cdiv = cdiv;
  32923. + dev_dbg(dev, "setup: want %d Hz; "
  32924. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  32925. + "mode %u: cs 0x%08X\n",
  32926. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  32927. + }
  32928. +
  32929. + return 0;
  32930. +}
  32931. +
  32932. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  32933. + struct spi_message *msg, struct spi_transfer *xfer)
  32934. +{
  32935. + struct spi_device *spi = msg->spi;
  32936. + struct bcm2708_spi_state state, *stp;
  32937. + int ret;
  32938. + u32 cs;
  32939. +
  32940. + if (bs->stopping)
  32941. + return -ESHUTDOWN;
  32942. +
  32943. + if (xfer->bits_per_word || xfer->speed_hz) {
  32944. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  32945. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32946. + spi->chip_select, spi->mode,
  32947. + xfer->bits_per_word ? xfer->bits_per_word :
  32948. + spi->bits_per_word);
  32949. + if (ret)
  32950. + return ret;
  32951. +
  32952. + stp = &state;
  32953. + } else {
  32954. + stp = spi->controller_state;
  32955. + }
  32956. +
  32957. + INIT_COMPLETION(bs->done);
  32958. + bs->tx_buf = xfer->tx_buf;
  32959. + bs->rx_buf = xfer->rx_buf;
  32960. + bs->len = xfer->len;
  32961. +
  32962. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  32963. +
  32964. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  32965. + bcm2708_wr(bs, SPI_CS, cs);
  32966. +
  32967. + ret = wait_for_completion_timeout(&bs->done,
  32968. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  32969. + if (ret == 0) {
  32970. + dev_err(&spi->dev, "transfer timed out\n");
  32971. + return -ETIMEDOUT;
  32972. + }
  32973. +
  32974. + if (xfer->delay_usecs)
  32975. + udelay(xfer->delay_usecs);
  32976. +
  32977. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  32978. + xfer->cs_change) {
  32979. + /* clear TA and interrupt flags */
  32980. + bcm2708_wr(bs, SPI_CS, stp->cs);
  32981. + }
  32982. +
  32983. + msg->actual_length += (xfer->len - bs->len);
  32984. +
  32985. + return 0;
  32986. +}
  32987. +
  32988. +static void bcm2708_work(struct work_struct *work)
  32989. +{
  32990. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  32991. + unsigned long flags;
  32992. + struct spi_message *msg;
  32993. + struct spi_transfer *xfer;
  32994. + int status = 0;
  32995. +
  32996. + spin_lock_irqsave(&bs->lock, flags);
  32997. + while (!list_empty(&bs->queue)) {
  32998. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  32999. + list_del_init(&msg->queue);
  33000. + spin_unlock_irqrestore(&bs->lock, flags);
  33001. +
  33002. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33003. + status = bcm2708_process_transfer(bs, msg, xfer);
  33004. + if (status)
  33005. + break;
  33006. + }
  33007. +
  33008. + msg->status = status;
  33009. + msg->complete(msg->context);
  33010. +
  33011. + spin_lock_irqsave(&bs->lock, flags);
  33012. + }
  33013. + spin_unlock_irqrestore(&bs->lock, flags);
  33014. +}
  33015. +
  33016. +static int bcm2708_spi_setup(struct spi_device *spi)
  33017. +{
  33018. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33019. + struct bcm2708_spi_state *state;
  33020. + int ret;
  33021. +
  33022. + if (bs->stopping)
  33023. + return -ESHUTDOWN;
  33024. +
  33025. + if (!(spi->mode & SPI_NO_CS) &&
  33026. + (spi->chip_select > spi->master->num_chipselect)) {
  33027. + dev_dbg(&spi->dev,
  33028. + "setup: invalid chipselect %u (%u defined)\n",
  33029. + spi->chip_select, spi->master->num_chipselect);
  33030. + return -EINVAL;
  33031. + }
  33032. +
  33033. + state = spi->controller_state;
  33034. + if (!state) {
  33035. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  33036. + if (!state)
  33037. + return -ENOMEM;
  33038. +
  33039. + spi->controller_state = state;
  33040. + }
  33041. +
  33042. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  33043. + spi->max_speed_hz, spi->chip_select, spi->mode,
  33044. + spi->bits_per_word);
  33045. + if (ret < 0) {
  33046. + kfree(state);
  33047. + spi->controller_state = NULL;
  33048. + return ret;
  33049. + }
  33050. +
  33051. + dev_dbg(&spi->dev,
  33052. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  33053. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  33054. + spi->mode, state->cs, state->cdiv);
  33055. +
  33056. + return 0;
  33057. +}
  33058. +
  33059. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  33060. +{
  33061. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33062. + struct spi_transfer *xfer;
  33063. + int ret;
  33064. + unsigned long flags;
  33065. +
  33066. + if (unlikely(list_empty(&msg->transfers)))
  33067. + return -EINVAL;
  33068. +
  33069. + if (bs->stopping)
  33070. + return -ESHUTDOWN;
  33071. +
  33072. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33073. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  33074. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  33075. + return -EINVAL;
  33076. + }
  33077. +
  33078. + if (!xfer->bits_per_word || xfer->speed_hz)
  33079. + continue;
  33080. +
  33081. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  33082. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33083. + spi->chip_select, spi->mode,
  33084. + xfer->bits_per_word ? xfer->bits_per_word :
  33085. + spi->bits_per_word);
  33086. + if (ret)
  33087. + return ret;
  33088. + }
  33089. +
  33090. + msg->status = -EINPROGRESS;
  33091. + msg->actual_length = 0;
  33092. +
  33093. + spin_lock_irqsave(&bs->lock, flags);
  33094. + list_add_tail(&msg->queue, &bs->queue);
  33095. + queue_work(bs->workq, &bs->work);
  33096. + spin_unlock_irqrestore(&bs->lock, flags);
  33097. +
  33098. + return 0;
  33099. +}
  33100. +
  33101. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  33102. +{
  33103. + if (spi->controller_state) {
  33104. + kfree(spi->controller_state);
  33105. + spi->controller_state = NULL;
  33106. + }
  33107. +}
  33108. +
  33109. +static int bcm2708_spi_probe(struct platform_device *pdev)
  33110. +{
  33111. + struct resource *regs;
  33112. + int irq, err = -ENOMEM;
  33113. + struct clk *clk;
  33114. + struct spi_master *master;
  33115. + struct bcm2708_spi *bs;
  33116. +
  33117. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  33118. + if (!regs) {
  33119. + dev_err(&pdev->dev, "could not get IO memory\n");
  33120. + return -ENXIO;
  33121. + }
  33122. +
  33123. + irq = platform_get_irq(pdev, 0);
  33124. + if (irq < 0) {
  33125. + dev_err(&pdev->dev, "could not get IRQ\n");
  33126. + return irq;
  33127. + }
  33128. +
  33129. + clk = clk_get(&pdev->dev, NULL);
  33130. + if (IS_ERR(clk)) {
  33131. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  33132. + return PTR_ERR(clk);
  33133. + }
  33134. +
  33135. + bcm2708_init_pinmode();
  33136. +
  33137. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  33138. + if (!master) {
  33139. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  33140. + goto out_clk_put;
  33141. + }
  33142. +
  33143. + /* the spi->mode bits understood by this driver: */
  33144. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  33145. +
  33146. + master->bus_num = pdev->id;
  33147. + master->num_chipselect = 3;
  33148. + master->setup = bcm2708_spi_setup;
  33149. + master->transfer = bcm2708_spi_transfer;
  33150. + master->cleanup = bcm2708_spi_cleanup;
  33151. + platform_set_drvdata(pdev, master);
  33152. +
  33153. + bs = spi_master_get_devdata(master);
  33154. +
  33155. + spin_lock_init(&bs->lock);
  33156. + INIT_LIST_HEAD(&bs->queue);
  33157. + init_completion(&bs->done);
  33158. + INIT_WORK(&bs->work, bcm2708_work);
  33159. +
  33160. + bs->base = ioremap(regs->start, resource_size(regs));
  33161. + if (!bs->base) {
  33162. + dev_err(&pdev->dev, "could not remap memory\n");
  33163. + goto out_master_put;
  33164. + }
  33165. +
  33166. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  33167. + if (!bs->workq) {
  33168. + dev_err(&pdev->dev, "could not create workqueue\n");
  33169. + goto out_iounmap;
  33170. + }
  33171. +
  33172. + bs->irq = irq;
  33173. + bs->clk = clk;
  33174. + bs->stopping = false;
  33175. +
  33176. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  33177. + master);
  33178. + if (err) {
  33179. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  33180. + goto out_workqueue;
  33181. + }
  33182. +
  33183. + /* initialise the hardware */
  33184. + clk_enable(clk);
  33185. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33186. +
  33187. + err = spi_register_master(master);
  33188. + if (err) {
  33189. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  33190. + goto out_free_irq;
  33191. + }
  33192. +
  33193. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  33194. + (unsigned long)regs->start, irq);
  33195. +
  33196. + return 0;
  33197. +
  33198. +out_free_irq:
  33199. + free_irq(bs->irq, master);
  33200. +out_workqueue:
  33201. + destroy_workqueue(bs->workq);
  33202. +out_iounmap:
  33203. + iounmap(bs->base);
  33204. +out_master_put:
  33205. + spi_master_put(master);
  33206. +out_clk_put:
  33207. + clk_put(clk);
  33208. + return err;
  33209. +}
  33210. +
  33211. +static int bcm2708_spi_remove(struct platform_device *pdev)
  33212. +{
  33213. + struct spi_master *master = platform_get_drvdata(pdev);
  33214. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33215. +
  33216. + /* reset the hardware and block queue progress */
  33217. + spin_lock_irq(&bs->lock);
  33218. + bs->stopping = true;
  33219. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33220. + spin_unlock_irq(&bs->lock);
  33221. +
  33222. + flush_work_sync(&bs->work);
  33223. +
  33224. + clk_disable(bs->clk);
  33225. + clk_put(bs->clk);
  33226. + free_irq(bs->irq, master);
  33227. + iounmap(bs->base);
  33228. +
  33229. + spi_unregister_master(master);
  33230. +
  33231. + return 0;
  33232. +}
  33233. +
  33234. +static struct platform_driver bcm2708_spi_driver = {
  33235. + .driver = {
  33236. + .name = DRV_NAME,
  33237. + .owner = THIS_MODULE,
  33238. + },
  33239. + .probe = bcm2708_spi_probe,
  33240. + .remove = bcm2708_spi_remove,
  33241. +};
  33242. +
  33243. +
  33244. +static int __init bcm2708_spi_init(void)
  33245. +{
  33246. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  33247. +}
  33248. +module_init(bcm2708_spi_init);
  33249. +
  33250. +static void __exit bcm2708_spi_exit(void)
  33251. +{
  33252. + platform_driver_unregister(&bcm2708_spi_driver);
  33253. +}
  33254. +module_exit(bcm2708_spi_exit);
  33255. +
  33256. +
  33257. +//module_platform_driver(bcm2708_spi_driver);
  33258. +
  33259. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  33260. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  33261. +MODULE_LICENSE("GPL v2");
  33262. +MODULE_ALIAS("platform:" DRV_NAME);
  33263. diff -Nur linux-3.11.10.orig/drivers/staging/media/lirc/Kconfig linux-3.11.10/drivers/staging/media/lirc/Kconfig
  33264. --- linux-3.11.10.orig/drivers/staging/media/lirc/Kconfig 2013-11-29 19:42:37.000000000 +0100
  33265. +++ linux-3.11.10/drivers/staging/media/lirc/Kconfig 2014-02-07 19:57:29.000000000 +0100
  33266. @@ -38,6 +38,12 @@
  33267. help
  33268. Driver for Homebrew Parallel Port Receivers
  33269. +config LIRC_RPI
  33270. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  33271. + depends on LIRC
  33272. + help
  33273. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  33274. +
  33275. config LIRC_SASEM
  33276. tristate "Sasem USB IR Remote"
  33277. depends on LIRC && USB
  33278. diff -Nur linux-3.11.10.orig/drivers/staging/media/lirc/lirc_rpi.c linux-3.11.10/drivers/staging/media/lirc/lirc_rpi.c
  33279. --- linux-3.11.10.orig/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  33280. +++ linux-3.11.10/drivers/staging/media/lirc/lirc_rpi.c 2014-02-07 19:57:29.000000000 +0100
  33281. @@ -0,0 +1,692 @@
  33282. +/*
  33283. + * lirc_rpi.c
  33284. + *
  33285. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  33286. + * (space-lengths) (just like the lirc_serial driver does)
  33287. + * between GPIO interrupt events on the Raspberry Pi.
  33288. + * Lots of code has been taken from the lirc_serial module,
  33289. + * so I would like say thanks to the authors.
  33290. + *
  33291. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  33292. + * Michael Bishop <cleverca22@gmail.com>
  33293. + * This program is free software; you can redistribute it and/or modify
  33294. + * it under the terms of the GNU General Public License as published by
  33295. + * the Free Software Foundation; either version 2 of the License, or
  33296. + * (at your option) any later version.
  33297. + *
  33298. + * This program is distributed in the hope that it will be useful,
  33299. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33300. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33301. + * GNU General Public License for more details.
  33302. + *
  33303. + * You should have received a copy of the GNU General Public License
  33304. + * along with this program; if not, write to the Free Software
  33305. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33306. + */
  33307. +
  33308. +#include <linux/module.h>
  33309. +#include <linux/errno.h>
  33310. +#include <linux/interrupt.h>
  33311. +#include <linux/sched.h>
  33312. +#include <linux/kernel.h>
  33313. +#include <linux/time.h>
  33314. +#include <linux/string.h>
  33315. +#include <linux/delay.h>
  33316. +#include <linux/platform_device.h>
  33317. +#include <linux/irq.h>
  33318. +#include <linux/spinlock.h>
  33319. +#include <media/lirc.h>
  33320. +#include <media/lirc_dev.h>
  33321. +#include <linux/gpio.h>
  33322. +
  33323. +#define LIRC_DRIVER_NAME "lirc_rpi"
  33324. +#define RBUF_LEN 256
  33325. +#define LIRC_TRANSMITTER_LATENCY 256
  33326. +
  33327. +#ifndef MAX_UDELAY_MS
  33328. +#define MAX_UDELAY_US 5000
  33329. +#else
  33330. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  33331. +#endif
  33332. +
  33333. +#define dprintk(fmt, args...) \
  33334. + do { \
  33335. + if (debug) \
  33336. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  33337. + fmt, ## args); \
  33338. + } while (0)
  33339. +
  33340. +/* module parameters */
  33341. +
  33342. +/* set the default GPIO input pin */
  33343. +static int gpio_in_pin = 18;
  33344. +/* set the default GPIO output pin */
  33345. +static int gpio_out_pin = 17;
  33346. +/* enable debugging messages */
  33347. +static int debug;
  33348. +/* -1 = auto, 0 = active high, 1 = active low */
  33349. +static int sense = -1;
  33350. +/* use softcarrier by default */
  33351. +static int softcarrier = 1;
  33352. +/* 0 = do not invert output, 1 = invert output */
  33353. +static int invert = 0;
  33354. +
  33355. +struct gpio_chip *gpiochip;
  33356. +struct irq_chip *irqchip;
  33357. +struct irq_data *irqdata;
  33358. +
  33359. +/* forward declarations */
  33360. +static long send_pulse(unsigned long length);
  33361. +static void send_space(long length);
  33362. +static void lirc_rpi_exit(void);
  33363. +
  33364. +int valid_gpio_pins[] = { 0, 1, 4, 8, 7, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23,
  33365. + 24, 25 };
  33366. +
  33367. +static struct platform_device *lirc_rpi_dev;
  33368. +static struct timeval lasttv = { 0, 0 };
  33369. +static struct lirc_buffer rbuf;
  33370. +static spinlock_t lock;
  33371. +
  33372. +/* initialized/set in init_timing_params() */
  33373. +static unsigned int freq = 38000;
  33374. +static unsigned int duty_cycle = 50;
  33375. +static unsigned long period;
  33376. +static unsigned long pulse_width;
  33377. +static unsigned long space_width;
  33378. +
  33379. +static void safe_udelay(unsigned long usecs)
  33380. +{
  33381. + while (usecs > MAX_UDELAY_US) {
  33382. + udelay(MAX_UDELAY_US);
  33383. + usecs -= MAX_UDELAY_US;
  33384. + }
  33385. + udelay(usecs);
  33386. +}
  33387. +
  33388. +static int init_timing_params(unsigned int new_duty_cycle,
  33389. + unsigned int new_freq)
  33390. +{
  33391. + /*
  33392. + * period, pulse/space width are kept with 8 binary places -
  33393. + * IE multiplied by 256.
  33394. + */
  33395. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  33396. + LIRC_TRANSMITTER_LATENCY)
  33397. + return -EINVAL;
  33398. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  33399. + LIRC_TRANSMITTER_LATENCY)
  33400. + return -EINVAL;
  33401. + duty_cycle = new_duty_cycle;
  33402. + freq = new_freq;
  33403. + period = 256 * 1000000L / freq;
  33404. + pulse_width = period * duty_cycle / 100;
  33405. + space_width = period - pulse_width;
  33406. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  33407. + "space=%ld\n", freq, pulse_width, space_width);
  33408. + return 0;
  33409. +}
  33410. +
  33411. +static long send_pulse_softcarrier(unsigned long length)
  33412. +{
  33413. + int flag;
  33414. + unsigned long actual, target, d;
  33415. +
  33416. + length <<= 8;
  33417. +
  33418. + actual = 0; target = 0; flag = 0;
  33419. + while (actual < length) {
  33420. + if (flag) {
  33421. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33422. + target += space_width;
  33423. + } else {
  33424. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33425. + target += pulse_width;
  33426. + }
  33427. + d = (target - actual -
  33428. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  33429. + /*
  33430. + * Note - we've checked in ioctl that the pulse/space
  33431. + * widths are big enough so that d is > 0
  33432. + */
  33433. + udelay(d);
  33434. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  33435. + flag = !flag;
  33436. + }
  33437. + return (actual-length) >> 8;
  33438. +}
  33439. +
  33440. +static long send_pulse(unsigned long length)
  33441. +{
  33442. + if (length <= 0)
  33443. + return 0;
  33444. +
  33445. + if (softcarrier) {
  33446. + return send_pulse_softcarrier(length);
  33447. + } else {
  33448. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33449. + safe_udelay(length);
  33450. + return 0;
  33451. + }
  33452. +}
  33453. +
  33454. +static void send_space(long length)
  33455. +{
  33456. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33457. + if (length <= 0)
  33458. + return;
  33459. + safe_udelay(length);
  33460. +}
  33461. +
  33462. +static void rbwrite(int l)
  33463. +{
  33464. + if (lirc_buffer_full(&rbuf)) {
  33465. + /* no new signals will be accepted */
  33466. + dprintk("Buffer overrun\n");
  33467. + return;
  33468. + }
  33469. + lirc_buffer_write(&rbuf, (void *)&l);
  33470. +}
  33471. +
  33472. +static void frbwrite(int l)
  33473. +{
  33474. + /* simple noise filter */
  33475. + static int pulse, space;
  33476. + static unsigned int ptr;
  33477. +
  33478. + if (ptr > 0 && (l & PULSE_BIT)) {
  33479. + pulse += l & PULSE_MASK;
  33480. + if (pulse > 250) {
  33481. + rbwrite(space);
  33482. + rbwrite(pulse | PULSE_BIT);
  33483. + ptr = 0;
  33484. + pulse = 0;
  33485. + }
  33486. + return;
  33487. + }
  33488. + if (!(l & PULSE_BIT)) {
  33489. + if (ptr == 0) {
  33490. + if (l > 20000) {
  33491. + space = l;
  33492. + ptr++;
  33493. + return;
  33494. + }
  33495. + } else {
  33496. + if (l > 20000) {
  33497. + space += pulse;
  33498. + if (space > PULSE_MASK)
  33499. + space = PULSE_MASK;
  33500. + space += l;
  33501. + if (space > PULSE_MASK)
  33502. + space = PULSE_MASK;
  33503. + pulse = 0;
  33504. + return;
  33505. + }
  33506. + rbwrite(space);
  33507. + rbwrite(pulse | PULSE_BIT);
  33508. + ptr = 0;
  33509. + pulse = 0;
  33510. + }
  33511. + }
  33512. + rbwrite(l);
  33513. +}
  33514. +
  33515. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  33516. +{
  33517. + struct timeval tv;
  33518. + long deltv;
  33519. + int data;
  33520. + int signal;
  33521. +
  33522. + /* use the GPIO signal level */
  33523. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  33524. +
  33525. + /* unmask the irq */
  33526. + irqchip->irq_unmask(irqdata);
  33527. +
  33528. + if (sense != -1) {
  33529. + /* get current time */
  33530. + do_gettimeofday(&tv);
  33531. +
  33532. + /* calc time since last interrupt in microseconds */
  33533. + deltv = tv.tv_sec-lasttv.tv_sec;
  33534. + if (tv.tv_sec < lasttv.tv_sec ||
  33535. + (tv.tv_sec == lasttv.tv_sec &&
  33536. + tv.tv_usec < lasttv.tv_usec)) {
  33537. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33538. + ": AIEEEE: your clock just jumped backwards\n");
  33539. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33540. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  33541. + tv.tv_sec, lasttv.tv_sec,
  33542. + tv.tv_usec, lasttv.tv_usec);
  33543. + data = PULSE_MASK;
  33544. + } else if (deltv > 15) {
  33545. + data = PULSE_MASK; /* really long time */
  33546. + if (!(signal^sense)) {
  33547. + /* sanity check */
  33548. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33549. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  33550. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  33551. + tv.tv_usec, lasttv.tv_usec);
  33552. + /*
  33553. + * detecting pulse while this
  33554. + * MUST be a space!
  33555. + */
  33556. + sense = sense ? 0 : 1;
  33557. + }
  33558. + } else {
  33559. + data = (int) (deltv*1000000 +
  33560. + (tv.tv_usec - lasttv.tv_usec));
  33561. + }
  33562. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  33563. + lasttv = tv;
  33564. + wake_up_interruptible(&rbuf.wait_poll);
  33565. + }
  33566. +
  33567. + return IRQ_HANDLED;
  33568. +}
  33569. +
  33570. +static int is_right_chip(struct gpio_chip *chip, void *data)
  33571. +{
  33572. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  33573. +
  33574. + if (strcmp(data, chip->label) == 0)
  33575. + return 1;
  33576. + return 0;
  33577. +}
  33578. +
  33579. +static int init_port(void)
  33580. +{
  33581. + int i, nlow, nhigh, ret, irq;
  33582. +
  33583. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  33584. +
  33585. + if (!gpiochip)
  33586. + return -ENODEV;
  33587. +
  33588. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  33589. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33590. + ": cant claim gpio pin %d\n", gpio_out_pin);
  33591. + ret = -ENODEV;
  33592. + goto exit_init_port;
  33593. + }
  33594. +
  33595. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  33596. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33597. + ": cant claim gpio pin %d\n", gpio_in_pin);
  33598. + ret = -ENODEV;
  33599. + goto exit_gpio_free_out_pin;
  33600. + }
  33601. +
  33602. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  33603. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  33604. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33605. +
  33606. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  33607. + dprintk("to_irq %d\n", irq);
  33608. + irqdata = irq_get_irq_data(irq);
  33609. +
  33610. + if (irqdata && irqdata->chip) {
  33611. + irqchip = irqdata->chip;
  33612. + } else {
  33613. + ret = -ENODEV;
  33614. + goto exit_gpio_free_in_pin;
  33615. + }
  33616. +
  33617. + /* if pin is high, then this must be an active low receiver. */
  33618. + if (sense == -1) {
  33619. + /* wait 1/2 sec for the power supply */
  33620. + msleep(500);
  33621. +
  33622. + /*
  33623. + * probe 9 times every 0.04s, collect "votes" for
  33624. + * active high/low
  33625. + */
  33626. + nlow = 0;
  33627. + nhigh = 0;
  33628. + for (i = 0; i < 9; i++) {
  33629. + if (gpiochip->get(gpiochip, gpio_in_pin))
  33630. + nlow++;
  33631. + else
  33632. + nhigh++;
  33633. + msleep(40);
  33634. + }
  33635. + sense = (nlow >= nhigh ? 1 : 0);
  33636. + printk(KERN_INFO LIRC_DRIVER_NAME
  33637. + ": auto-detected active %s receiver on GPIO pin %d\n",
  33638. + sense ? "low" : "high", gpio_in_pin);
  33639. + } else {
  33640. + printk(KERN_INFO LIRC_DRIVER_NAME
  33641. + ": manually using active %s receiver on GPIO pin %d\n",
  33642. + sense ? "low" : "high", gpio_in_pin);
  33643. + }
  33644. +
  33645. + return 0;
  33646. +
  33647. + exit_gpio_free_in_pin:
  33648. + gpio_free(gpio_in_pin);
  33649. +
  33650. + exit_gpio_free_out_pin:
  33651. + gpio_free(gpio_out_pin);
  33652. +
  33653. + exit_init_port:
  33654. + return ret;
  33655. +}
  33656. +
  33657. +// called when the character device is opened
  33658. +static int set_use_inc(void *data)
  33659. +{
  33660. + int result;
  33661. + unsigned long flags;
  33662. +
  33663. + /* initialize timestamp */
  33664. + do_gettimeofday(&lasttv);
  33665. +
  33666. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  33667. + (irq_handler_t) irq_handler, 0,
  33668. + LIRC_DRIVER_NAME, (void*) 0);
  33669. +
  33670. + switch (result) {
  33671. + case -EBUSY:
  33672. + printk(KERN_ERR LIRC_DRIVER_NAME
  33673. + ": IRQ %d is busy\n",
  33674. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33675. + return -EBUSY;
  33676. + case -EINVAL:
  33677. + printk(KERN_ERR LIRC_DRIVER_NAME
  33678. + ": Bad irq number or handler\n");
  33679. + return -EINVAL;
  33680. + default:
  33681. + dprintk("Interrupt %d obtained\n",
  33682. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33683. + break;
  33684. + };
  33685. +
  33686. + /* initialize pulse/space widths */
  33687. + init_timing_params(duty_cycle, freq);
  33688. +
  33689. + spin_lock_irqsave(&lock, flags);
  33690. +
  33691. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  33692. + irqchip->irq_set_type(irqdata,
  33693. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  33694. +
  33695. + /* unmask the irq */
  33696. + irqchip->irq_unmask(irqdata);
  33697. +
  33698. + spin_unlock_irqrestore(&lock, flags);
  33699. +
  33700. + return 0;
  33701. +}
  33702. +
  33703. +static void set_use_dec(void *data)
  33704. +{
  33705. + unsigned long flags;
  33706. +
  33707. + spin_lock_irqsave(&lock, flags);
  33708. +
  33709. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  33710. + irqchip->irq_set_type(irqdata, 0);
  33711. + irqchip->irq_mask(irqdata);
  33712. +
  33713. + spin_unlock_irqrestore(&lock, flags);
  33714. +
  33715. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  33716. +
  33717. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  33718. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  33719. +}
  33720. +
  33721. +static ssize_t lirc_write(struct file *file, const char *buf,
  33722. + size_t n, loff_t *ppos)
  33723. +{
  33724. + int i, count;
  33725. + unsigned long flags;
  33726. + long delta = 0;
  33727. + int *wbuf;
  33728. +
  33729. + count = n / sizeof(int);
  33730. + if (n % sizeof(int) || count % 2 == 0)
  33731. + return -EINVAL;
  33732. + wbuf = memdup_user(buf, n);
  33733. + if (IS_ERR(wbuf))
  33734. + return PTR_ERR(wbuf);
  33735. + spin_lock_irqsave(&lock, flags);
  33736. +
  33737. + for (i = 0; i < count; i++) {
  33738. + if (i%2)
  33739. + send_space(wbuf[i] - delta);
  33740. + else
  33741. + delta = send_pulse(wbuf[i]);
  33742. + }
  33743. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33744. +
  33745. + spin_unlock_irqrestore(&lock, flags);
  33746. + kfree(wbuf);
  33747. + return n;
  33748. +}
  33749. +
  33750. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  33751. +{
  33752. + int result;
  33753. + __u32 value;
  33754. +
  33755. + switch (cmd) {
  33756. + case LIRC_GET_SEND_MODE:
  33757. + return -ENOIOCTLCMD;
  33758. + break;
  33759. +
  33760. + case LIRC_SET_SEND_MODE:
  33761. + result = get_user(value, (__u32 *) arg);
  33762. + if (result)
  33763. + return result;
  33764. + /* only LIRC_MODE_PULSE supported */
  33765. + if (value != LIRC_MODE_PULSE)
  33766. + return -ENOSYS;
  33767. + break;
  33768. +
  33769. + case LIRC_GET_LENGTH:
  33770. + return -ENOSYS;
  33771. + break;
  33772. +
  33773. + case LIRC_SET_SEND_DUTY_CYCLE:
  33774. + dprintk("SET_SEND_DUTY_CYCLE\n");
  33775. + result = get_user(value, (__u32 *) arg);
  33776. + if (result)
  33777. + return result;
  33778. + if (value <= 0 || value > 100)
  33779. + return -EINVAL;
  33780. + return init_timing_params(value, freq);
  33781. + break;
  33782. +
  33783. + case LIRC_SET_SEND_CARRIER:
  33784. + dprintk("SET_SEND_CARRIER\n");
  33785. + result = get_user(value, (__u32 *) arg);
  33786. + if (result)
  33787. + return result;
  33788. + if (value > 500000 || value < 20000)
  33789. + return -EINVAL;
  33790. + return init_timing_params(duty_cycle, value);
  33791. + break;
  33792. +
  33793. + default:
  33794. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  33795. + }
  33796. + return 0;
  33797. +}
  33798. +
  33799. +static const struct file_operations lirc_fops = {
  33800. + .owner = THIS_MODULE,
  33801. + .write = lirc_write,
  33802. + .unlocked_ioctl = lirc_ioctl,
  33803. + .read = lirc_dev_fop_read,
  33804. + .poll = lirc_dev_fop_poll,
  33805. + .open = lirc_dev_fop_open,
  33806. + .release = lirc_dev_fop_close,
  33807. + .llseek = no_llseek,
  33808. +};
  33809. +
  33810. +static struct lirc_driver driver = {
  33811. + .name = LIRC_DRIVER_NAME,
  33812. + .minor = -1,
  33813. + .code_length = 1,
  33814. + .sample_rate = 0,
  33815. + .data = NULL,
  33816. + .add_to_buf = NULL,
  33817. + .rbuf = &rbuf,
  33818. + .set_use_inc = set_use_inc,
  33819. + .set_use_dec = set_use_dec,
  33820. + .fops = &lirc_fops,
  33821. + .dev = NULL,
  33822. + .owner = THIS_MODULE,
  33823. +};
  33824. +
  33825. +static struct platform_driver lirc_rpi_driver = {
  33826. + .driver = {
  33827. + .name = LIRC_DRIVER_NAME,
  33828. + .owner = THIS_MODULE,
  33829. + },
  33830. +};
  33831. +
  33832. +static int __init lirc_rpi_init(void)
  33833. +{
  33834. + int result;
  33835. +
  33836. + /* Init read buffer. */
  33837. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  33838. + if (result < 0)
  33839. + return -ENOMEM;
  33840. +
  33841. + result = platform_driver_register(&lirc_rpi_driver);
  33842. + if (result) {
  33843. + printk(KERN_ERR LIRC_DRIVER_NAME
  33844. + ": lirc register returned %d\n", result);
  33845. + goto exit_buffer_free;
  33846. + }
  33847. +
  33848. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  33849. + if (!lirc_rpi_dev) {
  33850. + result = -ENOMEM;
  33851. + goto exit_driver_unregister;
  33852. + }
  33853. +
  33854. + result = platform_device_add(lirc_rpi_dev);
  33855. + if (result)
  33856. + goto exit_device_put;
  33857. +
  33858. + return 0;
  33859. +
  33860. + exit_device_put:
  33861. + platform_device_put(lirc_rpi_dev);
  33862. +
  33863. + exit_driver_unregister:
  33864. + platform_driver_unregister(&lirc_rpi_driver);
  33865. +
  33866. + exit_buffer_free:
  33867. + lirc_buffer_free(&rbuf);
  33868. +
  33869. + return result;
  33870. +}
  33871. +
  33872. +static void lirc_rpi_exit(void)
  33873. +{
  33874. + gpio_free(gpio_out_pin);
  33875. + gpio_free(gpio_in_pin);
  33876. + platform_device_unregister(lirc_rpi_dev);
  33877. + platform_driver_unregister(&lirc_rpi_driver);
  33878. + lirc_buffer_free(&rbuf);
  33879. +}
  33880. +
  33881. +static int __init lirc_rpi_init_module(void)
  33882. +{
  33883. + int result, i;
  33884. +
  33885. + result = lirc_rpi_init();
  33886. + if (result)
  33887. + return result;
  33888. +
  33889. + /* check if the module received valid gpio pin numbers */
  33890. + result = 0;
  33891. + if (gpio_in_pin != gpio_out_pin) {
  33892. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  33893. + if (gpio_in_pin == valid_gpio_pins[i] ||
  33894. + gpio_out_pin == valid_gpio_pins[i]) {
  33895. + result++;
  33896. + }
  33897. + }
  33898. + }
  33899. +
  33900. + if (result != 2) {
  33901. + result = -EINVAL;
  33902. + printk(KERN_ERR LIRC_DRIVER_NAME
  33903. + ": invalid GPIO pin(s) specified!\n");
  33904. + goto exit_rpi;
  33905. + }
  33906. +
  33907. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  33908. + LIRC_CAN_SET_SEND_CARRIER |
  33909. + LIRC_CAN_SEND_PULSE |
  33910. + LIRC_CAN_REC_MODE2;
  33911. +
  33912. + driver.dev = &lirc_rpi_dev->dev;
  33913. + driver.minor = lirc_register_driver(&driver);
  33914. +
  33915. + if (driver.minor < 0) {
  33916. + printk(KERN_ERR LIRC_DRIVER_NAME
  33917. + ": device registration failed with %d\n", result);
  33918. + result = -EIO;
  33919. + goto exit_rpi;
  33920. + }
  33921. +
  33922. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  33923. +
  33924. + result = init_port();
  33925. + if (result < 0)
  33926. + goto exit_rpi;
  33927. +
  33928. + return 0;
  33929. +
  33930. + exit_rpi:
  33931. + lirc_rpi_exit();
  33932. +
  33933. + return result;
  33934. +}
  33935. +
  33936. +static void __exit lirc_rpi_exit_module(void)
  33937. +{
  33938. + lirc_rpi_exit();
  33939. +
  33940. + lirc_unregister_driver(driver.minor);
  33941. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  33942. +}
  33943. +
  33944. +module_init(lirc_rpi_init_module);
  33945. +module_exit(lirc_rpi_exit_module);
  33946. +
  33947. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  33948. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  33949. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  33950. +MODULE_LICENSE("GPL");
  33951. +
  33952. +module_param(gpio_out_pin, int, S_IRUGO);
  33953. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  33954. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  33955. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  33956. +
  33957. +module_param(gpio_in_pin, int, S_IRUGO);
  33958. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  33959. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  33960. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  33961. +
  33962. +module_param(sense, bool, S_IRUGO);
  33963. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  33964. + " (0 = active high, 1 = active low )");
  33965. +
  33966. +module_param(softcarrier, bool, S_IRUGO);
  33967. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  33968. +
  33969. +module_param(invert, bool, S_IRUGO);
  33970. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  33971. +
  33972. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  33973. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  33974. diff -Nur linux-3.11.10.orig/drivers/staging/media/lirc/Makefile linux-3.11.10/drivers/staging/media/lirc/Makefile
  33975. --- linux-3.11.10.orig/drivers/staging/media/lirc/Makefile 2013-11-29 19:42:37.000000000 +0100
  33976. +++ linux-3.11.10/drivers/staging/media/lirc/Makefile 2014-02-07 19:57:29.000000000 +0100
  33977. @@ -7,6 +7,7 @@
  33978. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  33979. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  33980. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  33981. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  33982. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  33983. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  33984. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  33985. diff -Nur linux-3.11.10.orig/drivers/thermal/bcm2835-thermal.c linux-3.11.10/drivers/thermal/bcm2835-thermal.c
  33986. --- linux-3.11.10.orig/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  33987. +++ linux-3.11.10/drivers/thermal/bcm2835-thermal.c 2014-02-07 19:57:29.000000000 +0100
  33988. @@ -0,0 +1,184 @@
  33989. +/*****************************************************************************
  33990. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  33991. +*
  33992. +* Unless you and Broadcom execute a separate written software license
  33993. +* agreement governing use of this software, this software is licensed to you
  33994. +* under the terms of the GNU General Public License version 2, available at
  33995. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  33996. +*
  33997. +* Notwithstanding the above, under no circumstances may you combine this
  33998. +* software in any way with any other Broadcom software provided under a
  33999. +* license other than the GPL, without Broadcom's express prior written
  34000. +* consent.
  34001. +*****************************************************************************/
  34002. +
  34003. +#include <linux/kernel.h>
  34004. +#include <linux/module.h>
  34005. +#include <linux/init.h>
  34006. +#include <linux/platform_device.h>
  34007. +#include <linux/slab.h>
  34008. +#include <linux/sysfs.h>
  34009. +#include <mach/vcio.h>
  34010. +#include <linux/thermal.h>
  34011. +
  34012. +
  34013. +/* --- DEFINITIONS --- */
  34014. +#define MODULE_NAME "bcm2835_thermal"
  34015. +
  34016. +/*#define THERMAL_DEBUG_ENABLE*/
  34017. +
  34018. +#ifdef THERMAL_DEBUG_ENABLE
  34019. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  34020. +#else
  34021. +#define print_debug(fmt,...)
  34022. +#endif
  34023. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  34024. +
  34025. +#define VC_TAG_GET_TEMP 0x00030006
  34026. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  34027. +
  34028. +typedef enum {
  34029. + TEMP,
  34030. + MAX_TEMP,
  34031. +} temp_type;
  34032. +
  34033. +/* --- STRUCTS --- */
  34034. +/* tag part of the message */
  34035. +struct vc_msg_tag {
  34036. + uint32_t tag_id; /* the tag ID for the temperature */
  34037. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  34038. + uint32_t request_code; /* identifies message as a request (should be 0) */
  34039. + uint32_t id; /* extra ID field (should be 0) */
  34040. + uint32_t val; /* returned value of the temperature */
  34041. +};
  34042. +
  34043. +/* message structure to be sent to videocore */
  34044. +struct vc_msg {
  34045. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  34046. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  34047. + struct vc_msg_tag tag; /* the tag structure above to make */
  34048. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  34049. +};
  34050. +
  34051. +struct bcm2835_thermal_data {
  34052. + struct thermal_zone_device *thermal_dev;
  34053. + struct vc_msg msg;
  34054. +};
  34055. +
  34056. +/* --- GLOBALS --- */
  34057. +static struct bcm2835_thermal_data bcm2835_data;
  34058. +
  34059. +/* Thermal Device Operations */
  34060. +static struct thermal_zone_device_ops ops;
  34061. +
  34062. +/* --- FUNCTIONS --- */
  34063. +
  34064. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  34065. +{
  34066. + int result = -1, retry = 3;
  34067. + print_debug("IN");
  34068. +
  34069. + *temp = 0;
  34070. + while (result != 0 && retry-- > 0) {
  34071. + /* wipe all previous message data */
  34072. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  34073. +
  34074. + /* prepare message */
  34075. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  34076. + bcm2835_data.msg.tag.buffer_size = 8;
  34077. + bcm2835_data.msg.tag.tag_id = tag_id;
  34078. +
  34079. + /* send the message */
  34080. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  34081. + print_debug("Got %stemperature as %u (%d,%x)\n", tag_id==VC_TAG_GET_MAX_TEMP ? "max ":"", (uint)bcm2835_data.msg.tag.val, result, bcm2835_data.msg.request_code);
  34082. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  34083. + result = -1;
  34084. + }
  34085. +
  34086. + /* check if it was all ok and return the rate in milli degrees C */
  34087. + if (result == 0)
  34088. + *temp = (uint)bcm2835_data.msg.tag.val;
  34089. + else
  34090. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  34091. + print_debug("OUT");
  34092. + return result;
  34093. +}
  34094. +
  34095. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  34096. +{
  34097. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  34098. +}
  34099. +
  34100. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  34101. +{
  34102. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  34103. +}
  34104. +
  34105. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  34106. +{
  34107. + *trip_type = THERMAL_TRIP_HOT;
  34108. + return 0;
  34109. +}
  34110. +
  34111. +
  34112. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  34113. +{
  34114. + *dev_mode = THERMAL_DEVICE_ENABLED;
  34115. + return 0;
  34116. +}
  34117. +
  34118. +
  34119. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  34120. +{
  34121. + print_debug("IN");
  34122. + print_debug("THERMAL Driver has been probed!");
  34123. +
  34124. + /* check that the device isn't null!*/
  34125. + if(pdev == NULL)
  34126. + {
  34127. + print_debug("Platform device is empty!");
  34128. + return -ENODEV;
  34129. + }
  34130. +
  34131. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  34132. + {
  34133. + print_debug("Unable to register the thermal device!");
  34134. + return -EFAULT;
  34135. + }
  34136. + return 0;
  34137. +}
  34138. +
  34139. +
  34140. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  34141. +{
  34142. + print_debug("IN");
  34143. +
  34144. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  34145. +
  34146. + print_debug("OUT");
  34147. +
  34148. + return 0;
  34149. +}
  34150. +
  34151. +static struct thermal_zone_device_ops ops = {
  34152. + .get_temp = bcm2835_get_temp,
  34153. + .get_trip_temp = bcm2835_get_max_temp,
  34154. + .get_trip_type = bcm2835_get_trip_type,
  34155. + .get_mode = bcm2835_get_mode,
  34156. +};
  34157. +
  34158. +/* Thermal Driver */
  34159. +static struct platform_driver bcm2835_thermal_driver = {
  34160. + .probe = bcm2835_thermal_probe,
  34161. + .remove = bcm2835_thermal_remove,
  34162. + .driver = {
  34163. + .name = "bcm2835_thermal",
  34164. + .owner = THIS_MODULE,
  34165. + },
  34166. +};
  34167. +
  34168. +MODULE_LICENSE("GPL");
  34169. +MODULE_AUTHOR("Dorian Peake");
  34170. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  34171. +
  34172. +module_platform_driver(bcm2835_thermal_driver);
  34173. diff -Nur linux-3.11.10.orig/drivers/thermal/Kconfig linux-3.11.10/drivers/thermal/Kconfig
  34174. --- linux-3.11.10.orig/drivers/thermal/Kconfig 2013-11-29 19:42:37.000000000 +0100
  34175. +++ linux-3.11.10/drivers/thermal/Kconfig 2014-02-07 19:57:29.000000000 +0100
  34176. @@ -169,6 +169,12 @@
  34177. enforce idle time which results in more package C-state residency. The
  34178. user interface is exposed via generic thermal framework.
  34179. +config THERMAL_BCM2835
  34180. + tristate "BCM2835 Thermal Driver"
  34181. + help
  34182. + This will enable temperature monitoring for the Broadcom BCM2835
  34183. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  34184. +
  34185. config X86_PKG_TEMP_THERMAL
  34186. tristate "X86 package temperature thermal driver"
  34187. depends on X86_THERMAL_VECTOR
  34188. diff -Nur linux-3.11.10.orig/drivers/thermal/Makefile linux-3.11.10/drivers/thermal/Makefile
  34189. --- linux-3.11.10.orig/drivers/thermal/Makefile 2013-11-29 19:42:37.000000000 +0100
  34190. +++ linux-3.11.10/drivers/thermal/Makefile 2014-02-07 19:57:29.000000000 +0100
  34191. @@ -23,5 +23,6 @@
  34192. obj-$(CONFIG_ARMADA_THERMAL) += armada_thermal.o
  34193. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  34194. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  34195. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  34196. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  34197. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  34198. diff -Nur linux-3.11.10.orig/drivers/tty/serial/amba-pl011.c linux-3.11.10/drivers/tty/serial/amba-pl011.c
  34199. --- linux-3.11.10.orig/drivers/tty/serial/amba-pl011.c 2013-11-29 19:42:37.000000000 +0100
  34200. +++ linux-3.11.10/drivers/tty/serial/amba-pl011.c 2014-02-07 19:57:29.000000000 +0100
  34201. @@ -84,7 +84,7 @@
  34202. static unsigned int get_fifosize_arm(struct amba_device *dev)
  34203. {
  34204. - return amba_rev(dev) < 3 ? 16 : 32;
  34205. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  34206. }
  34207. static struct vendor_data vendor_arm = {
  34208. diff -Nur linux-3.11.10.orig/drivers/usb/core/generic.c linux-3.11.10/drivers/usb/core/generic.c
  34209. --- linux-3.11.10.orig/drivers/usb/core/generic.c 2013-11-29 19:42:37.000000000 +0100
  34210. +++ linux-3.11.10/drivers/usb/core/generic.c 2014-02-07 19:57:30.000000000 +0100
  34211. @@ -152,6 +152,7 @@
  34212. dev_warn(&udev->dev,
  34213. "no configuration chosen from %d choice%s\n",
  34214. num_configs, plural(num_configs));
  34215. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  34216. }
  34217. return i;
  34218. }
  34219. diff -Nur linux-3.11.10.orig/drivers/usb/core/message.c linux-3.11.10/drivers/usb/core/message.c
  34220. --- linux-3.11.10.orig/drivers/usb/core/message.c 2013-11-29 19:42:37.000000000 +0100
  34221. +++ linux-3.11.10/drivers/usb/core/message.c 2014-02-07 19:57:30.000000000 +0100
  34222. @@ -1875,6 +1875,85 @@
  34223. if (cp->string == NULL &&
  34224. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  34225. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  34226. +/* Uncomment this define to enable the HS Electrical Test support */
  34227. +#define DWC_HS_ELECT_TST 1
  34228. +#ifdef DWC_HS_ELECT_TST
  34229. + /* Here we implement the HS Electrical Test support. The
  34230. + * tester uses a vendor ID of 0x1A0A to indicate we should
  34231. + * run a special test sequence. The product ID tells us
  34232. + * which sequence to run. We invoke the test sequence by
  34233. + * sending a non-standard SetFeature command to our root
  34234. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  34235. + * recognize the command and perform the desired test
  34236. + * sequence.
  34237. + */
  34238. + if (dev->descriptor.idVendor == 0x1A0A) {
  34239. + /* HSOTG Electrical Test */
  34240. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  34241. +
  34242. + if (dev->bus && dev->bus->root_hub) {
  34243. + struct usb_device *hdev = dev->bus->root_hub;
  34244. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  34245. +
  34246. + switch (dev->descriptor.idProduct) {
  34247. + case 0x0101: /* TEST_SE0_NAK */
  34248. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  34249. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34250. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34251. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  34252. + break;
  34253. +
  34254. + case 0x0102: /* TEST_J */
  34255. + dev_warn(&dev->dev, "TEST_J\n");
  34256. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34257. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34258. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  34259. + break;
  34260. +
  34261. + case 0x0103: /* TEST_K */
  34262. + dev_warn(&dev->dev, "TEST_K\n");
  34263. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34264. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34265. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  34266. + break;
  34267. +
  34268. + case 0x0104: /* TEST_PACKET */
  34269. + dev_warn(&dev->dev, "TEST_PACKET\n");
  34270. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34271. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34272. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  34273. + break;
  34274. +
  34275. + case 0x0105: /* TEST_FORCE_ENABLE */
  34276. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  34277. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34278. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34279. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  34280. + break;
  34281. +
  34282. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  34283. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  34284. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34285. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34286. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  34287. + break;
  34288. +
  34289. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  34290. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  34291. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34292. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34293. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  34294. + break;
  34295. +
  34296. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  34297. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  34298. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34299. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34300. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  34301. + }
  34302. + }
  34303. + }
  34304. +#endif /* DWC_HS_ELECT_TST */
  34305. /* Now that the interfaces are installed, re-enable LPM. */
  34306. usb_unlocked_enable_lpm(dev);
  34307. diff -Nur linux-3.11.10.orig/drivers/usb/core/otg_whitelist.h linux-3.11.10/drivers/usb/core/otg_whitelist.h
  34308. --- linux-3.11.10.orig/drivers/usb/core/otg_whitelist.h 2013-11-29 19:42:37.000000000 +0100
  34309. +++ linux-3.11.10/drivers/usb/core/otg_whitelist.h 2014-02-07 19:57:30.000000000 +0100
  34310. @@ -19,33 +19,82 @@
  34311. static struct usb_device_id whitelist_table [] = {
  34312. /* hubs are optional in OTG, but very handy ... */
  34313. +#define CERT_WITHOUT_HUBS
  34314. +#if defined(CERT_WITHOUT_HUBS)
  34315. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  34316. +#else
  34317. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  34318. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  34319. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  34320. +#endif
  34321. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  34322. /* FIXME actually, printers are NOT supposed to use device classes;
  34323. * they're supposed to use interface classes...
  34324. */
  34325. -{ USB_DEVICE_INFO(7, 1, 1) },
  34326. -{ USB_DEVICE_INFO(7, 1, 2) },
  34327. -{ USB_DEVICE_INFO(7, 1, 3) },
  34328. +//{ USB_DEVICE_INFO(7, 1, 1) },
  34329. +//{ USB_DEVICE_INFO(7, 1, 2) },
  34330. +//{ USB_DEVICE_INFO(7, 1, 3) },
  34331. #endif
  34332. #ifdef CONFIG_USB_NET_CDCETHER
  34333. /* Linux-USB CDC Ethernet gadget */
  34334. -{ USB_DEVICE(0x0525, 0xa4a1), },
  34335. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  34336. /* Linux-USB CDC Ethernet + RNDIS gadget */
  34337. -{ USB_DEVICE(0x0525, 0xa4a2), },
  34338. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  34339. #endif
  34340. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  34341. /* gadget zero, for testing */
  34342. -{ USB_DEVICE(0x0525, 0xa4a0), },
  34343. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  34344. #endif
  34345. +/* OPT Tester */
  34346. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  34347. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  34348. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  34349. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  34350. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  34351. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  34352. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  34353. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  34354. +
  34355. +/* Sony cameras */
  34356. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  34357. +
  34358. +/* Memory Devices */
  34359. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  34360. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  34361. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  34362. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  34363. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  34364. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  34365. +
  34366. +/* HP Printers */
  34367. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  34368. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  34369. +
  34370. +/* Speakers */
  34371. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  34372. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  34373. +
  34374. { } /* Terminating entry */
  34375. };
  34376. +static inline void report_errors(struct usb_device *dev)
  34377. +{
  34378. + /* OTG MESSAGE: report errors here, customize to match your product */
  34379. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  34380. + le16_to_cpu(dev->descriptor.idVendor),
  34381. + le16_to_cpu(dev->descriptor.idProduct));
  34382. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  34383. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  34384. + } else {
  34385. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  34386. + }
  34387. +}
  34388. +
  34389. +
  34390. static int is_targeted(struct usb_device *dev)
  34391. {
  34392. struct usb_device_id *id = whitelist_table;
  34393. @@ -55,58 +104,83 @@
  34394. return 1;
  34395. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  34396. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  34397. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  34398. - return 0;
  34399. + if (dev->descriptor.idVendor == 0x1a0a &&
  34400. + dev->descriptor.idProduct == 0xbadd) {
  34401. + return 0;
  34402. + } else if (!enable_whitelist) {
  34403. + return 1;
  34404. + } else {
  34405. - /* NOTE: can't use usb_match_id() since interface caches
  34406. - * aren't set up yet. this is cut/paste from that code.
  34407. - */
  34408. - for (id = whitelist_table; id->match_flags; id++) {
  34409. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34410. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34411. - continue;
  34412. -
  34413. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34414. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34415. - continue;
  34416. -
  34417. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34418. - greater than any unsigned number. */
  34419. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34420. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34421. - continue;
  34422. -
  34423. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34424. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34425. - continue;
  34426. -
  34427. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34428. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34429. - continue;
  34430. -
  34431. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34432. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34433. - continue;
  34434. -
  34435. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34436. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34437. - continue;
  34438. +#ifdef DEBUG
  34439. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34440. + dev->descriptor.idVendor,
  34441. + dev->descriptor.idProduct,
  34442. + dev->descriptor.bDeviceClass,
  34443. + dev->descriptor.bDeviceSubClass,
  34444. + dev->descriptor.bDeviceProtocol);
  34445. +#endif
  34446. return 1;
  34447. + /* NOTE: can't use usb_match_id() since interface caches
  34448. + * aren't set up yet. this is cut/paste from that code.
  34449. + */
  34450. + for (id = whitelist_table; id->match_flags; id++) {
  34451. +#ifdef DEBUG
  34452. + dev_dbg(&dev->dev,
  34453. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34454. + id->idVendor,
  34455. + id->idProduct,
  34456. + id->bDeviceClass,
  34457. + id->bDeviceSubClass,
  34458. + id->bDeviceProtocol);
  34459. +#endif
  34460. +
  34461. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34462. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34463. + continue;
  34464. +
  34465. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34466. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34467. + continue;
  34468. +
  34469. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34470. + greater than any unsigned number. */
  34471. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34472. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34473. + continue;
  34474. +
  34475. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34476. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34477. + continue;
  34478. +
  34479. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34480. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34481. + continue;
  34482. +
  34483. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34484. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34485. + continue;
  34486. +
  34487. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34488. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34489. + continue;
  34490. +
  34491. + return 1;
  34492. + }
  34493. }
  34494. /* add other match criteria here ... */
  34495. -
  34496. - /* OTG MESSAGE: report errors here, customize to match your product */
  34497. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  34498. - le16_to_cpu(dev->descriptor.idVendor),
  34499. - le16_to_cpu(dev->descriptor.idProduct));
  34500. #ifdef CONFIG_USB_OTG_WHITELIST
  34501. + report_errors(dev);
  34502. return 0;
  34503. #else
  34504. - return 1;
  34505. + if (enable_whitelist) {
  34506. + report_errors(dev);
  34507. + return 0;
  34508. + } else {
  34509. + return 1;
  34510. + }
  34511. #endif
  34512. }
  34513. diff -Nur linux-3.11.10.orig/drivers/usb/gadget/file_storage.c linux-3.11.10/drivers/usb/gadget/file_storage.c
  34514. --- linux-3.11.10.orig/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  34515. +++ linux-3.11.10/drivers/usb/gadget/file_storage.c 2014-02-07 19:57:30.000000000 +0100
  34516. @@ -0,0 +1,3676 @@
  34517. +/*
  34518. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  34519. + *
  34520. + * Copyright (C) 2003-2008 Alan Stern
  34521. + * All rights reserved.
  34522. + *
  34523. + * Redistribution and use in source and binary forms, with or without
  34524. + * modification, are permitted provided that the following conditions
  34525. + * are met:
  34526. + * 1. Redistributions of source code must retain the above copyright
  34527. + * notice, this list of conditions, and the following disclaimer,
  34528. + * without modification.
  34529. + * 2. Redistributions in binary form must reproduce the above copyright
  34530. + * notice, this list of conditions and the following disclaimer in the
  34531. + * documentation and/or other materials provided with the distribution.
  34532. + * 3. The names of the above-listed copyright holders may not be used
  34533. + * to endorse or promote products derived from this software without
  34534. + * specific prior written permission.
  34535. + *
  34536. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34537. + * GNU General Public License ("GPL") as published by the Free Software
  34538. + * Foundation, either version 2 of that License or (at your option) any
  34539. + * later version.
  34540. + *
  34541. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34542. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34543. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34544. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34545. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34546. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34547. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34548. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34549. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34550. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34551. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34552. + */
  34553. +
  34554. +
  34555. +/*
  34556. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  34557. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  34558. + * to providing an example of a genuinely useful gadget driver for a USB
  34559. + * device, it also illustrates a technique of double-buffering for increased
  34560. + * throughput. Last but not least, it gives an easy way to probe the
  34561. + * behavior of the Mass Storage drivers in a USB host.
  34562. + *
  34563. + * Backing storage is provided by a regular file or a block device, specified
  34564. + * by the "file" module parameter. Access can be limited to read-only by
  34565. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  34566. + * access is always read-only.) The gadget will indicate that it has
  34567. + * removable media if the optional "removable" module parameter is set.
  34568. + *
  34569. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  34570. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  34571. + * by the optional "transport" module parameter. It also supports the
  34572. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  34573. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  34574. + * the optional "protocol" module parameter. In addition, the default
  34575. + * Vendor ID, Product ID, release number and serial number can be overridden.
  34576. + *
  34577. + * There is support for multiple logical units (LUNs), each of which has
  34578. + * its own backing file. The number of LUNs can be set using the optional
  34579. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  34580. + * files are specified using comma-separated lists for "file" and "ro".
  34581. + * The default number of LUNs is taken from the number of "file" elements;
  34582. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  34583. + * file must be specified for each LUN. If it is set, then an unspecified
  34584. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  34585. + * each LUN would be settable independently as a disk drive or a CD-ROM
  34586. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  34587. + * emulation includes a single data track and no audio tracks; hence there
  34588. + * need be only one backing file per LUN.
  34589. + *
  34590. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  34591. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  34592. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  34593. + * Support is included for both full-speed and high-speed operation.
  34594. + *
  34595. + * Note that the driver is slightly non-portable in that it assumes a
  34596. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  34597. + * interrupt-in endpoints. With most device controllers this isn't an
  34598. + * issue, but there may be some with hardware restrictions that prevent
  34599. + * a buffer from being used by more than one endpoint.
  34600. + *
  34601. + * Module options:
  34602. + *
  34603. + * file=filename[,filename...]
  34604. + * Required if "removable" is not set, names of
  34605. + * the files or block devices used for
  34606. + * backing storage
  34607. + * serial=HHHH... Required serial number (string of hex chars)
  34608. + * ro=b[,b...] Default false, booleans for read-only access
  34609. + * removable Default false, boolean for removable media
  34610. + * luns=N Default N = number of filenames, number of
  34611. + * LUNs to support
  34612. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  34613. + * in SCSI WRITE(10,12) commands
  34614. + * stall Default determined according to the type of
  34615. + * USB device controller (usually true),
  34616. + * boolean to permit the driver to halt
  34617. + * bulk endpoints
  34618. + * cdrom Default false, boolean for whether to emulate
  34619. + * a CD-ROM drive
  34620. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  34621. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  34622. + * ATAPI, QIC, UFI, 8070, or SCSI;
  34623. + * also 1 - 6)
  34624. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  34625. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  34626. + * release=0xRRRR Override the USB release number (bcdDevice)
  34627. + * buflen=N Default N=16384, buffer size used (will be
  34628. + * rounded down to a multiple of
  34629. + * PAGE_CACHE_SIZE)
  34630. + *
  34631. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  34632. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  34633. + * default values are used for everything else.
  34634. + *
  34635. + * The pathnames of the backing files and the ro settings are available in
  34636. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  34637. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  34638. + * these files will simulate ejecting/loading the medium (writing an empty
  34639. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  34640. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  34641. + * is being used.
  34642. + *
  34643. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  34644. + * The driver's SCSI command interface was based on the "Information
  34645. + * technology - Small Computer System Interface - 2" document from
  34646. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  34647. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  34648. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  34649. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  34650. + * document, Revision 1.0, December 14, 1998, available at
  34651. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  34652. + */
  34653. +
  34654. +
  34655. +/*
  34656. + * Driver Design
  34657. + *
  34658. + * The FSG driver is fairly straightforward. There is a main kernel
  34659. + * thread that handles most of the work. Interrupt routines field
  34660. + * callbacks from the controller driver: bulk- and interrupt-request
  34661. + * completion notifications, endpoint-0 events, and disconnect events.
  34662. + * Completion events are passed to the main thread by wakeup calls. Many
  34663. + * ep0 requests are handled at interrupt time, but SetInterface,
  34664. + * SetConfiguration, and device reset requests are forwarded to the
  34665. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  34666. + * should interrupt any ongoing file I/O operations).
  34667. + *
  34668. + * The thread's main routine implements the standard command/data/status
  34669. + * parts of a SCSI interaction. It and its subroutines are full of tests
  34670. + * for pending signals/exceptions -- all this polling is necessary since
  34671. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  34672. + * indication that the driver really wants to be running in userspace.)
  34673. + * An important point is that so long as the thread is alive it keeps an
  34674. + * open reference to the backing file. This will prevent unmounting
  34675. + * the backing file's underlying filesystem and could cause problems
  34676. + * during system shutdown, for example. To prevent such problems, the
  34677. + * thread catches INT, TERM, and KILL signals and converts them into
  34678. + * an EXIT exception.
  34679. + *
  34680. + * In normal operation the main thread is started during the gadget's
  34681. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  34682. + * exit when it receives a signal, and there's no point leaving the
  34683. + * gadget running when the thread is dead. So just before the thread
  34684. + * exits, it deregisters the gadget driver. This makes things a little
  34685. + * tricky: The driver is deregistered at two places, and the exiting
  34686. + * thread can indirectly call fsg_unbind() which in turn can tell the
  34687. + * thread to exit. The first problem is resolved through the use of the
  34688. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  34689. + * The second problem is resolved by having fsg_unbind() check
  34690. + * fsg->state; it won't try to stop the thread if the state is already
  34691. + * FSG_STATE_TERMINATED.
  34692. + *
  34693. + * To provide maximum throughput, the driver uses a circular pipeline of
  34694. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  34695. + * arbitrarily long; in practice the benefits don't justify having more
  34696. + * than 2 stages (i.e., double buffering). But it helps to think of the
  34697. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  34698. + * a bulk-out request pointer (since the buffer can be used for both
  34699. + * output and input -- directions always are given from the host's
  34700. + * point of view) as well as a pointer to the buffer and various state
  34701. + * variables.
  34702. + *
  34703. + * Use of the pipeline follows a simple protocol. There is a variable
  34704. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  34705. + * At any time that buffer head may still be in use from an earlier
  34706. + * request, so each buffer head has a state variable indicating whether
  34707. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  34708. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  34709. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  34710. + * head FULL when the I/O is complete. Then the buffer will be emptied
  34711. + * (again possibly by USB I/O, during which it is marked BUSY) and
  34712. + * finally marked EMPTY again (possibly by a completion routine).
  34713. + *
  34714. + * A module parameter tells the driver to avoid stalling the bulk
  34715. + * endpoints wherever the transport specification allows. This is
  34716. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  34717. + * halt on a bulk endpoint. However, under certain circumstances the
  34718. + * Bulk-only specification requires a stall. In such cases the driver
  34719. + * will halt the endpoint and set a flag indicating that it should clear
  34720. + * the halt in software during the next device reset. Hopefully this
  34721. + * will permit everything to work correctly. Furthermore, although the
  34722. + * specification allows the bulk-out endpoint to halt when the host sends
  34723. + * too much data, implementing this would cause an unavoidable race.
  34724. + * The driver will always use the "no-stall" approach for OUT transfers.
  34725. + *
  34726. + * One subtle point concerns sending status-stage responses for ep0
  34727. + * requests. Some of these requests, such as device reset, can involve
  34728. + * interrupting an ongoing file I/O operation, which might take an
  34729. + * arbitrarily long time. During that delay the host might give up on
  34730. + * the original ep0 request and issue a new one. When that happens the
  34731. + * driver should not notify the host about completion of the original
  34732. + * request, as the host will no longer be waiting for it. So the driver
  34733. + * assigns to each ep0 request a unique tag, and it keeps track of the
  34734. + * tag value of the request associated with a long-running exception
  34735. + * (device-reset, interface-change, or configuration-change). When the
  34736. + * exception handler is finished, the status-stage response is submitted
  34737. + * only if the current ep0 request tag is equal to the exception request
  34738. + * tag. Thus only the most recently received ep0 request will get a
  34739. + * status-stage response.
  34740. + *
  34741. + * Warning: This driver source file is too long. It ought to be split up
  34742. + * into a header file plus about 3 separate .c files, to handle the details
  34743. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  34744. + */
  34745. +
  34746. +
  34747. +/* #define VERBOSE_DEBUG */
  34748. +/* #define DUMP_MSGS */
  34749. +
  34750. +
  34751. +#include <linux/blkdev.h>
  34752. +#include <linux/completion.h>
  34753. +#include <linux/dcache.h>
  34754. +#include <linux/delay.h>
  34755. +#include <linux/device.h>
  34756. +#include <linux/fcntl.h>
  34757. +#include <linux/file.h>
  34758. +#include <linux/fs.h>
  34759. +#include <linux/kref.h>
  34760. +#include <linux/kthread.h>
  34761. +#include <linux/limits.h>
  34762. +#include <linux/module.h>
  34763. +#include <linux/rwsem.h>
  34764. +#include <linux/slab.h>
  34765. +#include <linux/spinlock.h>
  34766. +#include <linux/string.h>
  34767. +#include <linux/freezer.h>
  34768. +#include <linux/utsname.h>
  34769. +
  34770. +#include <linux/usb/ch9.h>
  34771. +#include <linux/usb/gadget.h>
  34772. +
  34773. +#include "gadget_chips.h"
  34774. +
  34775. +
  34776. +
  34777. +/*
  34778. + * Kbuild is not very cooperative with respect to linking separately
  34779. + * compiled library objects into one module. So for now we won't use
  34780. + * separate compilation ... ensuring init/exit sections work to shrink
  34781. + * the runtime footprint, and giving us at least some parts of what
  34782. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  34783. + */
  34784. +#include "usbstring.c"
  34785. +#include "config.c"
  34786. +#include "epautoconf.c"
  34787. +
  34788. +/*-------------------------------------------------------------------------*/
  34789. +
  34790. +#define DRIVER_DESC "File-backed Storage Gadget"
  34791. +#define DRIVER_NAME "g_file_storage"
  34792. +#define DRIVER_VERSION "1 September 2010"
  34793. +
  34794. +static char fsg_string_manufacturer[64];
  34795. +static const char fsg_string_product[] = DRIVER_DESC;
  34796. +static const char fsg_string_config[] = "Self-powered";
  34797. +static const char fsg_string_interface[] = "Mass Storage";
  34798. +
  34799. +
  34800. +#include "storage_common.c"
  34801. +
  34802. +
  34803. +MODULE_DESCRIPTION(DRIVER_DESC);
  34804. +MODULE_AUTHOR("Alan Stern");
  34805. +MODULE_LICENSE("Dual BSD/GPL");
  34806. +
  34807. +/*
  34808. + * This driver assumes self-powered hardware and has no way for users to
  34809. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  34810. + * and endpoint addresses.
  34811. + */
  34812. +
  34813. +
  34814. +/*-------------------------------------------------------------------------*/
  34815. +
  34816. +
  34817. +/* Encapsulate the module parameter settings */
  34818. +
  34819. +static struct {
  34820. + char *file[FSG_MAX_LUNS];
  34821. + char *serial;
  34822. + bool ro[FSG_MAX_LUNS];
  34823. + bool nofua[FSG_MAX_LUNS];
  34824. + unsigned int num_filenames;
  34825. + unsigned int num_ros;
  34826. + unsigned int num_nofuas;
  34827. + unsigned int nluns;
  34828. +
  34829. + bool removable;
  34830. + bool can_stall;
  34831. + bool cdrom;
  34832. +
  34833. + char *transport_parm;
  34834. + char *protocol_parm;
  34835. + unsigned short vendor;
  34836. + unsigned short product;
  34837. + unsigned short release;
  34838. + unsigned int buflen;
  34839. +
  34840. + int transport_type;
  34841. + char *transport_name;
  34842. + int protocol_type;
  34843. + char *protocol_name;
  34844. +
  34845. +} mod_data = { // Default values
  34846. + .transport_parm = "BBB",
  34847. + .protocol_parm = "SCSI",
  34848. + .removable = 0,
  34849. + .can_stall = 1,
  34850. + .cdrom = 0,
  34851. + .vendor = FSG_VENDOR_ID,
  34852. + .product = FSG_PRODUCT_ID,
  34853. + .release = 0xffff, // Use controller chip type
  34854. + .buflen = 16384,
  34855. + };
  34856. +
  34857. +
  34858. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  34859. + S_IRUGO);
  34860. +MODULE_PARM_DESC(file, "names of backing files or devices");
  34861. +
  34862. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  34863. +MODULE_PARM_DESC(serial, "USB serial number");
  34864. +
  34865. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  34866. +MODULE_PARM_DESC(ro, "true to force read-only");
  34867. +
  34868. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  34869. + S_IRUGO);
  34870. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  34871. +
  34872. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  34873. +MODULE_PARM_DESC(luns, "number of LUNs");
  34874. +
  34875. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  34876. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  34877. +
  34878. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  34879. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  34880. +
  34881. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  34882. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  34883. +
  34884. +/* In the non-TEST version, only the module parameters listed above
  34885. + * are available. */
  34886. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34887. +
  34888. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  34889. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  34890. +
  34891. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  34892. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  34893. + "8070, or SCSI)");
  34894. +
  34895. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  34896. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  34897. +
  34898. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  34899. +MODULE_PARM_DESC(product, "USB Product ID");
  34900. +
  34901. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  34902. +MODULE_PARM_DESC(release, "USB release number");
  34903. +
  34904. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  34905. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  34906. +
  34907. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34908. +
  34909. +
  34910. +/*
  34911. + * These definitions will permit the compiler to avoid generating code for
  34912. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  34913. + * can recognize when a test of a constant expression yields a dead code
  34914. + * path.
  34915. + */
  34916. +
  34917. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34918. +
  34919. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  34920. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  34921. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  34922. +
  34923. +#else
  34924. +
  34925. +#define transport_is_bbb() 1
  34926. +#define transport_is_cbi() 0
  34927. +#define protocol_is_scsi() 1
  34928. +
  34929. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34930. +
  34931. +
  34932. +/*-------------------------------------------------------------------------*/
  34933. +
  34934. +
  34935. +struct fsg_dev {
  34936. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  34937. + spinlock_t lock;
  34938. + struct usb_gadget *gadget;
  34939. +
  34940. + /* filesem protects: backing files in use */
  34941. + struct rw_semaphore filesem;
  34942. +
  34943. + /* reference counting: wait until all LUNs are released */
  34944. + struct kref ref;
  34945. +
  34946. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  34947. + struct usb_request *ep0req; // For control responses
  34948. + unsigned int ep0_req_tag;
  34949. + const char *ep0req_name;
  34950. +
  34951. + struct usb_request *intreq; // For interrupt responses
  34952. + int intreq_busy;
  34953. + struct fsg_buffhd *intr_buffhd;
  34954. +
  34955. + unsigned int bulk_out_maxpacket;
  34956. + enum fsg_state state; // For exception handling
  34957. + unsigned int exception_req_tag;
  34958. +
  34959. + u8 config, new_config;
  34960. +
  34961. + unsigned int running : 1;
  34962. + unsigned int bulk_in_enabled : 1;
  34963. + unsigned int bulk_out_enabled : 1;
  34964. + unsigned int intr_in_enabled : 1;
  34965. + unsigned int phase_error : 1;
  34966. + unsigned int short_packet_received : 1;
  34967. + unsigned int bad_lun_okay : 1;
  34968. +
  34969. + unsigned long atomic_bitflags;
  34970. +#define REGISTERED 0
  34971. +#define IGNORE_BULK_OUT 1
  34972. +#define SUSPENDED 2
  34973. +
  34974. + struct usb_ep *bulk_in;
  34975. + struct usb_ep *bulk_out;
  34976. + struct usb_ep *intr_in;
  34977. +
  34978. + struct fsg_buffhd *next_buffhd_to_fill;
  34979. + struct fsg_buffhd *next_buffhd_to_drain;
  34980. +
  34981. + int thread_wakeup_needed;
  34982. + struct completion thread_notifier;
  34983. + struct task_struct *thread_task;
  34984. +
  34985. + int cmnd_size;
  34986. + u8 cmnd[MAX_COMMAND_SIZE];
  34987. + enum data_direction data_dir;
  34988. + u32 data_size;
  34989. + u32 data_size_from_cmnd;
  34990. + u32 tag;
  34991. + unsigned int lun;
  34992. + u32 residue;
  34993. + u32 usb_amount_left;
  34994. +
  34995. + /* The CB protocol offers no way for a host to know when a command
  34996. + * has completed. As a result the next command may arrive early,
  34997. + * and we will still have to handle it. For that reason we need
  34998. + * a buffer to store new commands when using CB (or CBI, which
  34999. + * does not oblige a host to wait for command completion either). */
  35000. + int cbbuf_cmnd_size;
  35001. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  35002. +
  35003. + unsigned int nluns;
  35004. + struct fsg_lun *luns;
  35005. + struct fsg_lun *curlun;
  35006. + /* Must be the last entry */
  35007. + struct fsg_buffhd buffhds[];
  35008. +};
  35009. +
  35010. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  35011. +
  35012. +static int exception_in_progress(struct fsg_dev *fsg)
  35013. +{
  35014. + return (fsg->state > FSG_STATE_IDLE);
  35015. +}
  35016. +
  35017. +/* Make bulk-out requests be divisible by the maxpacket size */
  35018. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  35019. + struct fsg_buffhd *bh, unsigned int length)
  35020. +{
  35021. + unsigned int rem;
  35022. +
  35023. + bh->bulk_out_intended_length = length;
  35024. + rem = length % fsg->bulk_out_maxpacket;
  35025. + if (rem > 0)
  35026. + length += fsg->bulk_out_maxpacket - rem;
  35027. + bh->outreq->length = length;
  35028. +}
  35029. +
  35030. +static struct fsg_dev *the_fsg;
  35031. +static struct usb_gadget_driver fsg_driver;
  35032. +
  35033. +
  35034. +/*-------------------------------------------------------------------------*/
  35035. +
  35036. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  35037. +{
  35038. + const char *name;
  35039. +
  35040. + if (ep == fsg->bulk_in)
  35041. + name = "bulk-in";
  35042. + else if (ep == fsg->bulk_out)
  35043. + name = "bulk-out";
  35044. + else
  35045. + name = ep->name;
  35046. + DBG(fsg, "%s set halt\n", name);
  35047. + return usb_ep_set_halt(ep);
  35048. +}
  35049. +
  35050. +
  35051. +/*-------------------------------------------------------------------------*/
  35052. +
  35053. +/*
  35054. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  35055. + * descriptors are built on demand. Also the (static) config and interface
  35056. + * descriptors are adjusted during fsg_bind().
  35057. + */
  35058. +
  35059. +/* There is only one configuration. */
  35060. +#define CONFIG_VALUE 1
  35061. +
  35062. +static struct usb_device_descriptor
  35063. +device_desc = {
  35064. + .bLength = sizeof device_desc,
  35065. + .bDescriptorType = USB_DT_DEVICE,
  35066. +
  35067. + .bcdUSB = cpu_to_le16(0x0200),
  35068. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35069. +
  35070. + /* The next three values can be overridden by module parameters */
  35071. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  35072. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  35073. + .bcdDevice = cpu_to_le16(0xffff),
  35074. +
  35075. + .iManufacturer = FSG_STRING_MANUFACTURER,
  35076. + .iProduct = FSG_STRING_PRODUCT,
  35077. + .iSerialNumber = FSG_STRING_SERIAL,
  35078. + .bNumConfigurations = 1,
  35079. +};
  35080. +
  35081. +static struct usb_config_descriptor
  35082. +config_desc = {
  35083. + .bLength = sizeof config_desc,
  35084. + .bDescriptorType = USB_DT_CONFIG,
  35085. +
  35086. + /* wTotalLength computed by usb_gadget_config_buf() */
  35087. + .bNumInterfaces = 1,
  35088. + .bConfigurationValue = CONFIG_VALUE,
  35089. + .iConfiguration = FSG_STRING_CONFIG,
  35090. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  35091. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  35092. +};
  35093. +
  35094. +
  35095. +static struct usb_qualifier_descriptor
  35096. +dev_qualifier = {
  35097. + .bLength = sizeof dev_qualifier,
  35098. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  35099. +
  35100. + .bcdUSB = cpu_to_le16(0x0200),
  35101. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35102. +
  35103. + .bNumConfigurations = 1,
  35104. +};
  35105. +
  35106. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  35107. +{
  35108. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  35109. + buf += USB_DT_BOS_SIZE;
  35110. +
  35111. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  35112. + buf += USB_DT_USB_EXT_CAP_SIZE;
  35113. +
  35114. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  35115. +
  35116. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  35117. + + USB_DT_USB_EXT_CAP_SIZE;
  35118. +}
  35119. +
  35120. +/*
  35121. + * Config descriptors must agree with the code that sets configurations
  35122. + * and with code managing interfaces and their altsettings. They must
  35123. + * also handle different speeds and other-speed requests.
  35124. + */
  35125. +static int populate_config_buf(struct usb_gadget *gadget,
  35126. + u8 *buf, u8 type, unsigned index)
  35127. +{
  35128. + enum usb_device_speed speed = gadget->speed;
  35129. + int len;
  35130. + const struct usb_descriptor_header **function;
  35131. +
  35132. + if (index > 0)
  35133. + return -EINVAL;
  35134. +
  35135. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  35136. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  35137. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  35138. + ? (const struct usb_descriptor_header **)fsg_hs_function
  35139. + : (const struct usb_descriptor_header **)fsg_fs_function;
  35140. +
  35141. + /* for now, don't advertise srp-only devices */
  35142. + if (!gadget_is_otg(gadget))
  35143. + function++;
  35144. +
  35145. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  35146. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  35147. + return len;
  35148. +}
  35149. +
  35150. +
  35151. +/*-------------------------------------------------------------------------*/
  35152. +
  35153. +/* These routines may be called in process context or in_irq */
  35154. +
  35155. +/* Caller must hold fsg->lock */
  35156. +static void wakeup_thread(struct fsg_dev *fsg)
  35157. +{
  35158. + /* Tell the main thread that something has happened */
  35159. + fsg->thread_wakeup_needed = 1;
  35160. + if (fsg->thread_task)
  35161. + wake_up_process(fsg->thread_task);
  35162. +}
  35163. +
  35164. +
  35165. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  35166. +{
  35167. + unsigned long flags;
  35168. +
  35169. + /* Do nothing if a higher-priority exception is already in progress.
  35170. + * If a lower-or-equal priority exception is in progress, preempt it
  35171. + * and notify the main thread by sending it a signal. */
  35172. + spin_lock_irqsave(&fsg->lock, flags);
  35173. + if (fsg->state <= new_state) {
  35174. + fsg->exception_req_tag = fsg->ep0_req_tag;
  35175. + fsg->state = new_state;
  35176. + if (fsg->thread_task)
  35177. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  35178. + fsg->thread_task);
  35179. + }
  35180. + spin_unlock_irqrestore(&fsg->lock, flags);
  35181. +}
  35182. +
  35183. +
  35184. +/*-------------------------------------------------------------------------*/
  35185. +
  35186. +/* The disconnect callback and ep0 routines. These always run in_irq,
  35187. + * except that ep0_queue() is called in the main thread to acknowledge
  35188. + * completion of various requests: set config, set interface, and
  35189. + * Bulk-only device reset. */
  35190. +
  35191. +static void fsg_disconnect(struct usb_gadget *gadget)
  35192. +{
  35193. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35194. +
  35195. + DBG(fsg, "disconnect or port reset\n");
  35196. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  35197. +}
  35198. +
  35199. +
  35200. +static int ep0_queue(struct fsg_dev *fsg)
  35201. +{
  35202. + int rc;
  35203. +
  35204. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  35205. + if (rc != 0 && rc != -ESHUTDOWN) {
  35206. +
  35207. + /* We can't do much more than wait for a reset */
  35208. + WARNING(fsg, "error in submission: %s --> %d\n",
  35209. + fsg->ep0->name, rc);
  35210. + }
  35211. + return rc;
  35212. +}
  35213. +
  35214. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  35215. +{
  35216. + struct fsg_dev *fsg = ep->driver_data;
  35217. +
  35218. + if (req->actual > 0)
  35219. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  35220. + if (req->status || req->actual != req->length)
  35221. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35222. + req->status, req->actual, req->length);
  35223. + if (req->status == -ECONNRESET) // Request was cancelled
  35224. + usb_ep_fifo_flush(ep);
  35225. +
  35226. + if (req->status == 0 && req->context)
  35227. + ((fsg_routine_t) (req->context))(fsg);
  35228. +}
  35229. +
  35230. +
  35231. +/*-------------------------------------------------------------------------*/
  35232. +
  35233. +/* Bulk and interrupt endpoint completion handlers.
  35234. + * These always run in_irq. */
  35235. +
  35236. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  35237. +{
  35238. + struct fsg_dev *fsg = ep->driver_data;
  35239. + struct fsg_buffhd *bh = req->context;
  35240. +
  35241. + if (req->status || req->actual != req->length)
  35242. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35243. + req->status, req->actual, req->length);
  35244. + if (req->status == -ECONNRESET) // Request was cancelled
  35245. + usb_ep_fifo_flush(ep);
  35246. +
  35247. + /* Hold the lock while we update the request and buffer states */
  35248. + smp_wmb();
  35249. + spin_lock(&fsg->lock);
  35250. + bh->inreq_busy = 0;
  35251. + bh->state = BUF_STATE_EMPTY;
  35252. + wakeup_thread(fsg);
  35253. + spin_unlock(&fsg->lock);
  35254. +}
  35255. +
  35256. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  35257. +{
  35258. + struct fsg_dev *fsg = ep->driver_data;
  35259. + struct fsg_buffhd *bh = req->context;
  35260. +
  35261. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  35262. + if (req->status || req->actual != bh->bulk_out_intended_length)
  35263. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35264. + req->status, req->actual,
  35265. + bh->bulk_out_intended_length);
  35266. + if (req->status == -ECONNRESET) // Request was cancelled
  35267. + usb_ep_fifo_flush(ep);
  35268. +
  35269. + /* Hold the lock while we update the request and buffer states */
  35270. + smp_wmb();
  35271. + spin_lock(&fsg->lock);
  35272. + bh->outreq_busy = 0;
  35273. + bh->state = BUF_STATE_FULL;
  35274. + wakeup_thread(fsg);
  35275. + spin_unlock(&fsg->lock);
  35276. +}
  35277. +
  35278. +
  35279. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35280. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35281. +{
  35282. + struct fsg_dev *fsg = ep->driver_data;
  35283. + struct fsg_buffhd *bh = req->context;
  35284. +
  35285. + if (req->status || req->actual != req->length)
  35286. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35287. + req->status, req->actual, req->length);
  35288. + if (req->status == -ECONNRESET) // Request was cancelled
  35289. + usb_ep_fifo_flush(ep);
  35290. +
  35291. + /* Hold the lock while we update the request and buffer states */
  35292. + smp_wmb();
  35293. + spin_lock(&fsg->lock);
  35294. + fsg->intreq_busy = 0;
  35295. + bh->state = BUF_STATE_EMPTY;
  35296. + wakeup_thread(fsg);
  35297. + spin_unlock(&fsg->lock);
  35298. +}
  35299. +
  35300. +#else
  35301. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35302. +{}
  35303. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35304. +
  35305. +
  35306. +/*-------------------------------------------------------------------------*/
  35307. +
  35308. +/* Ep0 class-specific handlers. These always run in_irq. */
  35309. +
  35310. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35311. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35312. +{
  35313. + struct usb_request *req = fsg->ep0req;
  35314. + static u8 cbi_reset_cmnd[6] = {
  35315. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  35316. +
  35317. + /* Error in command transfer? */
  35318. + if (req->status || req->length != req->actual ||
  35319. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  35320. +
  35321. + /* Not all controllers allow a protocol stall after
  35322. + * receiving control-out data, but we'll try anyway. */
  35323. + fsg_set_halt(fsg, fsg->ep0);
  35324. + return; // Wait for reset
  35325. + }
  35326. +
  35327. + /* Is it the special reset command? */
  35328. + if (req->actual >= sizeof cbi_reset_cmnd &&
  35329. + memcmp(req->buf, cbi_reset_cmnd,
  35330. + sizeof cbi_reset_cmnd) == 0) {
  35331. +
  35332. + /* Raise an exception to stop the current operation
  35333. + * and reinitialize our state. */
  35334. + DBG(fsg, "cbi reset request\n");
  35335. + raise_exception(fsg, FSG_STATE_RESET);
  35336. + return;
  35337. + }
  35338. +
  35339. + VDBG(fsg, "CB[I] accept device-specific command\n");
  35340. + spin_lock(&fsg->lock);
  35341. +
  35342. + /* Save the command for later */
  35343. + if (fsg->cbbuf_cmnd_size)
  35344. + WARNING(fsg, "CB[I] overwriting previous command\n");
  35345. + fsg->cbbuf_cmnd_size = req->actual;
  35346. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  35347. +
  35348. + wakeup_thread(fsg);
  35349. + spin_unlock(&fsg->lock);
  35350. +}
  35351. +
  35352. +#else
  35353. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35354. +{}
  35355. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35356. +
  35357. +
  35358. +static int class_setup_req(struct fsg_dev *fsg,
  35359. + const struct usb_ctrlrequest *ctrl)
  35360. +{
  35361. + struct usb_request *req = fsg->ep0req;
  35362. + int value = -EOPNOTSUPP;
  35363. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35364. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35365. + u16 w_length = le16_to_cpu(ctrl->wLength);
  35366. +
  35367. + if (!fsg->config)
  35368. + return value;
  35369. +
  35370. + /* Handle Bulk-only class-specific requests */
  35371. + if (transport_is_bbb()) {
  35372. + switch (ctrl->bRequest) {
  35373. +
  35374. + case US_BULK_RESET_REQUEST:
  35375. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35376. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35377. + break;
  35378. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  35379. + value = -EDOM;
  35380. + break;
  35381. + }
  35382. +
  35383. + /* Raise an exception to stop the current operation
  35384. + * and reinitialize our state. */
  35385. + DBG(fsg, "bulk reset request\n");
  35386. + raise_exception(fsg, FSG_STATE_RESET);
  35387. + value = DELAYED_STATUS;
  35388. + break;
  35389. +
  35390. + case US_BULK_GET_MAX_LUN:
  35391. + if (ctrl->bRequestType != (USB_DIR_IN |
  35392. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35393. + break;
  35394. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  35395. + value = -EDOM;
  35396. + break;
  35397. + }
  35398. + VDBG(fsg, "get max LUN\n");
  35399. + *(u8 *) req->buf = fsg->nluns - 1;
  35400. + value = 1;
  35401. + break;
  35402. + }
  35403. + }
  35404. +
  35405. + /* Handle CBI class-specific requests */
  35406. + else {
  35407. + switch (ctrl->bRequest) {
  35408. +
  35409. + case USB_CBI_ADSC_REQUEST:
  35410. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35411. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35412. + break;
  35413. + if (w_index != 0 || w_value != 0) {
  35414. + value = -EDOM;
  35415. + break;
  35416. + }
  35417. + if (w_length > MAX_COMMAND_SIZE) {
  35418. + value = -EOVERFLOW;
  35419. + break;
  35420. + }
  35421. + value = w_length;
  35422. + fsg->ep0req->context = received_cbi_adsc;
  35423. + break;
  35424. + }
  35425. + }
  35426. +
  35427. + if (value == -EOPNOTSUPP)
  35428. + VDBG(fsg,
  35429. + "unknown class-specific control req "
  35430. + "%02x.%02x v%04x i%04x l%u\n",
  35431. + ctrl->bRequestType, ctrl->bRequest,
  35432. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  35433. + return value;
  35434. +}
  35435. +
  35436. +
  35437. +/*-------------------------------------------------------------------------*/
  35438. +
  35439. +/* Ep0 standard request handlers. These always run in_irq. */
  35440. +
  35441. +static int standard_setup_req(struct fsg_dev *fsg,
  35442. + const struct usb_ctrlrequest *ctrl)
  35443. +{
  35444. + struct usb_request *req = fsg->ep0req;
  35445. + int value = -EOPNOTSUPP;
  35446. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35447. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35448. +
  35449. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  35450. + * but config change events will also reconfigure hardware. */
  35451. + switch (ctrl->bRequest) {
  35452. +
  35453. + case USB_REQ_GET_DESCRIPTOR:
  35454. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35455. + USB_RECIP_DEVICE))
  35456. + break;
  35457. + switch (w_value >> 8) {
  35458. +
  35459. + case USB_DT_DEVICE:
  35460. + VDBG(fsg, "get device descriptor\n");
  35461. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35462. + value = sizeof device_desc;
  35463. + memcpy(req->buf, &device_desc, value);
  35464. + break;
  35465. + case USB_DT_DEVICE_QUALIFIER:
  35466. + VDBG(fsg, "get device qualifier\n");
  35467. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35468. + fsg->gadget->speed == USB_SPEED_SUPER)
  35469. + break;
  35470. + /*
  35471. + * Assume ep0 uses the same maxpacket value for both
  35472. + * speeds
  35473. + */
  35474. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35475. + value = sizeof dev_qualifier;
  35476. + memcpy(req->buf, &dev_qualifier, value);
  35477. + break;
  35478. +
  35479. + case USB_DT_OTHER_SPEED_CONFIG:
  35480. + VDBG(fsg, "get other-speed config descriptor\n");
  35481. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35482. + fsg->gadget->speed == USB_SPEED_SUPER)
  35483. + break;
  35484. + goto get_config;
  35485. + case USB_DT_CONFIG:
  35486. + VDBG(fsg, "get configuration descriptor\n");
  35487. +get_config:
  35488. + value = populate_config_buf(fsg->gadget,
  35489. + req->buf,
  35490. + w_value >> 8,
  35491. + w_value & 0xff);
  35492. + break;
  35493. +
  35494. + case USB_DT_STRING:
  35495. + VDBG(fsg, "get string descriptor\n");
  35496. +
  35497. + /* wIndex == language code */
  35498. + value = usb_gadget_get_string(&fsg_stringtab,
  35499. + w_value & 0xff, req->buf);
  35500. + break;
  35501. +
  35502. + case USB_DT_BOS:
  35503. + VDBG(fsg, "get bos descriptor\n");
  35504. +
  35505. + if (gadget_is_superspeed(fsg->gadget))
  35506. + value = populate_bos(fsg, req->buf);
  35507. + break;
  35508. + }
  35509. +
  35510. + break;
  35511. +
  35512. + /* One config, two speeds */
  35513. + case USB_REQ_SET_CONFIGURATION:
  35514. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  35515. + USB_RECIP_DEVICE))
  35516. + break;
  35517. + VDBG(fsg, "set configuration\n");
  35518. + if (w_value == CONFIG_VALUE || w_value == 0) {
  35519. + fsg->new_config = w_value;
  35520. +
  35521. + /* Raise an exception to wipe out previous transaction
  35522. + * state (queued bufs, etc) and set the new config. */
  35523. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  35524. + value = DELAYED_STATUS;
  35525. + }
  35526. + break;
  35527. + case USB_REQ_GET_CONFIGURATION:
  35528. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35529. + USB_RECIP_DEVICE))
  35530. + break;
  35531. + VDBG(fsg, "get configuration\n");
  35532. + *(u8 *) req->buf = fsg->config;
  35533. + value = 1;
  35534. + break;
  35535. +
  35536. + case USB_REQ_SET_INTERFACE:
  35537. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  35538. + USB_RECIP_INTERFACE))
  35539. + break;
  35540. + if (fsg->config && w_index == 0) {
  35541. +
  35542. + /* Raise an exception to wipe out previous transaction
  35543. + * state (queued bufs, etc) and install the new
  35544. + * interface altsetting. */
  35545. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  35546. + value = DELAYED_STATUS;
  35547. + }
  35548. + break;
  35549. + case USB_REQ_GET_INTERFACE:
  35550. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35551. + USB_RECIP_INTERFACE))
  35552. + break;
  35553. + if (!fsg->config)
  35554. + break;
  35555. + if (w_index != 0) {
  35556. + value = -EDOM;
  35557. + break;
  35558. + }
  35559. + VDBG(fsg, "get interface\n");
  35560. + *(u8 *) req->buf = 0;
  35561. + value = 1;
  35562. + break;
  35563. +
  35564. + default:
  35565. + VDBG(fsg,
  35566. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  35567. + ctrl->bRequestType, ctrl->bRequest,
  35568. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  35569. + }
  35570. +
  35571. + return value;
  35572. +}
  35573. +
  35574. +
  35575. +static int fsg_setup(struct usb_gadget *gadget,
  35576. + const struct usb_ctrlrequest *ctrl)
  35577. +{
  35578. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35579. + int rc;
  35580. + int w_length = le16_to_cpu(ctrl->wLength);
  35581. +
  35582. + ++fsg->ep0_req_tag; // Record arrival of a new request
  35583. + fsg->ep0req->context = NULL;
  35584. + fsg->ep0req->length = 0;
  35585. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  35586. +
  35587. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  35588. + rc = class_setup_req(fsg, ctrl);
  35589. + else
  35590. + rc = standard_setup_req(fsg, ctrl);
  35591. +
  35592. + /* Respond with data/status or defer until later? */
  35593. + if (rc >= 0 && rc != DELAYED_STATUS) {
  35594. + rc = min(rc, w_length);
  35595. + fsg->ep0req->length = rc;
  35596. + fsg->ep0req->zero = rc < w_length;
  35597. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  35598. + "ep0-in" : "ep0-out");
  35599. + rc = ep0_queue(fsg);
  35600. + }
  35601. +
  35602. + /* Device either stalls (rc < 0) or reports success */
  35603. + return rc;
  35604. +}
  35605. +
  35606. +
  35607. +/*-------------------------------------------------------------------------*/
  35608. +
  35609. +/* All the following routines run in process context */
  35610. +
  35611. +
  35612. +/* Use this for bulk or interrupt transfers, not ep0 */
  35613. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  35614. + struct usb_request *req, int *pbusy,
  35615. + enum fsg_buffer_state *state)
  35616. +{
  35617. + int rc;
  35618. +
  35619. + if (ep == fsg->bulk_in)
  35620. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  35621. + else if (ep == fsg->intr_in)
  35622. + dump_msg(fsg, "intr-in", req->buf, req->length);
  35623. +
  35624. + spin_lock_irq(&fsg->lock);
  35625. + *pbusy = 1;
  35626. + *state = BUF_STATE_BUSY;
  35627. + spin_unlock_irq(&fsg->lock);
  35628. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  35629. + if (rc != 0) {
  35630. + *pbusy = 0;
  35631. + *state = BUF_STATE_EMPTY;
  35632. +
  35633. + /* We can't do much more than wait for a reset */
  35634. +
  35635. + /* Note: currently the net2280 driver fails zero-length
  35636. + * submissions if DMA is enabled. */
  35637. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  35638. + req->length == 0))
  35639. + WARNING(fsg, "error in submission: %s --> %d\n",
  35640. + ep->name, rc);
  35641. + }
  35642. +}
  35643. +
  35644. +
  35645. +static int sleep_thread(struct fsg_dev *fsg)
  35646. +{
  35647. + int rc = 0;
  35648. +
  35649. + /* Wait until a signal arrives or we are woken up */
  35650. + for (;;) {
  35651. + try_to_freeze();
  35652. + set_current_state(TASK_INTERRUPTIBLE);
  35653. + if (signal_pending(current)) {
  35654. + rc = -EINTR;
  35655. + break;
  35656. + }
  35657. + if (fsg->thread_wakeup_needed)
  35658. + break;
  35659. + schedule();
  35660. + }
  35661. + __set_current_state(TASK_RUNNING);
  35662. + fsg->thread_wakeup_needed = 0;
  35663. + return rc;
  35664. +}
  35665. +
  35666. +
  35667. +/*-------------------------------------------------------------------------*/
  35668. +
  35669. +static int do_read(struct fsg_dev *fsg)
  35670. +{
  35671. + struct fsg_lun *curlun = fsg->curlun;
  35672. + u32 lba;
  35673. + struct fsg_buffhd *bh;
  35674. + int rc;
  35675. + u32 amount_left;
  35676. + loff_t file_offset, file_offset_tmp;
  35677. + unsigned int amount;
  35678. + ssize_t nread;
  35679. +
  35680. + /* Get the starting Logical Block Address and check that it's
  35681. + * not too big */
  35682. + if (fsg->cmnd[0] == READ_6)
  35683. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35684. + else {
  35685. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35686. +
  35687. + /* We allow DPO (Disable Page Out = don't save data in the
  35688. + * cache) and FUA (Force Unit Access = don't read from the
  35689. + * cache), but we don't implement them. */
  35690. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35691. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35692. + return -EINVAL;
  35693. + }
  35694. + }
  35695. + if (lba >= curlun->num_sectors) {
  35696. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35697. + return -EINVAL;
  35698. + }
  35699. + file_offset = ((loff_t) lba) << curlun->blkbits;
  35700. +
  35701. + /* Carry out the file reads */
  35702. + amount_left = fsg->data_size_from_cmnd;
  35703. + if (unlikely(amount_left == 0))
  35704. + return -EIO; // No default reply
  35705. +
  35706. + for (;;) {
  35707. +
  35708. + /* Figure out how much we need to read:
  35709. + * Try to read the remaining amount.
  35710. + * But don't read more than the buffer size.
  35711. + * And don't try to read past the end of the file.
  35712. + */
  35713. + amount = min((unsigned int) amount_left, mod_data.buflen);
  35714. + amount = min((loff_t) amount,
  35715. + curlun->file_length - file_offset);
  35716. +
  35717. + /* Wait for the next buffer to become available */
  35718. + bh = fsg->next_buffhd_to_fill;
  35719. + while (bh->state != BUF_STATE_EMPTY) {
  35720. + rc = sleep_thread(fsg);
  35721. + if (rc)
  35722. + return rc;
  35723. + }
  35724. +
  35725. + /* If we were asked to read past the end of file,
  35726. + * end with an empty buffer. */
  35727. + if (amount == 0) {
  35728. + curlun->sense_data =
  35729. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35730. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35731. + curlun->info_valid = 1;
  35732. + bh->inreq->length = 0;
  35733. + bh->state = BUF_STATE_FULL;
  35734. + break;
  35735. + }
  35736. +
  35737. + /* Perform the read */
  35738. + file_offset_tmp = file_offset;
  35739. + nread = vfs_read(curlun->filp,
  35740. + (char __user *) bh->buf,
  35741. + amount, &file_offset_tmp);
  35742. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  35743. + (unsigned long long) file_offset,
  35744. + (int) nread);
  35745. + if (signal_pending(current))
  35746. + return -EINTR;
  35747. +
  35748. + if (nread < 0) {
  35749. + LDBG(curlun, "error in file read: %d\n",
  35750. + (int) nread);
  35751. + nread = 0;
  35752. + } else if (nread < amount) {
  35753. + LDBG(curlun, "partial file read: %d/%u\n",
  35754. + (int) nread, amount);
  35755. + nread = round_down(nread, curlun->blksize);
  35756. + }
  35757. + file_offset += nread;
  35758. + amount_left -= nread;
  35759. + fsg->residue -= nread;
  35760. +
  35761. + /* Except at the end of the transfer, nread will be
  35762. + * equal to the buffer size, which is divisible by the
  35763. + * bulk-in maxpacket size.
  35764. + */
  35765. + bh->inreq->length = nread;
  35766. + bh->state = BUF_STATE_FULL;
  35767. +
  35768. + /* If an error occurred, report it and its position */
  35769. + if (nread < amount) {
  35770. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  35771. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35772. + curlun->info_valid = 1;
  35773. + break;
  35774. + }
  35775. +
  35776. + if (amount_left == 0)
  35777. + break; // No more left to read
  35778. +
  35779. + /* Send this buffer and go read some more */
  35780. + bh->inreq->zero = 0;
  35781. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35782. + &bh->inreq_busy, &bh->state);
  35783. + fsg->next_buffhd_to_fill = bh->next;
  35784. + }
  35785. +
  35786. + return -EIO; // No default reply
  35787. +}
  35788. +
  35789. +
  35790. +/*-------------------------------------------------------------------------*/
  35791. +
  35792. +static int do_write(struct fsg_dev *fsg)
  35793. +{
  35794. + struct fsg_lun *curlun = fsg->curlun;
  35795. + u32 lba;
  35796. + struct fsg_buffhd *bh;
  35797. + int get_some_more;
  35798. + u32 amount_left_to_req, amount_left_to_write;
  35799. + loff_t usb_offset, file_offset, file_offset_tmp;
  35800. + unsigned int amount;
  35801. + ssize_t nwritten;
  35802. + int rc;
  35803. +
  35804. + if (curlun->ro) {
  35805. + curlun->sense_data = SS_WRITE_PROTECTED;
  35806. + return -EINVAL;
  35807. + }
  35808. + spin_lock(&curlun->filp->f_lock);
  35809. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  35810. + spin_unlock(&curlun->filp->f_lock);
  35811. +
  35812. + /* Get the starting Logical Block Address and check that it's
  35813. + * not too big */
  35814. + if (fsg->cmnd[0] == WRITE_6)
  35815. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35816. + else {
  35817. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35818. +
  35819. + /* We allow DPO (Disable Page Out = don't save data in the
  35820. + * cache) and FUA (Force Unit Access = write directly to the
  35821. + * medium). We don't implement DPO; we implement FUA by
  35822. + * performing synchronous output. */
  35823. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35824. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35825. + return -EINVAL;
  35826. + }
  35827. + /* FUA */
  35828. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  35829. + spin_lock(&curlun->filp->f_lock);
  35830. + curlun->filp->f_flags |= O_DSYNC;
  35831. + spin_unlock(&curlun->filp->f_lock);
  35832. + }
  35833. + }
  35834. + if (lba >= curlun->num_sectors) {
  35835. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35836. + return -EINVAL;
  35837. + }
  35838. +
  35839. + /* Carry out the file writes */
  35840. + get_some_more = 1;
  35841. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  35842. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  35843. +
  35844. + while (amount_left_to_write > 0) {
  35845. +
  35846. + /* Queue a request for more data from the host */
  35847. + bh = fsg->next_buffhd_to_fill;
  35848. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  35849. +
  35850. + /* Figure out how much we want to get:
  35851. + * Try to get the remaining amount,
  35852. + * but not more than the buffer size.
  35853. + */
  35854. + amount = min(amount_left_to_req, mod_data.buflen);
  35855. +
  35856. + /* Beyond the end of the backing file? */
  35857. + if (usb_offset >= curlun->file_length) {
  35858. + get_some_more = 0;
  35859. + curlun->sense_data =
  35860. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35861. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  35862. + curlun->info_valid = 1;
  35863. + continue;
  35864. + }
  35865. +
  35866. + /* Get the next buffer */
  35867. + usb_offset += amount;
  35868. + fsg->usb_amount_left -= amount;
  35869. + amount_left_to_req -= amount;
  35870. + if (amount_left_to_req == 0)
  35871. + get_some_more = 0;
  35872. +
  35873. + /* Except at the end of the transfer, amount will be
  35874. + * equal to the buffer size, which is divisible by
  35875. + * the bulk-out maxpacket size.
  35876. + */
  35877. + set_bulk_out_req_length(fsg, bh, amount);
  35878. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  35879. + &bh->outreq_busy, &bh->state);
  35880. + fsg->next_buffhd_to_fill = bh->next;
  35881. + continue;
  35882. + }
  35883. +
  35884. + /* Write the received data to the backing file */
  35885. + bh = fsg->next_buffhd_to_drain;
  35886. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  35887. + break; // We stopped early
  35888. + if (bh->state == BUF_STATE_FULL) {
  35889. + smp_rmb();
  35890. + fsg->next_buffhd_to_drain = bh->next;
  35891. + bh->state = BUF_STATE_EMPTY;
  35892. +
  35893. + /* Did something go wrong with the transfer? */
  35894. + if (bh->outreq->status != 0) {
  35895. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  35896. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35897. + curlun->info_valid = 1;
  35898. + break;
  35899. + }
  35900. +
  35901. + amount = bh->outreq->actual;
  35902. + if (curlun->file_length - file_offset < amount) {
  35903. + LERROR(curlun,
  35904. + "write %u @ %llu beyond end %llu\n",
  35905. + amount, (unsigned long long) file_offset,
  35906. + (unsigned long long) curlun->file_length);
  35907. + amount = curlun->file_length - file_offset;
  35908. + }
  35909. +
  35910. + /* Don't accept excess data. The spec doesn't say
  35911. + * what to do in this case. We'll ignore the error.
  35912. + */
  35913. + amount = min(amount, bh->bulk_out_intended_length);
  35914. +
  35915. + /* Don't write a partial block */
  35916. + amount = round_down(amount, curlun->blksize);
  35917. + if (amount == 0)
  35918. + goto empty_write;
  35919. +
  35920. + /* Perform the write */
  35921. + file_offset_tmp = file_offset;
  35922. + nwritten = vfs_write(curlun->filp,
  35923. + (char __user *) bh->buf,
  35924. + amount, &file_offset_tmp);
  35925. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  35926. + (unsigned long long) file_offset,
  35927. + (int) nwritten);
  35928. + if (signal_pending(current))
  35929. + return -EINTR; // Interrupted!
  35930. +
  35931. + if (nwritten < 0) {
  35932. + LDBG(curlun, "error in file write: %d\n",
  35933. + (int) nwritten);
  35934. + nwritten = 0;
  35935. + } else if (nwritten < amount) {
  35936. + LDBG(curlun, "partial file write: %d/%u\n",
  35937. + (int) nwritten, amount);
  35938. + nwritten = round_down(nwritten, curlun->blksize);
  35939. + }
  35940. + file_offset += nwritten;
  35941. + amount_left_to_write -= nwritten;
  35942. + fsg->residue -= nwritten;
  35943. +
  35944. + /* If an error occurred, report it and its position */
  35945. + if (nwritten < amount) {
  35946. + curlun->sense_data = SS_WRITE_ERROR;
  35947. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35948. + curlun->info_valid = 1;
  35949. + break;
  35950. + }
  35951. +
  35952. + empty_write:
  35953. + /* Did the host decide to stop early? */
  35954. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  35955. + fsg->short_packet_received = 1;
  35956. + break;
  35957. + }
  35958. + continue;
  35959. + }
  35960. +
  35961. + /* Wait for something to happen */
  35962. + rc = sleep_thread(fsg);
  35963. + if (rc)
  35964. + return rc;
  35965. + }
  35966. +
  35967. + return -EIO; // No default reply
  35968. +}
  35969. +
  35970. +
  35971. +/*-------------------------------------------------------------------------*/
  35972. +
  35973. +static int do_synchronize_cache(struct fsg_dev *fsg)
  35974. +{
  35975. + struct fsg_lun *curlun = fsg->curlun;
  35976. + int rc;
  35977. +
  35978. + /* We ignore the requested LBA and write out all file's
  35979. + * dirty data buffers. */
  35980. + rc = fsg_lun_fsync_sub(curlun);
  35981. + if (rc)
  35982. + curlun->sense_data = SS_WRITE_ERROR;
  35983. + return 0;
  35984. +}
  35985. +
  35986. +
  35987. +/*-------------------------------------------------------------------------*/
  35988. +
  35989. +static void invalidate_sub(struct fsg_lun *curlun)
  35990. +{
  35991. + struct file *filp = curlun->filp;
  35992. + struct inode *inode = filp->f_path.dentry->d_inode;
  35993. + unsigned long rc;
  35994. +
  35995. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  35996. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  35997. +}
  35998. +
  35999. +static int do_verify(struct fsg_dev *fsg)
  36000. +{
  36001. + struct fsg_lun *curlun = fsg->curlun;
  36002. + u32 lba;
  36003. + u32 verification_length;
  36004. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36005. + loff_t file_offset, file_offset_tmp;
  36006. + u32 amount_left;
  36007. + unsigned int amount;
  36008. + ssize_t nread;
  36009. +
  36010. + /* Get the starting Logical Block Address and check that it's
  36011. + * not too big */
  36012. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36013. + if (lba >= curlun->num_sectors) {
  36014. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36015. + return -EINVAL;
  36016. + }
  36017. +
  36018. + /* We allow DPO (Disable Page Out = don't save data in the
  36019. + * cache) but we don't implement it. */
  36020. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  36021. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36022. + return -EINVAL;
  36023. + }
  36024. +
  36025. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  36026. + if (unlikely(verification_length == 0))
  36027. + return -EIO; // No default reply
  36028. +
  36029. + /* Prepare to carry out the file verify */
  36030. + amount_left = verification_length << curlun->blkbits;
  36031. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36032. +
  36033. + /* Write out all the dirty buffers before invalidating them */
  36034. + fsg_lun_fsync_sub(curlun);
  36035. + if (signal_pending(current))
  36036. + return -EINTR;
  36037. +
  36038. + invalidate_sub(curlun);
  36039. + if (signal_pending(current))
  36040. + return -EINTR;
  36041. +
  36042. + /* Just try to read the requested blocks */
  36043. + while (amount_left > 0) {
  36044. +
  36045. + /* Figure out how much we need to read:
  36046. + * Try to read the remaining amount, but not more than
  36047. + * the buffer size.
  36048. + * And don't try to read past the end of the file.
  36049. + */
  36050. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36051. + amount = min((loff_t) amount,
  36052. + curlun->file_length - file_offset);
  36053. + if (amount == 0) {
  36054. + curlun->sense_data =
  36055. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36056. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36057. + curlun->info_valid = 1;
  36058. + break;
  36059. + }
  36060. +
  36061. + /* Perform the read */
  36062. + file_offset_tmp = file_offset;
  36063. + nread = vfs_read(curlun->filp,
  36064. + (char __user *) bh->buf,
  36065. + amount, &file_offset_tmp);
  36066. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36067. + (unsigned long long) file_offset,
  36068. + (int) nread);
  36069. + if (signal_pending(current))
  36070. + return -EINTR;
  36071. +
  36072. + if (nread < 0) {
  36073. + LDBG(curlun, "error in file verify: %d\n",
  36074. + (int) nread);
  36075. + nread = 0;
  36076. + } else if (nread < amount) {
  36077. + LDBG(curlun, "partial file verify: %d/%u\n",
  36078. + (int) nread, amount);
  36079. + nread = round_down(nread, curlun->blksize);
  36080. + }
  36081. + if (nread == 0) {
  36082. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36083. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36084. + curlun->info_valid = 1;
  36085. + break;
  36086. + }
  36087. + file_offset += nread;
  36088. + amount_left -= nread;
  36089. + }
  36090. + return 0;
  36091. +}
  36092. +
  36093. +
  36094. +/*-------------------------------------------------------------------------*/
  36095. +
  36096. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36097. +{
  36098. + u8 *buf = (u8 *) bh->buf;
  36099. +
  36100. + static char vendor_id[] = "Linux ";
  36101. + static char product_disk_id[] = "File-Stor Gadget";
  36102. + static char product_cdrom_id[] = "File-CD Gadget ";
  36103. +
  36104. + if (!fsg->curlun) { // Unsupported LUNs are okay
  36105. + fsg->bad_lun_okay = 1;
  36106. + memset(buf, 0, 36);
  36107. + buf[0] = 0x7f; // Unsupported, no device-type
  36108. + buf[4] = 31; // Additional length
  36109. + return 36;
  36110. + }
  36111. +
  36112. + memset(buf, 0, 8);
  36113. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  36114. + if (mod_data.removable)
  36115. + buf[1] = 0x80;
  36116. + buf[2] = 2; // ANSI SCSI level 2
  36117. + buf[3] = 2; // SCSI-2 INQUIRY data format
  36118. + buf[4] = 31; // Additional length
  36119. + // No special options
  36120. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  36121. + (mod_data.cdrom ? product_cdrom_id :
  36122. + product_disk_id),
  36123. + mod_data.release);
  36124. + return 36;
  36125. +}
  36126. +
  36127. +
  36128. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36129. +{
  36130. + struct fsg_lun *curlun = fsg->curlun;
  36131. + u8 *buf = (u8 *) bh->buf;
  36132. + u32 sd, sdinfo;
  36133. + int valid;
  36134. +
  36135. + /*
  36136. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  36137. + *
  36138. + * If a REQUEST SENSE command is received from an initiator
  36139. + * with a pending unit attention condition (before the target
  36140. + * generates the contingent allegiance condition), then the
  36141. + * target shall either:
  36142. + * a) report any pending sense data and preserve the unit
  36143. + * attention condition on the logical unit, or,
  36144. + * b) report the unit attention condition, may discard any
  36145. + * pending sense data, and clear the unit attention
  36146. + * condition on the logical unit for that initiator.
  36147. + *
  36148. + * FSG normally uses option a); enable this code to use option b).
  36149. + */
  36150. +#if 0
  36151. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  36152. + curlun->sense_data = curlun->unit_attention_data;
  36153. + curlun->unit_attention_data = SS_NO_SENSE;
  36154. + }
  36155. +#endif
  36156. +
  36157. + if (!curlun) { // Unsupported LUNs are okay
  36158. + fsg->bad_lun_okay = 1;
  36159. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36160. + sdinfo = 0;
  36161. + valid = 0;
  36162. + } else {
  36163. + sd = curlun->sense_data;
  36164. + sdinfo = curlun->sense_data_info;
  36165. + valid = curlun->info_valid << 7;
  36166. + curlun->sense_data = SS_NO_SENSE;
  36167. + curlun->sense_data_info = 0;
  36168. + curlun->info_valid = 0;
  36169. + }
  36170. +
  36171. + memset(buf, 0, 18);
  36172. + buf[0] = valid | 0x70; // Valid, current error
  36173. + buf[2] = SK(sd);
  36174. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  36175. + buf[7] = 18 - 8; // Additional sense length
  36176. + buf[12] = ASC(sd);
  36177. + buf[13] = ASCQ(sd);
  36178. + return 18;
  36179. +}
  36180. +
  36181. +
  36182. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36183. +{
  36184. + struct fsg_lun *curlun = fsg->curlun;
  36185. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36186. + int pmi = fsg->cmnd[8];
  36187. + u8 *buf = (u8 *) bh->buf;
  36188. +
  36189. + /* Check the PMI and LBA fields */
  36190. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  36191. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36192. + return -EINVAL;
  36193. + }
  36194. +
  36195. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  36196. + /* Max logical block */
  36197. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36198. + return 8;
  36199. +}
  36200. +
  36201. +
  36202. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36203. +{
  36204. + struct fsg_lun *curlun = fsg->curlun;
  36205. + int msf = fsg->cmnd[1] & 0x02;
  36206. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36207. + u8 *buf = (u8 *) bh->buf;
  36208. +
  36209. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  36210. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36211. + return -EINVAL;
  36212. + }
  36213. + if (lba >= curlun->num_sectors) {
  36214. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36215. + return -EINVAL;
  36216. + }
  36217. +
  36218. + memset(buf, 0, 8);
  36219. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  36220. + store_cdrom_address(&buf[4], msf, lba);
  36221. + return 8;
  36222. +}
  36223. +
  36224. +
  36225. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36226. +{
  36227. + struct fsg_lun *curlun = fsg->curlun;
  36228. + int msf = fsg->cmnd[1] & 0x02;
  36229. + int start_track = fsg->cmnd[6];
  36230. + u8 *buf = (u8 *) bh->buf;
  36231. +
  36232. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  36233. + start_track > 1) {
  36234. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36235. + return -EINVAL;
  36236. + }
  36237. +
  36238. + memset(buf, 0, 20);
  36239. + buf[1] = (20-2); /* TOC data length */
  36240. + buf[2] = 1; /* First track number */
  36241. + buf[3] = 1; /* Last track number */
  36242. + buf[5] = 0x16; /* Data track, copying allowed */
  36243. + buf[6] = 0x01; /* Only track is number 1 */
  36244. + store_cdrom_address(&buf[8], msf, 0);
  36245. +
  36246. + buf[13] = 0x16; /* Lead-out track is data */
  36247. + buf[14] = 0xAA; /* Lead-out track number */
  36248. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  36249. + return 20;
  36250. +}
  36251. +
  36252. +
  36253. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36254. +{
  36255. + struct fsg_lun *curlun = fsg->curlun;
  36256. + int mscmnd = fsg->cmnd[0];
  36257. + u8 *buf = (u8 *) bh->buf;
  36258. + u8 *buf0 = buf;
  36259. + int pc, page_code;
  36260. + int changeable_values, all_pages;
  36261. + int valid_page = 0;
  36262. + int len, limit;
  36263. +
  36264. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  36265. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36266. + return -EINVAL;
  36267. + }
  36268. + pc = fsg->cmnd[2] >> 6;
  36269. + page_code = fsg->cmnd[2] & 0x3f;
  36270. + if (pc == 3) {
  36271. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  36272. + return -EINVAL;
  36273. + }
  36274. + changeable_values = (pc == 1);
  36275. + all_pages = (page_code == 0x3f);
  36276. +
  36277. + /* Write the mode parameter header. Fixed values are: default
  36278. + * medium type, no cache control (DPOFUA), and no block descriptors.
  36279. + * The only variable value is the WriteProtect bit. We will fill in
  36280. + * the mode data length later. */
  36281. + memset(buf, 0, 8);
  36282. + if (mscmnd == MODE_SENSE) {
  36283. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36284. + buf += 4;
  36285. + limit = 255;
  36286. + } else { // MODE_SENSE_10
  36287. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36288. + buf += 8;
  36289. + limit = 65535; // Should really be mod_data.buflen
  36290. + }
  36291. +
  36292. + /* No block descriptors */
  36293. +
  36294. + /* The mode pages, in numerical order. The only page we support
  36295. + * is the Caching page. */
  36296. + if (page_code == 0x08 || all_pages) {
  36297. + valid_page = 1;
  36298. + buf[0] = 0x08; // Page code
  36299. + buf[1] = 10; // Page length
  36300. + memset(buf+2, 0, 10); // None of the fields are changeable
  36301. +
  36302. + if (!changeable_values) {
  36303. + buf[2] = 0x04; // Write cache enable,
  36304. + // Read cache not disabled
  36305. + // No cache retention priorities
  36306. + put_unaligned_be16(0xffff, &buf[4]);
  36307. + /* Don't disable prefetch */
  36308. + /* Minimum prefetch = 0 */
  36309. + put_unaligned_be16(0xffff, &buf[8]);
  36310. + /* Maximum prefetch */
  36311. + put_unaligned_be16(0xffff, &buf[10]);
  36312. + /* Maximum prefetch ceiling */
  36313. + }
  36314. + buf += 12;
  36315. + }
  36316. +
  36317. + /* Check that a valid page was requested and the mode data length
  36318. + * isn't too long. */
  36319. + len = buf - buf0;
  36320. + if (!valid_page || len > limit) {
  36321. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36322. + return -EINVAL;
  36323. + }
  36324. +
  36325. + /* Store the mode data length */
  36326. + if (mscmnd == MODE_SENSE)
  36327. + buf0[0] = len - 1;
  36328. + else
  36329. + put_unaligned_be16(len - 2, buf0);
  36330. + return len;
  36331. +}
  36332. +
  36333. +
  36334. +static int do_start_stop(struct fsg_dev *fsg)
  36335. +{
  36336. + struct fsg_lun *curlun = fsg->curlun;
  36337. + int loej, start;
  36338. +
  36339. + if (!mod_data.removable) {
  36340. + curlun->sense_data = SS_INVALID_COMMAND;
  36341. + return -EINVAL;
  36342. + }
  36343. +
  36344. + // int immed = fsg->cmnd[1] & 0x01;
  36345. + loej = fsg->cmnd[4] & 0x02;
  36346. + start = fsg->cmnd[4] & 0x01;
  36347. +
  36348. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36349. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  36350. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  36351. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36352. + return -EINVAL;
  36353. + }
  36354. +
  36355. + if (!start) {
  36356. +
  36357. + /* Are we allowed to unload the media? */
  36358. + if (curlun->prevent_medium_removal) {
  36359. + LDBG(curlun, "unload attempt prevented\n");
  36360. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  36361. + return -EINVAL;
  36362. + }
  36363. + if (loej) { // Simulate an unload/eject
  36364. + up_read(&fsg->filesem);
  36365. + down_write(&fsg->filesem);
  36366. + fsg_lun_close(curlun);
  36367. + up_write(&fsg->filesem);
  36368. + down_read(&fsg->filesem);
  36369. + }
  36370. + } else {
  36371. +
  36372. + /* Our emulation doesn't support mounting; the medium is
  36373. + * available for use as soon as it is loaded. */
  36374. + if (!fsg_lun_is_open(curlun)) {
  36375. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36376. + return -EINVAL;
  36377. + }
  36378. + }
  36379. +#endif
  36380. + return 0;
  36381. +}
  36382. +
  36383. +
  36384. +static int do_prevent_allow(struct fsg_dev *fsg)
  36385. +{
  36386. + struct fsg_lun *curlun = fsg->curlun;
  36387. + int prevent;
  36388. +
  36389. + if (!mod_data.removable) {
  36390. + curlun->sense_data = SS_INVALID_COMMAND;
  36391. + return -EINVAL;
  36392. + }
  36393. +
  36394. + prevent = fsg->cmnd[4] & 0x01;
  36395. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  36396. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36397. + return -EINVAL;
  36398. + }
  36399. +
  36400. + if (curlun->prevent_medium_removal && !prevent)
  36401. + fsg_lun_fsync_sub(curlun);
  36402. + curlun->prevent_medium_removal = prevent;
  36403. + return 0;
  36404. +}
  36405. +
  36406. +
  36407. +static int do_read_format_capacities(struct fsg_dev *fsg,
  36408. + struct fsg_buffhd *bh)
  36409. +{
  36410. + struct fsg_lun *curlun = fsg->curlun;
  36411. + u8 *buf = (u8 *) bh->buf;
  36412. +
  36413. + buf[0] = buf[1] = buf[2] = 0;
  36414. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  36415. + buf += 4;
  36416. +
  36417. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  36418. + /* Number of blocks */
  36419. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36420. + buf[4] = 0x02; /* Current capacity */
  36421. + return 12;
  36422. +}
  36423. +
  36424. +
  36425. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36426. +{
  36427. + struct fsg_lun *curlun = fsg->curlun;
  36428. +
  36429. + /* We don't support MODE SELECT */
  36430. + curlun->sense_data = SS_INVALID_COMMAND;
  36431. + return -EINVAL;
  36432. +}
  36433. +
  36434. +
  36435. +/*-------------------------------------------------------------------------*/
  36436. +
  36437. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  36438. +{
  36439. + int rc;
  36440. +
  36441. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  36442. + if (rc == -EAGAIN)
  36443. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  36444. + while (rc != 0) {
  36445. + if (rc != -EAGAIN) {
  36446. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  36447. + rc = 0;
  36448. + break;
  36449. + }
  36450. +
  36451. + /* Wait for a short time and then try again */
  36452. + if (msleep_interruptible(100) != 0)
  36453. + return -EINTR;
  36454. + rc = usb_ep_set_halt(fsg->bulk_in);
  36455. + }
  36456. + return rc;
  36457. +}
  36458. +
  36459. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  36460. +{
  36461. + int rc;
  36462. +
  36463. + DBG(fsg, "bulk-in set wedge\n");
  36464. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36465. + if (rc == -EAGAIN)
  36466. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  36467. + while (rc != 0) {
  36468. + if (rc != -EAGAIN) {
  36469. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  36470. + rc = 0;
  36471. + break;
  36472. + }
  36473. +
  36474. + /* Wait for a short time and then try again */
  36475. + if (msleep_interruptible(100) != 0)
  36476. + return -EINTR;
  36477. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36478. + }
  36479. + return rc;
  36480. +}
  36481. +
  36482. +static int throw_away_data(struct fsg_dev *fsg)
  36483. +{
  36484. + struct fsg_buffhd *bh;
  36485. + u32 amount;
  36486. + int rc;
  36487. +
  36488. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  36489. + fsg->usb_amount_left > 0) {
  36490. +
  36491. + /* Throw away the data in a filled buffer */
  36492. + if (bh->state == BUF_STATE_FULL) {
  36493. + smp_rmb();
  36494. + bh->state = BUF_STATE_EMPTY;
  36495. + fsg->next_buffhd_to_drain = bh->next;
  36496. +
  36497. + /* A short packet or an error ends everything */
  36498. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  36499. + bh->outreq->status != 0) {
  36500. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36501. + return -EINTR;
  36502. + }
  36503. + continue;
  36504. + }
  36505. +
  36506. + /* Try to submit another request if we need one */
  36507. + bh = fsg->next_buffhd_to_fill;
  36508. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  36509. + amount = min(fsg->usb_amount_left,
  36510. + (u32) mod_data.buflen);
  36511. +
  36512. + /* Except at the end of the transfer, amount will be
  36513. + * equal to the buffer size, which is divisible by
  36514. + * the bulk-out maxpacket size.
  36515. + */
  36516. + set_bulk_out_req_length(fsg, bh, amount);
  36517. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36518. + &bh->outreq_busy, &bh->state);
  36519. + fsg->next_buffhd_to_fill = bh->next;
  36520. + fsg->usb_amount_left -= amount;
  36521. + continue;
  36522. + }
  36523. +
  36524. + /* Otherwise wait for something to happen */
  36525. + rc = sleep_thread(fsg);
  36526. + if (rc)
  36527. + return rc;
  36528. + }
  36529. + return 0;
  36530. +}
  36531. +
  36532. +
  36533. +static int finish_reply(struct fsg_dev *fsg)
  36534. +{
  36535. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36536. + int rc = 0;
  36537. +
  36538. + switch (fsg->data_dir) {
  36539. + case DATA_DIR_NONE:
  36540. + break; // Nothing to send
  36541. +
  36542. + /* If we don't know whether the host wants to read or write,
  36543. + * this must be CB or CBI with an unknown command. We mustn't
  36544. + * try to send or receive any data. So stall both bulk pipes
  36545. + * if we can and wait for a reset. */
  36546. + case DATA_DIR_UNKNOWN:
  36547. + if (mod_data.can_stall) {
  36548. + fsg_set_halt(fsg, fsg->bulk_out);
  36549. + rc = halt_bulk_in_endpoint(fsg);
  36550. + }
  36551. + break;
  36552. +
  36553. + /* All but the last buffer of data must have already been sent */
  36554. + case DATA_DIR_TO_HOST:
  36555. + if (fsg->data_size == 0)
  36556. + ; // Nothing to send
  36557. +
  36558. + /* If there's no residue, simply send the last buffer */
  36559. + else if (fsg->residue == 0) {
  36560. + bh->inreq->zero = 0;
  36561. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36562. + &bh->inreq_busy, &bh->state);
  36563. + fsg->next_buffhd_to_fill = bh->next;
  36564. + }
  36565. +
  36566. + /* There is a residue. For CB and CBI, simply mark the end
  36567. + * of the data with a short packet. However, if we are
  36568. + * allowed to stall, there was no data at all (residue ==
  36569. + * data_size), and the command failed (invalid LUN or
  36570. + * sense data is set), then halt the bulk-in endpoint
  36571. + * instead. */
  36572. + else if (!transport_is_bbb()) {
  36573. + if (mod_data.can_stall &&
  36574. + fsg->residue == fsg->data_size &&
  36575. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  36576. + bh->state = BUF_STATE_EMPTY;
  36577. + rc = halt_bulk_in_endpoint(fsg);
  36578. + } else {
  36579. + bh->inreq->zero = 1;
  36580. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36581. + &bh->inreq_busy, &bh->state);
  36582. + fsg->next_buffhd_to_fill = bh->next;
  36583. + }
  36584. + }
  36585. +
  36586. + /*
  36587. + * For Bulk-only, mark the end of the data with a short
  36588. + * packet. If we are allowed to stall, halt the bulk-in
  36589. + * endpoint. (Note: This violates the Bulk-Only Transport
  36590. + * specification, which requires us to pad the data if we
  36591. + * don't halt the endpoint. Presumably nobody will mind.)
  36592. + */
  36593. + else {
  36594. + bh->inreq->zero = 1;
  36595. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36596. + &bh->inreq_busy, &bh->state);
  36597. + fsg->next_buffhd_to_fill = bh->next;
  36598. + if (mod_data.can_stall)
  36599. + rc = halt_bulk_in_endpoint(fsg);
  36600. + }
  36601. + break;
  36602. +
  36603. + /* We have processed all we want from the data the host has sent.
  36604. + * There may still be outstanding bulk-out requests. */
  36605. + case DATA_DIR_FROM_HOST:
  36606. + if (fsg->residue == 0)
  36607. + ; // Nothing to receive
  36608. +
  36609. + /* Did the host stop sending unexpectedly early? */
  36610. + else if (fsg->short_packet_received) {
  36611. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36612. + rc = -EINTR;
  36613. + }
  36614. +
  36615. + /* We haven't processed all the incoming data. Even though
  36616. + * we may be allowed to stall, doing so would cause a race.
  36617. + * The controller may already have ACK'ed all the remaining
  36618. + * bulk-out packets, in which case the host wouldn't see a
  36619. + * STALL. Not realizing the endpoint was halted, it wouldn't
  36620. + * clear the halt -- leading to problems later on. */
  36621. +#if 0
  36622. + else if (mod_data.can_stall) {
  36623. + fsg_set_halt(fsg, fsg->bulk_out);
  36624. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36625. + rc = -EINTR;
  36626. + }
  36627. +#endif
  36628. +
  36629. + /* We can't stall. Read in the excess data and throw it
  36630. + * all away. */
  36631. + else
  36632. + rc = throw_away_data(fsg);
  36633. + break;
  36634. + }
  36635. + return rc;
  36636. +}
  36637. +
  36638. +
  36639. +static int send_status(struct fsg_dev *fsg)
  36640. +{
  36641. + struct fsg_lun *curlun = fsg->curlun;
  36642. + struct fsg_buffhd *bh;
  36643. + int rc;
  36644. + u8 status = US_BULK_STAT_OK;
  36645. + u32 sd, sdinfo = 0;
  36646. +
  36647. + /* Wait for the next buffer to become available */
  36648. + bh = fsg->next_buffhd_to_fill;
  36649. + while (bh->state != BUF_STATE_EMPTY) {
  36650. + rc = sleep_thread(fsg);
  36651. + if (rc)
  36652. + return rc;
  36653. + }
  36654. +
  36655. + if (curlun) {
  36656. + sd = curlun->sense_data;
  36657. + sdinfo = curlun->sense_data_info;
  36658. + } else if (fsg->bad_lun_okay)
  36659. + sd = SS_NO_SENSE;
  36660. + else
  36661. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36662. +
  36663. + if (fsg->phase_error) {
  36664. + DBG(fsg, "sending phase-error status\n");
  36665. + status = US_BULK_STAT_PHASE;
  36666. + sd = SS_INVALID_COMMAND;
  36667. + } else if (sd != SS_NO_SENSE) {
  36668. + DBG(fsg, "sending command-failure status\n");
  36669. + status = US_BULK_STAT_FAIL;
  36670. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  36671. + " info x%x\n",
  36672. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  36673. + }
  36674. +
  36675. + if (transport_is_bbb()) {
  36676. + struct bulk_cs_wrap *csw = bh->buf;
  36677. +
  36678. + /* Store and send the Bulk-only CSW */
  36679. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  36680. + csw->Tag = fsg->tag;
  36681. + csw->Residue = cpu_to_le32(fsg->residue);
  36682. + csw->Status = status;
  36683. +
  36684. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  36685. + bh->inreq->zero = 0;
  36686. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36687. + &bh->inreq_busy, &bh->state);
  36688. +
  36689. + } else if (mod_data.transport_type == USB_PR_CB) {
  36690. +
  36691. + /* Control-Bulk transport has no status phase! */
  36692. + return 0;
  36693. +
  36694. + } else { // USB_PR_CBI
  36695. + struct interrupt_data *buf = bh->buf;
  36696. +
  36697. + /* Store and send the Interrupt data. UFI sends the ASC
  36698. + * and ASCQ bytes. Everything else sends a Type (which
  36699. + * is always 0) and the status Value. */
  36700. + if (mod_data.protocol_type == USB_SC_UFI) {
  36701. + buf->bType = ASC(sd);
  36702. + buf->bValue = ASCQ(sd);
  36703. + } else {
  36704. + buf->bType = 0;
  36705. + buf->bValue = status;
  36706. + }
  36707. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  36708. +
  36709. + fsg->intr_buffhd = bh; // Point to the right buffhd
  36710. + fsg->intreq->buf = bh->inreq->buf;
  36711. + fsg->intreq->context = bh;
  36712. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  36713. + &fsg->intreq_busy, &bh->state);
  36714. + }
  36715. +
  36716. + fsg->next_buffhd_to_fill = bh->next;
  36717. + return 0;
  36718. +}
  36719. +
  36720. +
  36721. +/*-------------------------------------------------------------------------*/
  36722. +
  36723. +/* Check whether the command is properly formed and whether its data size
  36724. + * and direction agree with the values we already have. */
  36725. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  36726. + enum data_direction data_dir, unsigned int mask,
  36727. + int needs_medium, const char *name)
  36728. +{
  36729. + int i;
  36730. + int lun = fsg->cmnd[1] >> 5;
  36731. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  36732. + char hdlen[20];
  36733. + struct fsg_lun *curlun;
  36734. +
  36735. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  36736. + * Transparent SCSI doesn't pad. */
  36737. + if (protocol_is_scsi())
  36738. + ;
  36739. +
  36740. + /* There's some disagreement as to whether RBC pads commands or not.
  36741. + * We'll play it safe and accept either form. */
  36742. + else if (mod_data.protocol_type == USB_SC_RBC) {
  36743. + if (fsg->cmnd_size == 12)
  36744. + cmnd_size = 12;
  36745. +
  36746. + /* All the other protocols pad to 12 bytes */
  36747. + } else
  36748. + cmnd_size = 12;
  36749. +
  36750. + hdlen[0] = 0;
  36751. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  36752. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  36753. + fsg->data_size);
  36754. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  36755. + name, cmnd_size, dirletter[(int) data_dir],
  36756. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  36757. +
  36758. + /* We can't reply at all until we know the correct data direction
  36759. + * and size. */
  36760. + if (fsg->data_size_from_cmnd == 0)
  36761. + data_dir = DATA_DIR_NONE;
  36762. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  36763. + fsg->data_dir = data_dir;
  36764. + fsg->data_size = fsg->data_size_from_cmnd;
  36765. +
  36766. + } else { // Bulk-only
  36767. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  36768. +
  36769. + /* Host data size < Device data size is a phase error.
  36770. + * Carry out the command, but only transfer as much
  36771. + * as we are allowed. */
  36772. + fsg->data_size_from_cmnd = fsg->data_size;
  36773. + fsg->phase_error = 1;
  36774. + }
  36775. + }
  36776. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  36777. +
  36778. + /* Conflicting data directions is a phase error */
  36779. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  36780. + fsg->phase_error = 1;
  36781. + return -EINVAL;
  36782. + }
  36783. +
  36784. + /* Verify the length of the command itself */
  36785. + if (cmnd_size != fsg->cmnd_size) {
  36786. +
  36787. + /* Special case workaround: There are plenty of buggy SCSI
  36788. + * implementations. Many have issues with cbw->Length
  36789. + * field passing a wrong command size. For those cases we
  36790. + * always try to work around the problem by using the length
  36791. + * sent by the host side provided it is at least as large
  36792. + * as the correct command length.
  36793. + * Examples of such cases would be MS-Windows, which issues
  36794. + * REQUEST SENSE with cbw->Length == 12 where it should
  36795. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  36796. + * REQUEST SENSE with cbw->Length == 10 where it should
  36797. + * be 6 as well.
  36798. + */
  36799. + if (cmnd_size <= fsg->cmnd_size) {
  36800. + DBG(fsg, "%s is buggy! Expected length %d "
  36801. + "but we got %d\n", name,
  36802. + cmnd_size, fsg->cmnd_size);
  36803. + cmnd_size = fsg->cmnd_size;
  36804. + } else {
  36805. + fsg->phase_error = 1;
  36806. + return -EINVAL;
  36807. + }
  36808. + }
  36809. +
  36810. + /* Check that the LUN values are consistent */
  36811. + if (transport_is_bbb()) {
  36812. + if (fsg->lun != lun)
  36813. + DBG(fsg, "using LUN %d from CBW, "
  36814. + "not LUN %d from CDB\n",
  36815. + fsg->lun, lun);
  36816. + }
  36817. +
  36818. + /* Check the LUN */
  36819. + curlun = fsg->curlun;
  36820. + if (curlun) {
  36821. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  36822. + curlun->sense_data = SS_NO_SENSE;
  36823. + curlun->sense_data_info = 0;
  36824. + curlun->info_valid = 0;
  36825. + }
  36826. + } else {
  36827. + fsg->bad_lun_okay = 0;
  36828. +
  36829. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  36830. + * to use unsupported LUNs; all others may not. */
  36831. + if (fsg->cmnd[0] != INQUIRY &&
  36832. + fsg->cmnd[0] != REQUEST_SENSE) {
  36833. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  36834. + return -EINVAL;
  36835. + }
  36836. + }
  36837. +
  36838. + /* If a unit attention condition exists, only INQUIRY and
  36839. + * REQUEST SENSE commands are allowed; anything else must fail. */
  36840. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  36841. + fsg->cmnd[0] != INQUIRY &&
  36842. + fsg->cmnd[0] != REQUEST_SENSE) {
  36843. + curlun->sense_data = curlun->unit_attention_data;
  36844. + curlun->unit_attention_data = SS_NO_SENSE;
  36845. + return -EINVAL;
  36846. + }
  36847. +
  36848. + /* Check that only command bytes listed in the mask are non-zero */
  36849. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  36850. + for (i = 1; i < cmnd_size; ++i) {
  36851. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  36852. + if (curlun)
  36853. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36854. + return -EINVAL;
  36855. + }
  36856. + }
  36857. +
  36858. + /* If the medium isn't mounted and the command needs to access
  36859. + * it, return an error. */
  36860. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  36861. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36862. + return -EINVAL;
  36863. + }
  36864. +
  36865. + return 0;
  36866. +}
  36867. +
  36868. +/* wrapper of check_command for data size in blocks handling */
  36869. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  36870. + enum data_direction data_dir, unsigned int mask,
  36871. + int needs_medium, const char *name)
  36872. +{
  36873. + if (fsg->curlun)
  36874. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  36875. + return check_command(fsg, cmnd_size, data_dir,
  36876. + mask, needs_medium, name);
  36877. +}
  36878. +
  36879. +static int do_scsi_command(struct fsg_dev *fsg)
  36880. +{
  36881. + struct fsg_buffhd *bh;
  36882. + int rc;
  36883. + int reply = -EINVAL;
  36884. + int i;
  36885. + static char unknown[16];
  36886. +
  36887. + dump_cdb(fsg);
  36888. +
  36889. + /* Wait for the next buffer to become available for data or status */
  36890. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  36891. + while (bh->state != BUF_STATE_EMPTY) {
  36892. + rc = sleep_thread(fsg);
  36893. + if (rc)
  36894. + return rc;
  36895. + }
  36896. + fsg->phase_error = 0;
  36897. + fsg->short_packet_received = 0;
  36898. +
  36899. + down_read(&fsg->filesem); // We're using the backing file
  36900. + switch (fsg->cmnd[0]) {
  36901. +
  36902. + case INQUIRY:
  36903. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36904. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36905. + (1<<4), 0,
  36906. + "INQUIRY")) == 0)
  36907. + reply = do_inquiry(fsg, bh);
  36908. + break;
  36909. +
  36910. + case MODE_SELECT:
  36911. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36912. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  36913. + (1<<1) | (1<<4), 0,
  36914. + "MODE SELECT(6)")) == 0)
  36915. + reply = do_mode_select(fsg, bh);
  36916. + break;
  36917. +
  36918. + case MODE_SELECT_10:
  36919. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36920. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  36921. + (1<<1) | (3<<7), 0,
  36922. + "MODE SELECT(10)")) == 0)
  36923. + reply = do_mode_select(fsg, bh);
  36924. + break;
  36925. +
  36926. + case MODE_SENSE:
  36927. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36928. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36929. + (1<<1) | (1<<2) | (1<<4), 0,
  36930. + "MODE SENSE(6)")) == 0)
  36931. + reply = do_mode_sense(fsg, bh);
  36932. + break;
  36933. +
  36934. + case MODE_SENSE_10:
  36935. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36936. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36937. + (1<<1) | (1<<2) | (3<<7), 0,
  36938. + "MODE SENSE(10)")) == 0)
  36939. + reply = do_mode_sense(fsg, bh);
  36940. + break;
  36941. +
  36942. + case ALLOW_MEDIUM_REMOVAL:
  36943. + fsg->data_size_from_cmnd = 0;
  36944. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  36945. + (1<<4), 0,
  36946. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  36947. + reply = do_prevent_allow(fsg);
  36948. + break;
  36949. +
  36950. + case READ_6:
  36951. + i = fsg->cmnd[4];
  36952. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  36953. + if ((reply = check_command_size_in_blocks(fsg, 6,
  36954. + DATA_DIR_TO_HOST,
  36955. + (7<<1) | (1<<4), 1,
  36956. + "READ(6)")) == 0)
  36957. + reply = do_read(fsg);
  36958. + break;
  36959. +
  36960. + case READ_10:
  36961. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36962. + if ((reply = check_command_size_in_blocks(fsg, 10,
  36963. + DATA_DIR_TO_HOST,
  36964. + (1<<1) | (0xf<<2) | (3<<7), 1,
  36965. + "READ(10)")) == 0)
  36966. + reply = do_read(fsg);
  36967. + break;
  36968. +
  36969. + case READ_12:
  36970. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  36971. + if ((reply = check_command_size_in_blocks(fsg, 12,
  36972. + DATA_DIR_TO_HOST,
  36973. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  36974. + "READ(12)")) == 0)
  36975. + reply = do_read(fsg);
  36976. + break;
  36977. +
  36978. + case READ_CAPACITY:
  36979. + fsg->data_size_from_cmnd = 8;
  36980. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36981. + (0xf<<2) | (1<<8), 1,
  36982. + "READ CAPACITY")) == 0)
  36983. + reply = do_read_capacity(fsg, bh);
  36984. + break;
  36985. +
  36986. + case READ_HEADER:
  36987. + if (!mod_data.cdrom)
  36988. + goto unknown_cmnd;
  36989. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36990. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36991. + (3<<7) | (0x1f<<1), 1,
  36992. + "READ HEADER")) == 0)
  36993. + reply = do_read_header(fsg, bh);
  36994. + break;
  36995. +
  36996. + case READ_TOC:
  36997. + if (!mod_data.cdrom)
  36998. + goto unknown_cmnd;
  36999. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37000. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37001. + (7<<6) | (1<<1), 1,
  37002. + "READ TOC")) == 0)
  37003. + reply = do_read_toc(fsg, bh);
  37004. + break;
  37005. +
  37006. + case READ_FORMAT_CAPACITIES:
  37007. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37008. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37009. + (3<<7), 1,
  37010. + "READ FORMAT CAPACITIES")) == 0)
  37011. + reply = do_read_format_capacities(fsg, bh);
  37012. + break;
  37013. +
  37014. + case REQUEST_SENSE:
  37015. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37016. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37017. + (1<<4), 0,
  37018. + "REQUEST SENSE")) == 0)
  37019. + reply = do_request_sense(fsg, bh);
  37020. + break;
  37021. +
  37022. + case START_STOP:
  37023. + fsg->data_size_from_cmnd = 0;
  37024. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37025. + (1<<1) | (1<<4), 0,
  37026. + "START-STOP UNIT")) == 0)
  37027. + reply = do_start_stop(fsg);
  37028. + break;
  37029. +
  37030. + case SYNCHRONIZE_CACHE:
  37031. + fsg->data_size_from_cmnd = 0;
  37032. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37033. + (0xf<<2) | (3<<7), 1,
  37034. + "SYNCHRONIZE CACHE")) == 0)
  37035. + reply = do_synchronize_cache(fsg);
  37036. + break;
  37037. +
  37038. + case TEST_UNIT_READY:
  37039. + fsg->data_size_from_cmnd = 0;
  37040. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  37041. + 0, 1,
  37042. + "TEST UNIT READY");
  37043. + break;
  37044. +
  37045. + /* Although optional, this command is used by MS-Windows. We
  37046. + * support a minimal version: BytChk must be 0. */
  37047. + case VERIFY:
  37048. + fsg->data_size_from_cmnd = 0;
  37049. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37050. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37051. + "VERIFY")) == 0)
  37052. + reply = do_verify(fsg);
  37053. + break;
  37054. +
  37055. + case WRITE_6:
  37056. + i = fsg->cmnd[4];
  37057. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37058. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37059. + DATA_DIR_FROM_HOST,
  37060. + (7<<1) | (1<<4), 1,
  37061. + "WRITE(6)")) == 0)
  37062. + reply = do_write(fsg);
  37063. + break;
  37064. +
  37065. + case WRITE_10:
  37066. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37067. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37068. + DATA_DIR_FROM_HOST,
  37069. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37070. + "WRITE(10)")) == 0)
  37071. + reply = do_write(fsg);
  37072. + break;
  37073. +
  37074. + case WRITE_12:
  37075. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37076. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37077. + DATA_DIR_FROM_HOST,
  37078. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37079. + "WRITE(12)")) == 0)
  37080. + reply = do_write(fsg);
  37081. + break;
  37082. +
  37083. + /* Some mandatory commands that we recognize but don't implement.
  37084. + * They don't mean much in this setting. It's left as an exercise
  37085. + * for anyone interested to implement RESERVE and RELEASE in terms
  37086. + * of Posix locks. */
  37087. + case FORMAT_UNIT:
  37088. + case RELEASE:
  37089. + case RESERVE:
  37090. + case SEND_DIAGNOSTIC:
  37091. + // Fall through
  37092. +
  37093. + default:
  37094. + unknown_cmnd:
  37095. + fsg->data_size_from_cmnd = 0;
  37096. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  37097. + if ((reply = check_command(fsg, fsg->cmnd_size,
  37098. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  37099. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  37100. + reply = -EINVAL;
  37101. + }
  37102. + break;
  37103. + }
  37104. + up_read(&fsg->filesem);
  37105. +
  37106. + if (reply == -EINTR || signal_pending(current))
  37107. + return -EINTR;
  37108. +
  37109. + /* Set up the single reply buffer for finish_reply() */
  37110. + if (reply == -EINVAL)
  37111. + reply = 0; // Error reply length
  37112. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  37113. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  37114. + bh->inreq->length = reply;
  37115. + bh->state = BUF_STATE_FULL;
  37116. + fsg->residue -= reply;
  37117. + } // Otherwise it's already set
  37118. +
  37119. + return 0;
  37120. +}
  37121. +
  37122. +
  37123. +/*-------------------------------------------------------------------------*/
  37124. +
  37125. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37126. +{
  37127. + struct usb_request *req = bh->outreq;
  37128. + struct bulk_cb_wrap *cbw = req->buf;
  37129. +
  37130. + /* Was this a real packet? Should it be ignored? */
  37131. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37132. + return -EINVAL;
  37133. +
  37134. + /* Is the CBW valid? */
  37135. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  37136. + cbw->Signature != cpu_to_le32(
  37137. + US_BULK_CB_SIGN)) {
  37138. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  37139. + req->actual,
  37140. + le32_to_cpu(cbw->Signature));
  37141. +
  37142. + /* The Bulk-only spec says we MUST stall the IN endpoint
  37143. + * (6.6.1), so it's unavoidable. It also says we must
  37144. + * retain this state until the next reset, but there's
  37145. + * no way to tell the controller driver it should ignore
  37146. + * Clear-Feature(HALT) requests.
  37147. + *
  37148. + * We aren't required to halt the OUT endpoint; instead
  37149. + * we can simply accept and discard any data received
  37150. + * until the next reset. */
  37151. + wedge_bulk_in_endpoint(fsg);
  37152. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37153. + return -EINVAL;
  37154. + }
  37155. +
  37156. + /* Is the CBW meaningful? */
  37157. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  37158. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  37159. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  37160. + "cmdlen %u\n",
  37161. + cbw->Lun, cbw->Flags, cbw->Length);
  37162. +
  37163. + /* We can do anything we want here, so let's stall the
  37164. + * bulk pipes if we are allowed to. */
  37165. + if (mod_data.can_stall) {
  37166. + fsg_set_halt(fsg, fsg->bulk_out);
  37167. + halt_bulk_in_endpoint(fsg);
  37168. + }
  37169. + return -EINVAL;
  37170. + }
  37171. +
  37172. + /* Save the command for later */
  37173. + fsg->cmnd_size = cbw->Length;
  37174. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  37175. + if (cbw->Flags & US_BULK_FLAG_IN)
  37176. + fsg->data_dir = DATA_DIR_TO_HOST;
  37177. + else
  37178. + fsg->data_dir = DATA_DIR_FROM_HOST;
  37179. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  37180. + if (fsg->data_size == 0)
  37181. + fsg->data_dir = DATA_DIR_NONE;
  37182. + fsg->lun = cbw->Lun;
  37183. + fsg->tag = cbw->Tag;
  37184. + return 0;
  37185. +}
  37186. +
  37187. +
  37188. +static int get_next_command(struct fsg_dev *fsg)
  37189. +{
  37190. + struct fsg_buffhd *bh;
  37191. + int rc = 0;
  37192. +
  37193. + if (transport_is_bbb()) {
  37194. +
  37195. + /* Wait for the next buffer to become available */
  37196. + bh = fsg->next_buffhd_to_fill;
  37197. + while (bh->state != BUF_STATE_EMPTY) {
  37198. + rc = sleep_thread(fsg);
  37199. + if (rc)
  37200. + return rc;
  37201. + }
  37202. +
  37203. + /* Queue a request to read a Bulk-only CBW */
  37204. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  37205. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37206. + &bh->outreq_busy, &bh->state);
  37207. +
  37208. + /* We will drain the buffer in software, which means we
  37209. + * can reuse it for the next filling. No need to advance
  37210. + * next_buffhd_to_fill. */
  37211. +
  37212. + /* Wait for the CBW to arrive */
  37213. + while (bh->state != BUF_STATE_FULL) {
  37214. + rc = sleep_thread(fsg);
  37215. + if (rc)
  37216. + return rc;
  37217. + }
  37218. + smp_rmb();
  37219. + rc = received_cbw(fsg, bh);
  37220. + bh->state = BUF_STATE_EMPTY;
  37221. +
  37222. + } else { // USB_PR_CB or USB_PR_CBI
  37223. +
  37224. + /* Wait for the next command to arrive */
  37225. + while (fsg->cbbuf_cmnd_size == 0) {
  37226. + rc = sleep_thread(fsg);
  37227. + if (rc)
  37228. + return rc;
  37229. + }
  37230. +
  37231. + /* Is the previous status interrupt request still busy?
  37232. + * The host is allowed to skip reading the status,
  37233. + * so we must cancel it. */
  37234. + if (fsg->intreq_busy)
  37235. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37236. +
  37237. + /* Copy the command and mark the buffer empty */
  37238. + fsg->data_dir = DATA_DIR_UNKNOWN;
  37239. + spin_lock_irq(&fsg->lock);
  37240. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  37241. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  37242. + fsg->cbbuf_cmnd_size = 0;
  37243. + spin_unlock_irq(&fsg->lock);
  37244. +
  37245. + /* Use LUN from the command */
  37246. + fsg->lun = fsg->cmnd[1] >> 5;
  37247. + }
  37248. +
  37249. + /* Update current lun */
  37250. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  37251. + fsg->curlun = &fsg->luns[fsg->lun];
  37252. + else
  37253. + fsg->curlun = NULL;
  37254. +
  37255. + return rc;
  37256. +}
  37257. +
  37258. +
  37259. +/*-------------------------------------------------------------------------*/
  37260. +
  37261. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  37262. + const struct usb_endpoint_descriptor *d)
  37263. +{
  37264. + int rc;
  37265. +
  37266. + ep->driver_data = fsg;
  37267. + ep->desc = d;
  37268. + rc = usb_ep_enable(ep);
  37269. + if (rc)
  37270. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  37271. + return rc;
  37272. +}
  37273. +
  37274. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  37275. + struct usb_request **preq)
  37276. +{
  37277. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  37278. + if (*preq)
  37279. + return 0;
  37280. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  37281. + return -ENOMEM;
  37282. +}
  37283. +
  37284. +/*
  37285. + * Reset interface setting and re-init endpoint state (toggle etc).
  37286. + * Call with altsetting < 0 to disable the interface. The only other
  37287. + * available altsetting is 0, which enables the interface.
  37288. + */
  37289. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  37290. +{
  37291. + int rc = 0;
  37292. + int i;
  37293. + const struct usb_endpoint_descriptor *d;
  37294. +
  37295. + if (fsg->running)
  37296. + DBG(fsg, "reset interface\n");
  37297. +
  37298. +reset:
  37299. + /* Deallocate the requests */
  37300. + for (i = 0; i < fsg_num_buffers; ++i) {
  37301. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37302. +
  37303. + if (bh->inreq) {
  37304. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  37305. + bh->inreq = NULL;
  37306. + }
  37307. + if (bh->outreq) {
  37308. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  37309. + bh->outreq = NULL;
  37310. + }
  37311. + }
  37312. + if (fsg->intreq) {
  37313. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  37314. + fsg->intreq = NULL;
  37315. + }
  37316. +
  37317. + /* Disable the endpoints */
  37318. + if (fsg->bulk_in_enabled) {
  37319. + usb_ep_disable(fsg->bulk_in);
  37320. + fsg->bulk_in_enabled = 0;
  37321. + }
  37322. + if (fsg->bulk_out_enabled) {
  37323. + usb_ep_disable(fsg->bulk_out);
  37324. + fsg->bulk_out_enabled = 0;
  37325. + }
  37326. + if (fsg->intr_in_enabled) {
  37327. + usb_ep_disable(fsg->intr_in);
  37328. + fsg->intr_in_enabled = 0;
  37329. + }
  37330. +
  37331. + fsg->running = 0;
  37332. + if (altsetting < 0 || rc != 0)
  37333. + return rc;
  37334. +
  37335. + DBG(fsg, "set interface %d\n", altsetting);
  37336. +
  37337. + /* Enable the endpoints */
  37338. + d = fsg_ep_desc(fsg->gadget,
  37339. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  37340. + &fsg_ss_bulk_in_desc);
  37341. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  37342. + goto reset;
  37343. + fsg->bulk_in_enabled = 1;
  37344. +
  37345. + d = fsg_ep_desc(fsg->gadget,
  37346. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  37347. + &fsg_ss_bulk_out_desc);
  37348. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  37349. + goto reset;
  37350. + fsg->bulk_out_enabled = 1;
  37351. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  37352. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37353. +
  37354. + if (transport_is_cbi()) {
  37355. + d = fsg_ep_desc(fsg->gadget,
  37356. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  37357. + &fsg_ss_intr_in_desc);
  37358. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  37359. + goto reset;
  37360. + fsg->intr_in_enabled = 1;
  37361. + }
  37362. +
  37363. + /* Allocate the requests */
  37364. + for (i = 0; i < fsg_num_buffers; ++i) {
  37365. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37366. +
  37367. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  37368. + goto reset;
  37369. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  37370. + goto reset;
  37371. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  37372. + bh->inreq->context = bh->outreq->context = bh;
  37373. + bh->inreq->complete = bulk_in_complete;
  37374. + bh->outreq->complete = bulk_out_complete;
  37375. + }
  37376. + if (transport_is_cbi()) {
  37377. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  37378. + goto reset;
  37379. + fsg->intreq->complete = intr_in_complete;
  37380. + }
  37381. +
  37382. + fsg->running = 1;
  37383. + for (i = 0; i < fsg->nluns; ++i)
  37384. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37385. + return rc;
  37386. +}
  37387. +
  37388. +
  37389. +/*
  37390. + * Change our operational configuration. This code must agree with the code
  37391. + * that returns config descriptors, and with interface altsetting code.
  37392. + *
  37393. + * It's also responsible for power management interactions. Some
  37394. + * configurations might not work with our current power sources.
  37395. + * For now we just assume the gadget is always self-powered.
  37396. + */
  37397. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  37398. +{
  37399. + int rc = 0;
  37400. +
  37401. + /* Disable the single interface */
  37402. + if (fsg->config != 0) {
  37403. + DBG(fsg, "reset config\n");
  37404. + fsg->config = 0;
  37405. + rc = do_set_interface(fsg, -1);
  37406. + }
  37407. +
  37408. + /* Enable the interface */
  37409. + if (new_config != 0) {
  37410. + fsg->config = new_config;
  37411. + if ((rc = do_set_interface(fsg, 0)) != 0)
  37412. + fsg->config = 0; // Reset on errors
  37413. + else
  37414. + INFO(fsg, "%s config #%d\n",
  37415. + usb_speed_string(fsg->gadget->speed),
  37416. + fsg->config);
  37417. + }
  37418. + return rc;
  37419. +}
  37420. +
  37421. +
  37422. +/*-------------------------------------------------------------------------*/
  37423. +
  37424. +static void handle_exception(struct fsg_dev *fsg)
  37425. +{
  37426. + siginfo_t info;
  37427. + int sig;
  37428. + int i;
  37429. + int num_active;
  37430. + struct fsg_buffhd *bh;
  37431. + enum fsg_state old_state;
  37432. + u8 new_config;
  37433. + struct fsg_lun *curlun;
  37434. + unsigned int exception_req_tag;
  37435. + int rc;
  37436. +
  37437. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  37438. + * into a high-priority EXIT exception. */
  37439. + for (;;) {
  37440. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  37441. + if (!sig)
  37442. + break;
  37443. + if (sig != SIGUSR1) {
  37444. + if (fsg->state < FSG_STATE_EXIT)
  37445. + DBG(fsg, "Main thread exiting on signal\n");
  37446. + raise_exception(fsg, FSG_STATE_EXIT);
  37447. + }
  37448. + }
  37449. +
  37450. + /* Cancel all the pending transfers */
  37451. + if (fsg->intreq_busy)
  37452. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37453. + for (i = 0; i < fsg_num_buffers; ++i) {
  37454. + bh = &fsg->buffhds[i];
  37455. + if (bh->inreq_busy)
  37456. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  37457. + if (bh->outreq_busy)
  37458. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  37459. + }
  37460. +
  37461. + /* Wait until everything is idle */
  37462. + for (;;) {
  37463. + num_active = fsg->intreq_busy;
  37464. + for (i = 0; i < fsg_num_buffers; ++i) {
  37465. + bh = &fsg->buffhds[i];
  37466. + num_active += bh->inreq_busy + bh->outreq_busy;
  37467. + }
  37468. + if (num_active == 0)
  37469. + break;
  37470. + if (sleep_thread(fsg))
  37471. + return;
  37472. + }
  37473. +
  37474. + /* Clear out the controller's fifos */
  37475. + if (fsg->bulk_in_enabled)
  37476. + usb_ep_fifo_flush(fsg->bulk_in);
  37477. + if (fsg->bulk_out_enabled)
  37478. + usb_ep_fifo_flush(fsg->bulk_out);
  37479. + if (fsg->intr_in_enabled)
  37480. + usb_ep_fifo_flush(fsg->intr_in);
  37481. +
  37482. + /* Reset the I/O buffer states and pointers, the SCSI
  37483. + * state, and the exception. Then invoke the handler. */
  37484. + spin_lock_irq(&fsg->lock);
  37485. +
  37486. + for (i = 0; i < fsg_num_buffers; ++i) {
  37487. + bh = &fsg->buffhds[i];
  37488. + bh->state = BUF_STATE_EMPTY;
  37489. + }
  37490. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  37491. + &fsg->buffhds[0];
  37492. +
  37493. + exception_req_tag = fsg->exception_req_tag;
  37494. + new_config = fsg->new_config;
  37495. + old_state = fsg->state;
  37496. +
  37497. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  37498. + fsg->state = FSG_STATE_STATUS_PHASE;
  37499. + else {
  37500. + for (i = 0; i < fsg->nluns; ++i) {
  37501. + curlun = &fsg->luns[i];
  37502. + curlun->prevent_medium_removal = 0;
  37503. + curlun->sense_data = curlun->unit_attention_data =
  37504. + SS_NO_SENSE;
  37505. + curlun->sense_data_info = 0;
  37506. + curlun->info_valid = 0;
  37507. + }
  37508. + fsg->state = FSG_STATE_IDLE;
  37509. + }
  37510. + spin_unlock_irq(&fsg->lock);
  37511. +
  37512. + /* Carry out any extra actions required for the exception */
  37513. + switch (old_state) {
  37514. + default:
  37515. + break;
  37516. +
  37517. + case FSG_STATE_ABORT_BULK_OUT:
  37518. + send_status(fsg);
  37519. + spin_lock_irq(&fsg->lock);
  37520. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  37521. + fsg->state = FSG_STATE_IDLE;
  37522. + spin_unlock_irq(&fsg->lock);
  37523. + break;
  37524. +
  37525. + case FSG_STATE_RESET:
  37526. + /* In case we were forced against our will to halt a
  37527. + * bulk endpoint, clear the halt now. (The SuperH UDC
  37528. + * requires this.) */
  37529. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37530. + usb_ep_clear_halt(fsg->bulk_in);
  37531. +
  37532. + if (transport_is_bbb()) {
  37533. + if (fsg->ep0_req_tag == exception_req_tag)
  37534. + ep0_queue(fsg); // Complete the status stage
  37535. +
  37536. + } else if (transport_is_cbi())
  37537. + send_status(fsg); // Status by interrupt pipe
  37538. +
  37539. + /* Technically this should go here, but it would only be
  37540. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  37541. + * CONFIG_CHANGE cases. */
  37542. + // for (i = 0; i < fsg->nluns; ++i)
  37543. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37544. + break;
  37545. +
  37546. + case FSG_STATE_INTERFACE_CHANGE:
  37547. + rc = do_set_interface(fsg, 0);
  37548. + if (fsg->ep0_req_tag != exception_req_tag)
  37549. + break;
  37550. + if (rc != 0) // STALL on errors
  37551. + fsg_set_halt(fsg, fsg->ep0);
  37552. + else // Complete the status stage
  37553. + ep0_queue(fsg);
  37554. + break;
  37555. +
  37556. + case FSG_STATE_CONFIG_CHANGE:
  37557. + rc = do_set_config(fsg, new_config);
  37558. + if (fsg->ep0_req_tag != exception_req_tag)
  37559. + break;
  37560. + if (rc != 0) // STALL on errors
  37561. + fsg_set_halt(fsg, fsg->ep0);
  37562. + else // Complete the status stage
  37563. + ep0_queue(fsg);
  37564. + break;
  37565. +
  37566. + case FSG_STATE_DISCONNECT:
  37567. + for (i = 0; i < fsg->nluns; ++i)
  37568. + fsg_lun_fsync_sub(fsg->luns + i);
  37569. + do_set_config(fsg, 0); // Unconfigured state
  37570. + break;
  37571. +
  37572. + case FSG_STATE_EXIT:
  37573. + case FSG_STATE_TERMINATED:
  37574. + do_set_config(fsg, 0); // Free resources
  37575. + spin_lock_irq(&fsg->lock);
  37576. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  37577. + spin_unlock_irq(&fsg->lock);
  37578. + break;
  37579. + }
  37580. +}
  37581. +
  37582. +
  37583. +/*-------------------------------------------------------------------------*/
  37584. +
  37585. +static int fsg_main_thread(void *fsg_)
  37586. +{
  37587. + struct fsg_dev *fsg = fsg_;
  37588. +
  37589. + /* Allow the thread to be killed by a signal, but set the signal mask
  37590. + * to block everything but INT, TERM, KILL, and USR1. */
  37591. + allow_signal(SIGINT);
  37592. + allow_signal(SIGTERM);
  37593. + allow_signal(SIGKILL);
  37594. + allow_signal(SIGUSR1);
  37595. +
  37596. + /* Allow the thread to be frozen */
  37597. + set_freezable();
  37598. +
  37599. + /* Arrange for userspace references to be interpreted as kernel
  37600. + * pointers. That way we can pass a kernel pointer to a routine
  37601. + * that expects a __user pointer and it will work okay. */
  37602. + set_fs(get_ds());
  37603. +
  37604. + /* The main loop */
  37605. + while (fsg->state != FSG_STATE_TERMINATED) {
  37606. + if (exception_in_progress(fsg) || signal_pending(current)) {
  37607. + handle_exception(fsg);
  37608. + continue;
  37609. + }
  37610. +
  37611. + if (!fsg->running) {
  37612. + sleep_thread(fsg);
  37613. + continue;
  37614. + }
  37615. +
  37616. + if (get_next_command(fsg))
  37617. + continue;
  37618. +
  37619. + spin_lock_irq(&fsg->lock);
  37620. + if (!exception_in_progress(fsg))
  37621. + fsg->state = FSG_STATE_DATA_PHASE;
  37622. + spin_unlock_irq(&fsg->lock);
  37623. +
  37624. + if (do_scsi_command(fsg) || finish_reply(fsg))
  37625. + continue;
  37626. +
  37627. + spin_lock_irq(&fsg->lock);
  37628. + if (!exception_in_progress(fsg))
  37629. + fsg->state = FSG_STATE_STATUS_PHASE;
  37630. + spin_unlock_irq(&fsg->lock);
  37631. +
  37632. + if (send_status(fsg))
  37633. + continue;
  37634. +
  37635. + spin_lock_irq(&fsg->lock);
  37636. + if (!exception_in_progress(fsg))
  37637. + fsg->state = FSG_STATE_IDLE;
  37638. + spin_unlock_irq(&fsg->lock);
  37639. + }
  37640. +
  37641. + spin_lock_irq(&fsg->lock);
  37642. + fsg->thread_task = NULL;
  37643. + spin_unlock_irq(&fsg->lock);
  37644. +
  37645. + /* If we are exiting because of a signal, unregister the
  37646. + * gadget driver. */
  37647. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  37648. + usb_gadget_unregister_driver(&fsg_driver);
  37649. +
  37650. + /* Let the unbind and cleanup routines know the thread has exited */
  37651. + complete_and_exit(&fsg->thread_notifier, 0);
  37652. +}
  37653. +
  37654. +
  37655. +/*-------------------------------------------------------------------------*/
  37656. +
  37657. +
  37658. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  37659. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  37660. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  37661. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  37662. +
  37663. +
  37664. +/*-------------------------------------------------------------------------*/
  37665. +
  37666. +static void fsg_release(struct kref *ref)
  37667. +{
  37668. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  37669. +
  37670. + kfree(fsg->luns);
  37671. + kfree(fsg);
  37672. +}
  37673. +
  37674. +static void lun_release(struct device *dev)
  37675. +{
  37676. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  37677. + struct fsg_dev *fsg =
  37678. + container_of(filesem, struct fsg_dev, filesem);
  37679. +
  37680. + kref_put(&fsg->ref, fsg_release);
  37681. +}
  37682. +
  37683. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  37684. +{
  37685. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37686. + int i;
  37687. + struct fsg_lun *curlun;
  37688. + struct usb_request *req = fsg->ep0req;
  37689. +
  37690. + DBG(fsg, "unbind\n");
  37691. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  37692. +
  37693. + /* If the thread isn't already dead, tell it to exit now */
  37694. + if (fsg->state != FSG_STATE_TERMINATED) {
  37695. + raise_exception(fsg, FSG_STATE_EXIT);
  37696. + wait_for_completion(&fsg->thread_notifier);
  37697. +
  37698. + /* The cleanup routine waits for this completion also */
  37699. + complete(&fsg->thread_notifier);
  37700. + }
  37701. +
  37702. + /* Unregister the sysfs attribute files and the LUNs */
  37703. + for (i = 0; i < fsg->nluns; ++i) {
  37704. + curlun = &fsg->luns[i];
  37705. + if (curlun->registered) {
  37706. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  37707. + device_remove_file(&curlun->dev, &dev_attr_ro);
  37708. + device_remove_file(&curlun->dev, &dev_attr_file);
  37709. + fsg_lun_close(curlun);
  37710. + device_unregister(&curlun->dev);
  37711. + curlun->registered = 0;
  37712. + }
  37713. + }
  37714. +
  37715. + /* Free the data buffers */
  37716. + for (i = 0; i < fsg_num_buffers; ++i)
  37717. + kfree(fsg->buffhds[i].buf);
  37718. +
  37719. + /* Free the request and buffer for endpoint 0 */
  37720. + if (req) {
  37721. + kfree(req->buf);
  37722. + usb_ep_free_request(fsg->ep0, req);
  37723. + }
  37724. +
  37725. + set_gadget_data(gadget, NULL);
  37726. +}
  37727. +
  37728. +
  37729. +static int __init check_parameters(struct fsg_dev *fsg)
  37730. +{
  37731. + int prot;
  37732. + int gcnum;
  37733. +
  37734. + /* Store the default values */
  37735. + mod_data.transport_type = USB_PR_BULK;
  37736. + mod_data.transport_name = "Bulk-only";
  37737. + mod_data.protocol_type = USB_SC_SCSI;
  37738. + mod_data.protocol_name = "Transparent SCSI";
  37739. +
  37740. + /* Some peripheral controllers are known not to be able to
  37741. + * halt bulk endpoints correctly. If one of them is present,
  37742. + * disable stalls.
  37743. + */
  37744. + if (gadget_is_at91(fsg->gadget))
  37745. + mod_data.can_stall = 0;
  37746. +
  37747. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  37748. + gcnum = usb_gadget_controller_number(fsg->gadget);
  37749. + if (gcnum >= 0)
  37750. + mod_data.release = 0x0300 + gcnum;
  37751. + else {
  37752. + WARNING(fsg, "controller '%s' not recognized\n",
  37753. + fsg->gadget->name);
  37754. + mod_data.release = 0x0399;
  37755. + }
  37756. + }
  37757. +
  37758. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  37759. +
  37760. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37761. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  37762. + ; // Use default setting
  37763. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  37764. + mod_data.transport_type = USB_PR_CB;
  37765. + mod_data.transport_name = "Control-Bulk";
  37766. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  37767. + mod_data.transport_type = USB_PR_CBI;
  37768. + mod_data.transport_name = "Control-Bulk-Interrupt";
  37769. + } else {
  37770. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  37771. + return -EINVAL;
  37772. + }
  37773. +
  37774. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  37775. + prot == USB_SC_SCSI) {
  37776. + ; // Use default setting
  37777. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  37778. + prot == USB_SC_RBC) {
  37779. + mod_data.protocol_type = USB_SC_RBC;
  37780. + mod_data.protocol_name = "RBC";
  37781. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  37782. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  37783. + prot == USB_SC_8020) {
  37784. + mod_data.protocol_type = USB_SC_8020;
  37785. + mod_data.protocol_name = "8020i (ATAPI)";
  37786. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  37787. + prot == USB_SC_QIC) {
  37788. + mod_data.protocol_type = USB_SC_QIC;
  37789. + mod_data.protocol_name = "QIC-157";
  37790. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  37791. + prot == USB_SC_UFI) {
  37792. + mod_data.protocol_type = USB_SC_UFI;
  37793. + mod_data.protocol_name = "UFI";
  37794. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  37795. + prot == USB_SC_8070) {
  37796. + mod_data.protocol_type = USB_SC_8070;
  37797. + mod_data.protocol_name = "8070i";
  37798. + } else {
  37799. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  37800. + return -EINVAL;
  37801. + }
  37802. +
  37803. + mod_data.buflen &= PAGE_CACHE_MASK;
  37804. + if (mod_data.buflen <= 0) {
  37805. + ERROR(fsg, "invalid buflen\n");
  37806. + return -ETOOSMALL;
  37807. + }
  37808. +
  37809. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37810. +
  37811. + /* Serial string handling.
  37812. + * On a real device, the serial string would be loaded
  37813. + * from permanent storage. */
  37814. + if (mod_data.serial) {
  37815. + const char *ch;
  37816. + unsigned len = 0;
  37817. +
  37818. + /* Sanity check :
  37819. + * The CB[I] specification limits the serial string to
  37820. + * 12 uppercase hexadecimal characters.
  37821. + * BBB need at least 12 uppercase hexadecimal characters,
  37822. + * with a maximum of 126. */
  37823. + for (ch = mod_data.serial; *ch; ++ch) {
  37824. + ++len;
  37825. + if ((*ch < '0' || *ch > '9') &&
  37826. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  37827. + WARNING(fsg,
  37828. + "Invalid serial string character: %c\n",
  37829. + *ch);
  37830. + goto no_serial;
  37831. + }
  37832. + }
  37833. + if (len > 126 ||
  37834. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  37835. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  37836. + WARNING(fsg, "Invalid serial string length!\n");
  37837. + goto no_serial;
  37838. + }
  37839. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  37840. + } else {
  37841. + WARNING(fsg, "No serial-number string provided!\n");
  37842. + no_serial:
  37843. + device_desc.iSerialNumber = 0;
  37844. + }
  37845. +
  37846. + return 0;
  37847. +}
  37848. +
  37849. +
  37850. +static int __init fsg_bind(struct usb_gadget *gadget)
  37851. +{
  37852. + struct fsg_dev *fsg = the_fsg;
  37853. + int rc;
  37854. + int i;
  37855. + struct fsg_lun *curlun;
  37856. + struct usb_ep *ep;
  37857. + struct usb_request *req;
  37858. + char *pathbuf, *p;
  37859. +
  37860. + fsg->gadget = gadget;
  37861. + set_gadget_data(gadget, fsg);
  37862. + fsg->ep0 = gadget->ep0;
  37863. + fsg->ep0->driver_data = fsg;
  37864. +
  37865. + if ((rc = check_parameters(fsg)) != 0)
  37866. + goto out;
  37867. +
  37868. + if (mod_data.removable) { // Enable the store_xxx attributes
  37869. + dev_attr_file.attr.mode = 0644;
  37870. + dev_attr_file.store = fsg_store_file;
  37871. + if (!mod_data.cdrom) {
  37872. + dev_attr_ro.attr.mode = 0644;
  37873. + dev_attr_ro.store = fsg_store_ro;
  37874. + }
  37875. + }
  37876. +
  37877. + /* Only for removable media? */
  37878. + dev_attr_nofua.attr.mode = 0644;
  37879. + dev_attr_nofua.store = fsg_store_nofua;
  37880. +
  37881. + /* Find out how many LUNs there should be */
  37882. + i = mod_data.nluns;
  37883. + if (i == 0)
  37884. + i = max(mod_data.num_filenames, 1u);
  37885. + if (i > FSG_MAX_LUNS) {
  37886. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  37887. + rc = -EINVAL;
  37888. + goto out;
  37889. + }
  37890. +
  37891. + /* Create the LUNs, open their backing files, and register the
  37892. + * LUN devices in sysfs. */
  37893. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  37894. + if (!fsg->luns) {
  37895. + rc = -ENOMEM;
  37896. + goto out;
  37897. + }
  37898. + fsg->nluns = i;
  37899. +
  37900. + for (i = 0; i < fsg->nluns; ++i) {
  37901. + curlun = &fsg->luns[i];
  37902. + curlun->cdrom = !!mod_data.cdrom;
  37903. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  37904. + curlun->initially_ro = curlun->ro;
  37905. + curlun->removable = mod_data.removable;
  37906. + curlun->nofua = mod_data.nofua[i];
  37907. + curlun->dev.release = lun_release;
  37908. + curlun->dev.parent = &gadget->dev;
  37909. + curlun->dev.driver = &fsg_driver.driver;
  37910. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  37911. + dev_set_name(&curlun->dev,"%s-lun%d",
  37912. + dev_name(&gadget->dev), i);
  37913. +
  37914. + kref_get(&fsg->ref);
  37915. + rc = device_register(&curlun->dev);
  37916. + if (rc) {
  37917. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  37918. + put_device(&curlun->dev);
  37919. + goto out;
  37920. + }
  37921. + curlun->registered = 1;
  37922. +
  37923. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  37924. + if (rc)
  37925. + goto out;
  37926. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  37927. + if (rc)
  37928. + goto out;
  37929. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  37930. + if (rc)
  37931. + goto out;
  37932. +
  37933. + if (mod_data.file[i] && *mod_data.file[i]) {
  37934. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  37935. + if (rc)
  37936. + goto out;
  37937. + } else if (!mod_data.removable) {
  37938. + ERROR(fsg, "no file given for LUN%d\n", i);
  37939. + rc = -EINVAL;
  37940. + goto out;
  37941. + }
  37942. + }
  37943. +
  37944. + /* Find all the endpoints we will use */
  37945. + usb_ep_autoconfig_reset(gadget);
  37946. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  37947. + if (!ep)
  37948. + goto autoconf_fail;
  37949. + ep->driver_data = fsg; // claim the endpoint
  37950. + fsg->bulk_in = ep;
  37951. +
  37952. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  37953. + if (!ep)
  37954. + goto autoconf_fail;
  37955. + ep->driver_data = fsg; // claim the endpoint
  37956. + fsg->bulk_out = ep;
  37957. +
  37958. + if (transport_is_cbi()) {
  37959. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  37960. + if (!ep)
  37961. + goto autoconf_fail;
  37962. + ep->driver_data = fsg; // claim the endpoint
  37963. + fsg->intr_in = ep;
  37964. + }
  37965. +
  37966. + /* Fix up the descriptors */
  37967. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  37968. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  37969. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  37970. +
  37971. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  37972. + fsg_intf_desc.bNumEndpoints = i;
  37973. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  37974. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  37975. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37976. +
  37977. + if (gadget_is_dualspeed(gadget)) {
  37978. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37979. +
  37980. + /* Assume endpoint addresses are the same for both speeds */
  37981. + fsg_hs_bulk_in_desc.bEndpointAddress =
  37982. + fsg_fs_bulk_in_desc.bEndpointAddress;
  37983. + fsg_hs_bulk_out_desc.bEndpointAddress =
  37984. + fsg_fs_bulk_out_desc.bEndpointAddress;
  37985. + fsg_hs_intr_in_desc.bEndpointAddress =
  37986. + fsg_fs_intr_in_desc.bEndpointAddress;
  37987. + }
  37988. +
  37989. + if (gadget_is_superspeed(gadget)) {
  37990. + unsigned max_burst;
  37991. +
  37992. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37993. +
  37994. + /* Calculate bMaxBurst, we know packet size is 1024 */
  37995. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  37996. +
  37997. + /* Assume endpoint addresses are the same for both speeds */
  37998. + fsg_ss_bulk_in_desc.bEndpointAddress =
  37999. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38000. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  38001. +
  38002. + fsg_ss_bulk_out_desc.bEndpointAddress =
  38003. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38004. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  38005. + }
  38006. +
  38007. + if (gadget_is_otg(gadget))
  38008. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  38009. +
  38010. + rc = -ENOMEM;
  38011. +
  38012. + /* Allocate the request and buffer for endpoint 0 */
  38013. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  38014. + if (!req)
  38015. + goto out;
  38016. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  38017. + if (!req->buf)
  38018. + goto out;
  38019. + req->complete = ep0_complete;
  38020. +
  38021. + /* Allocate the data buffers */
  38022. + for (i = 0; i < fsg_num_buffers; ++i) {
  38023. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38024. +
  38025. + /* Allocate for the bulk-in endpoint. We assume that
  38026. + * the buffer will also work with the bulk-out (and
  38027. + * interrupt-in) endpoint. */
  38028. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  38029. + if (!bh->buf)
  38030. + goto out;
  38031. + bh->next = bh + 1;
  38032. + }
  38033. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  38034. +
  38035. + /* This should reflect the actual gadget power source */
  38036. + usb_gadget_set_selfpowered(gadget);
  38037. +
  38038. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  38039. + "%s %s with %s",
  38040. + init_utsname()->sysname, init_utsname()->release,
  38041. + gadget->name);
  38042. +
  38043. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  38044. + "file-storage-gadget");
  38045. + if (IS_ERR(fsg->thread_task)) {
  38046. + rc = PTR_ERR(fsg->thread_task);
  38047. + goto out;
  38048. + }
  38049. +
  38050. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  38051. + INFO(fsg, "NOTE: This driver is deprecated. "
  38052. + "Consider using g_mass_storage instead.\n");
  38053. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  38054. +
  38055. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  38056. + for (i = 0; i < fsg->nluns; ++i) {
  38057. + curlun = &fsg->luns[i];
  38058. + if (fsg_lun_is_open(curlun)) {
  38059. + p = NULL;
  38060. + if (pathbuf) {
  38061. + p = d_path(&curlun->filp->f_path,
  38062. + pathbuf, PATH_MAX);
  38063. + if (IS_ERR(p))
  38064. + p = NULL;
  38065. + }
  38066. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  38067. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  38068. + }
  38069. + }
  38070. + kfree(pathbuf);
  38071. +
  38072. + DBG(fsg, "transport=%s (x%02x)\n",
  38073. + mod_data.transport_name, mod_data.transport_type);
  38074. + DBG(fsg, "protocol=%s (x%02x)\n",
  38075. + mod_data.protocol_name, mod_data.protocol_type);
  38076. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  38077. + mod_data.vendor, mod_data.product, mod_data.release);
  38078. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  38079. + mod_data.removable, mod_data.can_stall,
  38080. + mod_data.cdrom, mod_data.buflen);
  38081. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  38082. +
  38083. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  38084. +
  38085. + /* Tell the thread to start working */
  38086. + wake_up_process(fsg->thread_task);
  38087. + return 0;
  38088. +
  38089. +autoconf_fail:
  38090. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  38091. + rc = -ENOTSUPP;
  38092. +
  38093. +out:
  38094. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  38095. + fsg_unbind(gadget);
  38096. + complete(&fsg->thread_notifier);
  38097. + return rc;
  38098. +}
  38099. +
  38100. +
  38101. +/*-------------------------------------------------------------------------*/
  38102. +
  38103. +static void fsg_suspend(struct usb_gadget *gadget)
  38104. +{
  38105. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38106. +
  38107. + DBG(fsg, "suspend\n");
  38108. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  38109. +}
  38110. +
  38111. +static void fsg_resume(struct usb_gadget *gadget)
  38112. +{
  38113. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38114. +
  38115. + DBG(fsg, "resume\n");
  38116. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  38117. +}
  38118. +
  38119. +
  38120. +/*-------------------------------------------------------------------------*/
  38121. +
  38122. +static struct usb_gadget_driver fsg_driver = {
  38123. + .max_speed = USB_SPEED_SUPER,
  38124. + .function = (char *) fsg_string_product,
  38125. + .unbind = fsg_unbind,
  38126. + .disconnect = fsg_disconnect,
  38127. + .setup = fsg_setup,
  38128. + .suspend = fsg_suspend,
  38129. + .resume = fsg_resume,
  38130. +
  38131. + .driver = {
  38132. + .name = DRIVER_NAME,
  38133. + .owner = THIS_MODULE,
  38134. + // .release = ...
  38135. + // .suspend = ...
  38136. + // .resume = ...
  38137. + },
  38138. +};
  38139. +
  38140. +
  38141. +static int __init fsg_alloc(void)
  38142. +{
  38143. + struct fsg_dev *fsg;
  38144. +
  38145. + fsg = kzalloc(sizeof *fsg +
  38146. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  38147. +
  38148. + if (!fsg)
  38149. + return -ENOMEM;
  38150. + spin_lock_init(&fsg->lock);
  38151. + init_rwsem(&fsg->filesem);
  38152. + kref_init(&fsg->ref);
  38153. + init_completion(&fsg->thread_notifier);
  38154. +
  38155. + the_fsg = fsg;
  38156. + return 0;
  38157. +}
  38158. +
  38159. +
  38160. +static int __init fsg_init(void)
  38161. +{
  38162. + int rc;
  38163. + struct fsg_dev *fsg;
  38164. +
  38165. + rc = fsg_num_buffers_validate();
  38166. + if (rc != 0)
  38167. + return rc;
  38168. +
  38169. + if ((rc = fsg_alloc()) != 0)
  38170. + return rc;
  38171. + fsg = the_fsg;
  38172. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  38173. + kref_put(&fsg->ref, fsg_release);
  38174. + return rc;
  38175. +}
  38176. +module_init(fsg_init);
  38177. +
  38178. +
  38179. +static void __exit fsg_cleanup(void)
  38180. +{
  38181. + struct fsg_dev *fsg = the_fsg;
  38182. +
  38183. + /* Unregister the driver iff the thread hasn't already done so */
  38184. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38185. + usb_gadget_unregister_driver(&fsg_driver);
  38186. +
  38187. + /* Wait for the thread to finish up */
  38188. + wait_for_completion(&fsg->thread_notifier);
  38189. +
  38190. + kref_put(&fsg->ref, fsg_release);
  38191. +}
  38192. +module_exit(fsg_cleanup);
  38193. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/changes.txt linux-3.11.10/drivers/usb/host/dwc_common_port/changes.txt
  38194. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  38195. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/changes.txt 2014-02-07 19:57:30.000000000 +0100
  38196. @@ -0,0 +1,174 @@
  38197. +
  38198. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  38199. +IO context struct. The IO context struct should live in an os-dependent struct
  38200. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  38201. +named 'os_dep' embedded in the main device struct. So there these calls look
  38202. +like this:
  38203. +
  38204. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  38205. +
  38206. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  38207. + &pcd->dev_global_regs->dcfg, 0);
  38208. +
  38209. +Note that for the existing Linux driver ports, it is not necessary to actually
  38210. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  38211. +require an IO context, its macros for dwc_read_reg32() and friends do not
  38212. +use the context pointer, so it is optimized away by the compiler. But it is
  38213. +necessary to add the pointer parameter to all of the call sites, to be ready
  38214. +for any future ports (such as FreeBSD) which do require an IO context.
  38215. +
  38216. +
  38217. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  38218. +take an additional parameter, a pointer to a memory context. Examples:
  38219. +
  38220. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  38221. +
  38222. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  38223. +
  38224. +Again, for the Linux ports, it is not necessary to actually define the memctx
  38225. +member, but it is necessary to add the pointer parameter to all of the call
  38226. +sites.
  38227. +
  38228. +
  38229. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  38230. +
  38231. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  38232. +
  38233. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  38234. +
  38235. +
  38236. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  38237. +
  38238. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  38239. +
  38240. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  38241. +
  38242. +
  38243. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  38244. +
  38245. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  38246. +
  38247. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  38248. +
  38249. +
  38250. +Same for dwc_timer_alloc(). Example:
  38251. +
  38252. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  38253. + cb_func, cb_data);
  38254. +
  38255. +
  38256. +Same for dwc_waitq_alloc(). Example:
  38257. +
  38258. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  38259. +
  38260. +
  38261. +Same for dwc_thread_run(). Example:
  38262. +
  38263. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  38264. + "dwc_usb3_thd1", data);
  38265. +
  38266. +
  38267. +Same for dwc_workq_alloc(). Example:
  38268. +
  38269. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  38270. +
  38271. +
  38272. +Same for dwc_task_alloc(). Example:
  38273. +
  38274. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  38275. + cb_func, cb_data);
  38276. +
  38277. +
  38278. +In addition to the context pointer additions, a few core functions have had
  38279. +other changes made to their parameters:
  38280. +
  38281. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  38282. +has been changed from a uint64_t to a dwc_irqflags_t.
  38283. +
  38284. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  38285. +FreeBSD equivalent of that function requires it.
  38286. +
  38287. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  38288. +'char *name' parameter, to be consistent with dwc_thread_run() and
  38289. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  38290. +requires a unique name.
  38291. +
  38292. +
  38293. +Here is a complete list of the core functions that now take a pointer to a
  38294. +context as their first parameter:
  38295. +
  38296. + dwc_read_reg32
  38297. + dwc_read_reg64
  38298. + dwc_write_reg32
  38299. + dwc_write_reg64
  38300. + dwc_modify_reg32
  38301. + dwc_modify_reg64
  38302. + dwc_alloc
  38303. + dwc_alloc_atomic
  38304. + dwc_strdup
  38305. + dwc_free
  38306. + dwc_dma_alloc
  38307. + dwc_dma_free
  38308. + dwc_mutex_alloc
  38309. + dwc_mutex_free
  38310. + dwc_spinlock_alloc
  38311. + dwc_spinlock_free
  38312. + dwc_timer_alloc
  38313. + dwc_waitq_alloc
  38314. + dwc_thread_run
  38315. + dwc_workq_alloc
  38316. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  38317. +
  38318. +And here are the core functions that have other changes to their parameters:
  38319. +
  38320. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  38321. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  38322. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  38323. +
  38324. +
  38325. +
  38326. +The changes to the core functions also require some of the other library
  38327. +functions to change:
  38328. +
  38329. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  38330. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  38331. + (for mutex allocation) as the 2nd param.
  38332. +
  38333. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  38334. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  38335. + 'void *memctx' as the 1st param.
  38336. +
  38337. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  38338. + 'void *memctx' as the 1st param.
  38339. +
  38340. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  38341. +
  38342. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  38343. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  38344. + param, and also now returns an integer value that is non-zero if
  38345. + allocation of its data structures or work queue fails.
  38346. +
  38347. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  38348. +
  38349. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  38350. + param, and also now returns an integer value that is non-zero if
  38351. + allocation of its data structures fails.
  38352. +
  38353. +
  38354. +
  38355. +Other miscellaneous changes:
  38356. +
  38357. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  38358. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  38359. +
  38360. +The following #define's have been added to allow selectively compiling library
  38361. +features:
  38362. +
  38363. + DWC_CCLIB
  38364. + DWC_CRYPTOLIB
  38365. + DWC_NOTIFYLIB
  38366. + DWC_UTFLIB
  38367. +
  38368. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  38369. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  38370. +library code directly into a driver module, instead of as a standalone module.
  38371. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-3.11.10/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  38372. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  38373. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-02-07 19:57:30.000000000 +0100
  38374. @@ -0,0 +1,270 @@
  38375. +# Doxyfile 1.4.5
  38376. +
  38377. +#---------------------------------------------------------------------------
  38378. +# Project related configuration options
  38379. +#---------------------------------------------------------------------------
  38380. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  38381. +PROJECT_NUMBER =
  38382. +OUTPUT_DIRECTORY = doc
  38383. +CREATE_SUBDIRS = NO
  38384. +OUTPUT_LANGUAGE = English
  38385. +BRIEF_MEMBER_DESC = YES
  38386. +REPEAT_BRIEF = YES
  38387. +ABBREVIATE_BRIEF = "The $name class" \
  38388. + "The $name widget" \
  38389. + "The $name file" \
  38390. + is \
  38391. + provides \
  38392. + specifies \
  38393. + contains \
  38394. + represents \
  38395. + a \
  38396. + an \
  38397. + the
  38398. +ALWAYS_DETAILED_SEC = YES
  38399. +INLINE_INHERITED_MEMB = NO
  38400. +FULL_PATH_NAMES = NO
  38401. +STRIP_FROM_PATH = ..
  38402. +STRIP_FROM_INC_PATH =
  38403. +SHORT_NAMES = NO
  38404. +JAVADOC_AUTOBRIEF = YES
  38405. +MULTILINE_CPP_IS_BRIEF = NO
  38406. +DETAILS_AT_TOP = YES
  38407. +INHERIT_DOCS = YES
  38408. +SEPARATE_MEMBER_PAGES = NO
  38409. +TAB_SIZE = 8
  38410. +ALIASES =
  38411. +OPTIMIZE_OUTPUT_FOR_C = YES
  38412. +OPTIMIZE_OUTPUT_JAVA = NO
  38413. +BUILTIN_STL_SUPPORT = NO
  38414. +DISTRIBUTE_GROUP_DOC = NO
  38415. +SUBGROUPING = NO
  38416. +#---------------------------------------------------------------------------
  38417. +# Build related configuration options
  38418. +#---------------------------------------------------------------------------
  38419. +EXTRACT_ALL = NO
  38420. +EXTRACT_PRIVATE = NO
  38421. +EXTRACT_STATIC = YES
  38422. +EXTRACT_LOCAL_CLASSES = NO
  38423. +EXTRACT_LOCAL_METHODS = NO
  38424. +HIDE_UNDOC_MEMBERS = NO
  38425. +HIDE_UNDOC_CLASSES = NO
  38426. +HIDE_FRIEND_COMPOUNDS = NO
  38427. +HIDE_IN_BODY_DOCS = NO
  38428. +INTERNAL_DOCS = NO
  38429. +CASE_SENSE_NAMES = YES
  38430. +HIDE_SCOPE_NAMES = NO
  38431. +SHOW_INCLUDE_FILES = NO
  38432. +INLINE_INFO = YES
  38433. +SORT_MEMBER_DOCS = NO
  38434. +SORT_BRIEF_DOCS = NO
  38435. +SORT_BY_SCOPE_NAME = NO
  38436. +GENERATE_TODOLIST = YES
  38437. +GENERATE_TESTLIST = YES
  38438. +GENERATE_BUGLIST = YES
  38439. +GENERATE_DEPRECATEDLIST= YES
  38440. +ENABLED_SECTIONS =
  38441. +MAX_INITIALIZER_LINES = 30
  38442. +SHOW_USED_FILES = YES
  38443. +SHOW_DIRECTORIES = YES
  38444. +FILE_VERSION_FILTER =
  38445. +#---------------------------------------------------------------------------
  38446. +# configuration options related to warning and progress messages
  38447. +#---------------------------------------------------------------------------
  38448. +QUIET = YES
  38449. +WARNINGS = YES
  38450. +WARN_IF_UNDOCUMENTED = NO
  38451. +WARN_IF_DOC_ERROR = YES
  38452. +WARN_NO_PARAMDOC = YES
  38453. +WARN_FORMAT = "$file:$line: $text"
  38454. +WARN_LOGFILE =
  38455. +#---------------------------------------------------------------------------
  38456. +# configuration options related to the input files
  38457. +#---------------------------------------------------------------------------
  38458. +INPUT = .
  38459. +FILE_PATTERNS = *.c \
  38460. + *.cc \
  38461. + *.cxx \
  38462. + *.cpp \
  38463. + *.c++ \
  38464. + *.d \
  38465. + *.java \
  38466. + *.ii \
  38467. + *.ixx \
  38468. + *.ipp \
  38469. + *.i++ \
  38470. + *.inl \
  38471. + *.h \
  38472. + *.hh \
  38473. + *.hxx \
  38474. + *.hpp \
  38475. + *.h++ \
  38476. + *.idl \
  38477. + *.odl \
  38478. + *.cs \
  38479. + *.php \
  38480. + *.php3 \
  38481. + *.inc \
  38482. + *.m \
  38483. + *.mm \
  38484. + *.dox \
  38485. + *.py \
  38486. + *.C \
  38487. + *.CC \
  38488. + *.C++ \
  38489. + *.II \
  38490. + *.I++ \
  38491. + *.H \
  38492. + *.HH \
  38493. + *.H++ \
  38494. + *.CS \
  38495. + *.PHP \
  38496. + *.PHP3 \
  38497. + *.M \
  38498. + *.MM \
  38499. + *.PY
  38500. +RECURSIVE = NO
  38501. +EXCLUDE =
  38502. +EXCLUDE_SYMLINKS = NO
  38503. +EXCLUDE_PATTERNS =
  38504. +EXAMPLE_PATH =
  38505. +EXAMPLE_PATTERNS = *
  38506. +EXAMPLE_RECURSIVE = NO
  38507. +IMAGE_PATH =
  38508. +INPUT_FILTER =
  38509. +FILTER_PATTERNS =
  38510. +FILTER_SOURCE_FILES = NO
  38511. +#---------------------------------------------------------------------------
  38512. +# configuration options related to source browsing
  38513. +#---------------------------------------------------------------------------
  38514. +SOURCE_BROWSER = NO
  38515. +INLINE_SOURCES = NO
  38516. +STRIP_CODE_COMMENTS = YES
  38517. +REFERENCED_BY_RELATION = YES
  38518. +REFERENCES_RELATION = YES
  38519. +USE_HTAGS = NO
  38520. +VERBATIM_HEADERS = NO
  38521. +#---------------------------------------------------------------------------
  38522. +# configuration options related to the alphabetical class index
  38523. +#---------------------------------------------------------------------------
  38524. +ALPHABETICAL_INDEX = NO
  38525. +COLS_IN_ALPHA_INDEX = 5
  38526. +IGNORE_PREFIX =
  38527. +#---------------------------------------------------------------------------
  38528. +# configuration options related to the HTML output
  38529. +#---------------------------------------------------------------------------
  38530. +GENERATE_HTML = YES
  38531. +HTML_OUTPUT = html
  38532. +HTML_FILE_EXTENSION = .html
  38533. +HTML_HEADER =
  38534. +HTML_FOOTER =
  38535. +HTML_STYLESHEET =
  38536. +HTML_ALIGN_MEMBERS = YES
  38537. +GENERATE_HTMLHELP = NO
  38538. +CHM_FILE =
  38539. +HHC_LOCATION =
  38540. +GENERATE_CHI = NO
  38541. +BINARY_TOC = NO
  38542. +TOC_EXPAND = NO
  38543. +DISABLE_INDEX = NO
  38544. +ENUM_VALUES_PER_LINE = 4
  38545. +GENERATE_TREEVIEW = YES
  38546. +TREEVIEW_WIDTH = 250
  38547. +#---------------------------------------------------------------------------
  38548. +# configuration options related to the LaTeX output
  38549. +#---------------------------------------------------------------------------
  38550. +GENERATE_LATEX = NO
  38551. +LATEX_OUTPUT = latex
  38552. +LATEX_CMD_NAME = latex
  38553. +MAKEINDEX_CMD_NAME = makeindex
  38554. +COMPACT_LATEX = NO
  38555. +PAPER_TYPE = a4wide
  38556. +EXTRA_PACKAGES =
  38557. +LATEX_HEADER =
  38558. +PDF_HYPERLINKS = NO
  38559. +USE_PDFLATEX = NO
  38560. +LATEX_BATCHMODE = NO
  38561. +LATEX_HIDE_INDICES = NO
  38562. +#---------------------------------------------------------------------------
  38563. +# configuration options related to the RTF output
  38564. +#---------------------------------------------------------------------------
  38565. +GENERATE_RTF = NO
  38566. +RTF_OUTPUT = rtf
  38567. +COMPACT_RTF = NO
  38568. +RTF_HYPERLINKS = NO
  38569. +RTF_STYLESHEET_FILE =
  38570. +RTF_EXTENSIONS_FILE =
  38571. +#---------------------------------------------------------------------------
  38572. +# configuration options related to the man page output
  38573. +#---------------------------------------------------------------------------
  38574. +GENERATE_MAN = NO
  38575. +MAN_OUTPUT = man
  38576. +MAN_EXTENSION = .3
  38577. +MAN_LINKS = NO
  38578. +#---------------------------------------------------------------------------
  38579. +# configuration options related to the XML output
  38580. +#---------------------------------------------------------------------------
  38581. +GENERATE_XML = NO
  38582. +XML_OUTPUT = xml
  38583. +XML_SCHEMA =
  38584. +XML_DTD =
  38585. +XML_PROGRAMLISTING = YES
  38586. +#---------------------------------------------------------------------------
  38587. +# configuration options for the AutoGen Definitions output
  38588. +#---------------------------------------------------------------------------
  38589. +GENERATE_AUTOGEN_DEF = NO
  38590. +#---------------------------------------------------------------------------
  38591. +# configuration options related to the Perl module output
  38592. +#---------------------------------------------------------------------------
  38593. +GENERATE_PERLMOD = NO
  38594. +PERLMOD_LATEX = NO
  38595. +PERLMOD_PRETTY = YES
  38596. +PERLMOD_MAKEVAR_PREFIX =
  38597. +#---------------------------------------------------------------------------
  38598. +# Configuration options related to the preprocessor
  38599. +#---------------------------------------------------------------------------
  38600. +ENABLE_PREPROCESSING = YES
  38601. +MACRO_EXPANSION = NO
  38602. +EXPAND_ONLY_PREDEF = NO
  38603. +SEARCH_INCLUDES = YES
  38604. +INCLUDE_PATH =
  38605. +INCLUDE_FILE_PATTERNS =
  38606. +PREDEFINED = DEBUG DEBUG_MEMORY
  38607. +EXPAND_AS_DEFINED =
  38608. +SKIP_FUNCTION_MACROS = YES
  38609. +#---------------------------------------------------------------------------
  38610. +# Configuration::additions related to external references
  38611. +#---------------------------------------------------------------------------
  38612. +TAGFILES =
  38613. +GENERATE_TAGFILE =
  38614. +ALLEXTERNALS = NO
  38615. +EXTERNAL_GROUPS = YES
  38616. +PERL_PATH = /usr/bin/perl
  38617. +#---------------------------------------------------------------------------
  38618. +# Configuration options related to the dot tool
  38619. +#---------------------------------------------------------------------------
  38620. +CLASS_DIAGRAMS = YES
  38621. +HIDE_UNDOC_RELATIONS = YES
  38622. +HAVE_DOT = NO
  38623. +CLASS_GRAPH = YES
  38624. +COLLABORATION_GRAPH = YES
  38625. +GROUP_GRAPHS = YES
  38626. +UML_LOOK = NO
  38627. +TEMPLATE_RELATIONS = NO
  38628. +INCLUDE_GRAPH = NO
  38629. +INCLUDED_BY_GRAPH = YES
  38630. +CALL_GRAPH = NO
  38631. +GRAPHICAL_HIERARCHY = YES
  38632. +DIRECTORY_GRAPH = YES
  38633. +DOT_IMAGE_FORMAT = png
  38634. +DOT_PATH =
  38635. +DOTFILE_DIRS =
  38636. +MAX_DOT_GRAPH_DEPTH = 1000
  38637. +DOT_TRANSPARENT = NO
  38638. +DOT_MULTI_TARGETS = NO
  38639. +GENERATE_LEGEND = YES
  38640. +DOT_CLEANUP = YES
  38641. +#---------------------------------------------------------------------------
  38642. +# Configuration::additions related to the search engine
  38643. +#---------------------------------------------------------------------------
  38644. +SEARCHENGINE = NO
  38645. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_cc.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_cc.c
  38646. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  38647. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-02-07 19:57:30.000000000 +0100
  38648. @@ -0,0 +1,532 @@
  38649. +/* =========================================================================
  38650. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  38651. + * $Revision: #4 $
  38652. + * $Date: 2010/11/04 $
  38653. + * $Change: 1621692 $
  38654. + *
  38655. + * Synopsys Portability Library Software and documentation
  38656. + * (hereinafter, "Software") is an Unsupported proprietary work of
  38657. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  38658. + * between Synopsys and you.
  38659. + *
  38660. + * The Software IS NOT an item of Licensed Software or Licensed Product
  38661. + * under any End User Software License Agreement or Agreement for
  38662. + * Licensed Product with Synopsys or any supplement thereto. You are
  38663. + * permitted to use and redistribute this Software in source and binary
  38664. + * forms, with or without modification, provided that redistributions
  38665. + * of source code must retain this notice. You may not view, use,
  38666. + * disclose, copy or distribute this file or any information contained
  38667. + * herein except pursuant to this license grant from Synopsys. If you
  38668. + * do not agree with this notice, including the disclaimer below, then
  38669. + * you are not authorized to use the Software.
  38670. + *
  38671. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  38672. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38673. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  38674. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  38675. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38676. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38677. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38678. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  38679. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38680. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  38681. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  38682. + * DAMAGE.
  38683. + * ========================================================================= */
  38684. +#ifdef DWC_CCLIB
  38685. +
  38686. +#include "dwc_cc.h"
  38687. +
  38688. +typedef struct dwc_cc
  38689. +{
  38690. + uint32_t uid;
  38691. + uint8_t chid[16];
  38692. + uint8_t cdid[16];
  38693. + uint8_t ck[16];
  38694. + uint8_t *name;
  38695. + uint8_t length;
  38696. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  38697. +} dwc_cc_t;
  38698. +
  38699. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  38700. +
  38701. +/** The main structure for CC management. */
  38702. +struct dwc_cc_if
  38703. +{
  38704. + dwc_mutex_t *mutex;
  38705. + char *filename;
  38706. +
  38707. + unsigned is_host:1;
  38708. +
  38709. + dwc_notifier_t *notifier;
  38710. +
  38711. + struct context_list list;
  38712. +};
  38713. +
  38714. +#ifdef DEBUG
  38715. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  38716. +{
  38717. + int i;
  38718. + DWC_PRINTF("%s: ", name);
  38719. + for (i=0; i<len; i++) {
  38720. + DWC_PRINTF("%02x ", bytes[i]);
  38721. + }
  38722. + DWC_PRINTF("\n");
  38723. +}
  38724. +#else
  38725. +#define dump_bytes(x...)
  38726. +#endif
  38727. +
  38728. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  38729. +{
  38730. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  38731. + if (!cc) {
  38732. + return NULL;
  38733. + }
  38734. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  38735. +
  38736. + if (name) {
  38737. + cc->length = length;
  38738. + cc->name = dwc_alloc(mem_ctx, length);
  38739. + if (!cc->name) {
  38740. + dwc_free(mem_ctx, cc);
  38741. + return NULL;
  38742. + }
  38743. +
  38744. + DWC_MEMCPY(cc->name, name, length);
  38745. + }
  38746. +
  38747. + return cc;
  38748. +}
  38749. +
  38750. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  38751. +{
  38752. + if (cc->name) {
  38753. + dwc_free(mem_ctx, cc->name);
  38754. + }
  38755. + dwc_free(mem_ctx, cc);
  38756. +}
  38757. +
  38758. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  38759. +{
  38760. + uint32_t uid = 0;
  38761. + dwc_cc_t *cc;
  38762. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38763. + if (cc->uid > uid) {
  38764. + uid = cc->uid;
  38765. + }
  38766. + }
  38767. +
  38768. + if (uid == 0) {
  38769. + uid = 255;
  38770. + }
  38771. +
  38772. + return uid + 1;
  38773. +}
  38774. +
  38775. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  38776. +{
  38777. + dwc_cc_t *cc;
  38778. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38779. + if (cc->uid == uid) {
  38780. + return cc;
  38781. + }
  38782. + }
  38783. + return NULL;
  38784. +}
  38785. +
  38786. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  38787. +{
  38788. + unsigned int size = 0;
  38789. + dwc_cc_t *cc;
  38790. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38791. + size += (48 + 1);
  38792. + if (cc->name) {
  38793. + size += cc->length;
  38794. + }
  38795. + }
  38796. + return size;
  38797. +}
  38798. +
  38799. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  38800. +{
  38801. + uint32_t uid = 0;
  38802. + dwc_cc_t *cc;
  38803. +
  38804. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38805. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  38806. + uid = cc->uid;
  38807. + break;
  38808. + }
  38809. + }
  38810. + return uid;
  38811. +}
  38812. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  38813. +{
  38814. + uint32_t uid = 0;
  38815. + dwc_cc_t *cc;
  38816. +
  38817. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38818. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  38819. + uid = cc->uid;
  38820. + break;
  38821. + }
  38822. + }
  38823. + return uid;
  38824. +}
  38825. +
  38826. +/* Internal cc_add */
  38827. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38828. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38829. +{
  38830. + dwc_cc_t *cc;
  38831. + uint32_t uid;
  38832. +
  38833. + if (cc_if->is_host) {
  38834. + uid = cc_match_cdid(cc_if, cdid);
  38835. + }
  38836. + else {
  38837. + uid = cc_match_chid(cc_if, chid);
  38838. + }
  38839. +
  38840. + if (uid) {
  38841. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  38842. + cc = cc_find(cc_if, uid);
  38843. + }
  38844. + else {
  38845. + cc = alloc_cc(mem_ctx, name, length);
  38846. + cc->uid = next_uid(cc_if);
  38847. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  38848. + }
  38849. +
  38850. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38851. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38852. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38853. +
  38854. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  38855. + dump_bytes("CHID", cc->chid, 16);
  38856. + dump_bytes("CDID", cc->cdid, 16);
  38857. + dump_bytes("CK", cc->ck, 16);
  38858. + return cc->uid;
  38859. +}
  38860. +
  38861. +/* Internal cc_clear */
  38862. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38863. +{
  38864. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  38865. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  38866. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38867. + free_cc(mem_ctx, cc);
  38868. + }
  38869. +}
  38870. +
  38871. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  38872. + dwc_notifier_t *notifier, unsigned is_host)
  38873. +{
  38874. + dwc_cc_if_t *cc_if = NULL;
  38875. +
  38876. + /* Allocate a common_cc_if structure */
  38877. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  38878. +
  38879. + if (!cc_if)
  38880. + return NULL;
  38881. +
  38882. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38883. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  38884. +#else
  38885. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  38886. +#endif
  38887. + if (!cc_if->mutex) {
  38888. + dwc_free(mem_ctx, cc_if);
  38889. + return NULL;
  38890. + }
  38891. +
  38892. + DWC_CIRCLEQ_INIT(&cc_if->list);
  38893. + cc_if->is_host = is_host;
  38894. + cc_if->notifier = notifier;
  38895. + return cc_if;
  38896. +}
  38897. +
  38898. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  38899. +{
  38900. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38901. + DWC_MUTEX_FREE(cc_if->mutex);
  38902. +#else
  38903. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  38904. +#endif
  38905. + cc_clear(mem_ctx, cc_if);
  38906. + dwc_free(mem_ctx, cc_if);
  38907. +}
  38908. +
  38909. +static void cc_changed(dwc_cc_if_t *cc_if)
  38910. +{
  38911. + if (cc_if->notifier) {
  38912. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  38913. + }
  38914. +}
  38915. +
  38916. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38917. +{
  38918. + DWC_MUTEX_LOCK(cc_if->mutex);
  38919. + cc_clear(mem_ctx, cc_if);
  38920. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38921. + cc_changed(cc_if);
  38922. +}
  38923. +
  38924. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38925. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38926. +{
  38927. + uint32_t uid;
  38928. +
  38929. + DWC_MUTEX_LOCK(cc_if->mutex);
  38930. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  38931. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38932. + cc_changed(cc_if);
  38933. +
  38934. + return uid;
  38935. +}
  38936. +
  38937. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  38938. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38939. +{
  38940. + dwc_cc_t* cc;
  38941. +
  38942. + DWC_DEBUGC("Change connection context %d", id);
  38943. +
  38944. + DWC_MUTEX_LOCK(cc_if->mutex);
  38945. + cc = cc_find(cc_if, id);
  38946. + if (!cc) {
  38947. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38948. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38949. + return;
  38950. + }
  38951. +
  38952. + if (chid) {
  38953. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38954. + }
  38955. + if (cdid) {
  38956. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38957. + }
  38958. + if (ck) {
  38959. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38960. + }
  38961. +
  38962. + if (name) {
  38963. + if (cc->name) {
  38964. + dwc_free(mem_ctx, cc->name);
  38965. + }
  38966. + cc->name = dwc_alloc(mem_ctx, length);
  38967. + if (!cc->name) {
  38968. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  38969. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38970. + return;
  38971. + }
  38972. + cc->length = length;
  38973. + DWC_MEMCPY(cc->name, name, length);
  38974. + }
  38975. +
  38976. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38977. +
  38978. + cc_changed(cc_if);
  38979. +
  38980. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  38981. + dump_bytes("New CHID", cc->chid, 16);
  38982. + dump_bytes("New CDID", cc->cdid, 16);
  38983. + dump_bytes("New CK", cc->ck, 16);
  38984. +}
  38985. +
  38986. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  38987. +{
  38988. + dwc_cc_t *cc;
  38989. +
  38990. + DWC_DEBUGC("Removing connection context %d", id);
  38991. +
  38992. + DWC_MUTEX_LOCK(cc_if->mutex);
  38993. + cc = cc_find(cc_if, id);
  38994. + if (!cc) {
  38995. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38996. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38997. + return;
  38998. + }
  38999. +
  39000. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39001. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39002. + free_cc(mem_ctx, cc);
  39003. +
  39004. + cc_changed(cc_if);
  39005. +}
  39006. +
  39007. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  39008. +{
  39009. + uint8_t *buf, *x;
  39010. + uint8_t zero = 0;
  39011. + dwc_cc_t *cc;
  39012. +
  39013. + DWC_MUTEX_LOCK(cc_if->mutex);
  39014. + *length = cc_data_size(cc_if);
  39015. + if (!(*length)) {
  39016. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39017. + return NULL;
  39018. + }
  39019. +
  39020. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  39021. +
  39022. + buf = dwc_alloc(mem_ctx, *length);
  39023. + if (!buf) {
  39024. + *length = 0;
  39025. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39026. + return NULL;
  39027. + }
  39028. +
  39029. + x = buf;
  39030. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39031. + DWC_MEMCPY(x, cc->chid, 16);
  39032. + x += 16;
  39033. + DWC_MEMCPY(x, cc->cdid, 16);
  39034. + x += 16;
  39035. + DWC_MEMCPY(x, cc->ck, 16);
  39036. + x += 16;
  39037. + if (cc->name) {
  39038. + DWC_MEMCPY(x, &cc->length, 1);
  39039. + x += 1;
  39040. + DWC_MEMCPY(x, cc->name, cc->length);
  39041. + x += cc->length;
  39042. + }
  39043. + else {
  39044. + DWC_MEMCPY(x, &zero, 1);
  39045. + x += 1;
  39046. + }
  39047. + }
  39048. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39049. +
  39050. + return buf;
  39051. +}
  39052. +
  39053. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  39054. +{
  39055. + uint8_t name_length;
  39056. + uint8_t *name;
  39057. + uint8_t *chid;
  39058. + uint8_t *cdid;
  39059. + uint8_t *ck;
  39060. + uint32_t i = 0;
  39061. +
  39062. + DWC_MUTEX_LOCK(cc_if->mutex);
  39063. + cc_clear(mem_ctx, cc_if);
  39064. +
  39065. + while (i < length) {
  39066. + chid = &data[i];
  39067. + i += 16;
  39068. + cdid = &data[i];
  39069. + i += 16;
  39070. + ck = &data[i];
  39071. + i += 16;
  39072. +
  39073. + name_length = data[i];
  39074. + i ++;
  39075. +
  39076. + if (name_length) {
  39077. + name = &data[i];
  39078. + i += name_length;
  39079. + }
  39080. + else {
  39081. + name = NULL;
  39082. + }
  39083. +
  39084. + /* check to see if we haven't overflown the buffer */
  39085. + if (i > length) {
  39086. + DWC_ERROR("Data format error while attempting to load CCs "
  39087. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  39088. + break;
  39089. + }
  39090. +
  39091. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  39092. + }
  39093. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39094. +
  39095. + cc_changed(cc_if);
  39096. +}
  39097. +
  39098. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39099. +{
  39100. + uint32_t uid = 0;
  39101. +
  39102. + DWC_MUTEX_LOCK(cc_if->mutex);
  39103. + uid = cc_match_chid(cc_if, chid);
  39104. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39105. + return uid;
  39106. +}
  39107. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39108. +{
  39109. + uint32_t uid = 0;
  39110. +
  39111. + DWC_MUTEX_LOCK(cc_if->mutex);
  39112. + uid = cc_match_cdid(cc_if, cdid);
  39113. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39114. + return uid;
  39115. +}
  39116. +
  39117. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  39118. +{
  39119. + uint8_t *ck = NULL;
  39120. + dwc_cc_t *cc;
  39121. +
  39122. + DWC_MUTEX_LOCK(cc_if->mutex);
  39123. + cc = cc_find(cc_if, id);
  39124. + if (cc) {
  39125. + ck = cc->ck;
  39126. + }
  39127. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39128. +
  39129. + return ck;
  39130. +
  39131. +}
  39132. +
  39133. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  39134. +{
  39135. + uint8_t *retval = NULL;
  39136. + dwc_cc_t *cc;
  39137. +
  39138. + DWC_MUTEX_LOCK(cc_if->mutex);
  39139. + cc = cc_find(cc_if, id);
  39140. + if (cc) {
  39141. + retval = cc->chid;
  39142. + }
  39143. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39144. +
  39145. + return retval;
  39146. +}
  39147. +
  39148. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  39149. +{
  39150. + uint8_t *retval = NULL;
  39151. + dwc_cc_t *cc;
  39152. +
  39153. + DWC_MUTEX_LOCK(cc_if->mutex);
  39154. + cc = cc_find(cc_if, id);
  39155. + if (cc) {
  39156. + retval = cc->cdid;
  39157. + }
  39158. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39159. +
  39160. + return retval;
  39161. +}
  39162. +
  39163. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  39164. +{
  39165. + uint8_t *retval = NULL;
  39166. + dwc_cc_t *cc;
  39167. +
  39168. + DWC_MUTEX_LOCK(cc_if->mutex);
  39169. + *length = 0;
  39170. + cc = cc_find(cc_if, id);
  39171. + if (cc) {
  39172. + *length = cc->length;
  39173. + retval = cc->name;
  39174. + }
  39175. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39176. +
  39177. + return retval;
  39178. +}
  39179. +
  39180. +#endif /* DWC_CCLIB */
  39181. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_cc.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_cc.h
  39182. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  39183. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-02-07 19:57:30.000000000 +0100
  39184. @@ -0,0 +1,224 @@
  39185. +/* =========================================================================
  39186. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  39187. + * $Revision: #4 $
  39188. + * $Date: 2010/09/28 $
  39189. + * $Change: 1596182 $
  39190. + *
  39191. + * Synopsys Portability Library Software and documentation
  39192. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39193. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39194. + * between Synopsys and you.
  39195. + *
  39196. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39197. + * under any End User Software License Agreement or Agreement for
  39198. + * Licensed Product with Synopsys or any supplement thereto. You are
  39199. + * permitted to use and redistribute this Software in source and binary
  39200. + * forms, with or without modification, provided that redistributions
  39201. + * of source code must retain this notice. You may not view, use,
  39202. + * disclose, copy or distribute this file or any information contained
  39203. + * herein except pursuant to this license grant from Synopsys. If you
  39204. + * do not agree with this notice, including the disclaimer below, then
  39205. + * you are not authorized to use the Software.
  39206. + *
  39207. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39208. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39209. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39210. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39211. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39212. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39213. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39214. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39215. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39216. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39217. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39218. + * DAMAGE.
  39219. + * ========================================================================= */
  39220. +#ifndef _DWC_CC_H_
  39221. +#define _DWC_CC_H_
  39222. +
  39223. +#ifdef __cplusplus
  39224. +extern "C" {
  39225. +#endif
  39226. +
  39227. +/** @file
  39228. + *
  39229. + * This file defines the Context Context library.
  39230. + *
  39231. + * The main data structure is dwc_cc_if_t which is returned by either the
  39232. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  39233. + * function. The data structure is opaque and should only be manipulated via the
  39234. + * functions provied in this API.
  39235. + *
  39236. + * It manages a list of connection contexts and operations can be performed to
  39237. + * add, remove, query, search, and change, those contexts. Additionally,
  39238. + * a dwc_notifier_t object can be requested from the manager so that
  39239. + * the user can be notified whenever the context list has changed.
  39240. + */
  39241. +
  39242. +#include "dwc_os.h"
  39243. +#include "dwc_list.h"
  39244. +#include "dwc_notifier.h"
  39245. +
  39246. +
  39247. +/* Notifications */
  39248. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  39249. +
  39250. +struct dwc_cc_if;
  39251. +typedef struct dwc_cc_if dwc_cc_if_t;
  39252. +
  39253. +
  39254. +/** @name Connection Context Operations */
  39255. +/** @{ */
  39256. +
  39257. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  39258. + * fields to default values, and returns a pointer to the structure or NULL on
  39259. + * error. */
  39260. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39261. + dwc_notifier_t *notifier, unsigned is_host);
  39262. +
  39263. +/** Frees the memory for the specified CC structure allocated from
  39264. + * dwc_cc_if_alloc(). */
  39265. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  39266. +
  39267. +/** Removes all contexts from the connection context list */
  39268. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  39269. +
  39270. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  39271. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  39272. + * not overwritten.
  39273. + *
  39274. + * @param cc_if The cc_if structure.
  39275. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  39276. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  39277. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  39278. + * @param name An optional host friendly name as defined in the association model
  39279. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  39280. + * @param length The length othe unicode string.
  39281. + * @return A unique identifier used to refer to this context that is valid for
  39282. + * as long as this context is still in the list. */
  39283. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39284. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  39285. + uint8_t length);
  39286. +
  39287. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  39288. + * list, preserving any accumulated statistics. This would typically be called
  39289. + * if the host decideds to change the context with a SET_CONNECTION request.
  39290. + *
  39291. + * @param cc_if The cc_if structure.
  39292. + * @param id The identifier of the connection context.
  39293. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  39294. + * indicates no change.
  39295. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  39296. + * indicates no change.
  39297. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  39298. + * indicates no change.
  39299. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  39300. + * @param length Length of name. */
  39301. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  39302. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  39303. + uint8_t *name, uint8_t length);
  39304. +
  39305. +/** Remove the specified connection context.
  39306. + * @param cc_if The cc_if structure.
  39307. + * @param id The identifier of the connection context to remove. */
  39308. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  39309. +
  39310. +/** Get a binary block of data for the connection context list and attributes.
  39311. + * This data can be used by the OS specific driver to save the connection
  39312. + * context list into non-volatile memory.
  39313. + *
  39314. + * @param cc_if The cc_if structure.
  39315. + * @param length Return the length of the data buffer.
  39316. + * @return A pointer to the data buffer. The memory for this buffer should be
  39317. + * freed with DWC_FREE() after use. */
  39318. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  39319. + unsigned int *length);
  39320. +
  39321. +/** Restore the connection context list from the binary data that was previously
  39322. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  39323. + * driver to load a connection context list from non-volatile memory.
  39324. + *
  39325. + * @param cc_if The cc_if structure.
  39326. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  39327. + * @param length The length of the data. */
  39328. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  39329. + uint8_t *data, unsigned int length);
  39330. +
  39331. +/** Find the connection context from the specified CHID.
  39332. + *
  39333. + * @param cc_if The cc_if structure.
  39334. + * @param chid A pointer to the CHID data.
  39335. + * @return A non-zero identifier of the connection context if the CHID matches.
  39336. + * Otherwise returns 0. */
  39337. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  39338. +
  39339. +/** Find the connection context from the specified CDID.
  39340. + *
  39341. + * @param cc_if The cc_if structure.
  39342. + * @param cdid A pointer to the CDID data.
  39343. + * @return A non-zero identifier of the connection context if the CHID matches.
  39344. + * Otherwise returns 0. */
  39345. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  39346. +
  39347. +/** Retrieve the CK from the specified connection context.
  39348. + *
  39349. + * @param cc_if The cc_if structure.
  39350. + * @param id The identifier of the connection context.
  39351. + * @return A pointer to the CK data. The memory does not need to be freed. */
  39352. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  39353. +
  39354. +/** Retrieve the CHID from the specified connection context.
  39355. + *
  39356. + * @param cc_if The cc_if structure.
  39357. + * @param id The identifier of the connection context.
  39358. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  39359. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  39360. +
  39361. +/** Retrieve the CDID from the specified connection context.
  39362. + *
  39363. + * @param cc_if The cc_if structure.
  39364. + * @param id The identifier of the connection context.
  39365. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  39366. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  39367. +
  39368. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  39369. +
  39370. +/** Checks a buffer for non-zero.
  39371. + * @param id A pointer to a 16 byte buffer.
  39372. + * @return true if the 16 byte value is non-zero. */
  39373. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  39374. + int i;
  39375. + for (i=0; i<16; i++) {
  39376. + if (id[i]) return 1;
  39377. + }
  39378. + return 0;
  39379. +}
  39380. +
  39381. +/** Checks a buffer for zero.
  39382. + * @param id A pointer to a 16 byte buffer.
  39383. + * @return true if the 16 byte value is zero. */
  39384. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  39385. + return !dwc_assoc_is_not_zero_id(id);
  39386. +}
  39387. +
  39388. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  39389. + * buffer. */
  39390. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  39391. + char *ptr = buffer;
  39392. + int i;
  39393. + for (i=0; i<16; i++) {
  39394. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  39395. + if (i < 15) {
  39396. + ptr += DWC_SPRINTF(ptr, " ");
  39397. + }
  39398. + }
  39399. + return ptr - buffer;
  39400. +}
  39401. +
  39402. +/** @} */
  39403. +
  39404. +#ifdef __cplusplus
  39405. +}
  39406. +#endif
  39407. +
  39408. +#endif /* _DWC_CC_H_ */
  39409. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  39410. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  39411. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-02-07 19:57:30.000000000 +0100
  39412. @@ -0,0 +1,1308 @@
  39413. +#include "dwc_os.h"
  39414. +#include "dwc_list.h"
  39415. +
  39416. +#ifdef DWC_CCLIB
  39417. +# include "dwc_cc.h"
  39418. +#endif
  39419. +
  39420. +#ifdef DWC_CRYPTOLIB
  39421. +# include "dwc_modpow.h"
  39422. +# include "dwc_dh.h"
  39423. +# include "dwc_crypto.h"
  39424. +#endif
  39425. +
  39426. +#ifdef DWC_NOTIFYLIB
  39427. +# include "dwc_notifier.h"
  39428. +#endif
  39429. +
  39430. +/* OS-Level Implementations */
  39431. +
  39432. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  39433. +
  39434. +
  39435. +/* MISC */
  39436. +
  39437. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  39438. +{
  39439. + return memset(dest, byte, size);
  39440. +}
  39441. +
  39442. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  39443. +{
  39444. + return memcpy(dest, src, size);
  39445. +}
  39446. +
  39447. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  39448. +{
  39449. + bcopy(src, dest, size);
  39450. + return dest;
  39451. +}
  39452. +
  39453. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  39454. +{
  39455. + return memcmp(m1, m2, size);
  39456. +}
  39457. +
  39458. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  39459. +{
  39460. + return strncmp(s1, s2, size);
  39461. +}
  39462. +
  39463. +int DWC_STRCMP(void *s1, void *s2)
  39464. +{
  39465. + return strcmp(s1, s2);
  39466. +}
  39467. +
  39468. +int DWC_STRLEN(char const *str)
  39469. +{
  39470. + return strlen(str);
  39471. +}
  39472. +
  39473. +char *DWC_STRCPY(char *to, char const *from)
  39474. +{
  39475. + return strcpy(to, from);
  39476. +}
  39477. +
  39478. +char *DWC_STRDUP(char const *str)
  39479. +{
  39480. + int len = DWC_STRLEN(str) + 1;
  39481. + char *new = DWC_ALLOC_ATOMIC(len);
  39482. +
  39483. + if (!new) {
  39484. + return NULL;
  39485. + }
  39486. +
  39487. + DWC_MEMCPY(new, str, len);
  39488. + return new;
  39489. +}
  39490. +
  39491. +int DWC_ATOI(char *str, int32_t *value)
  39492. +{
  39493. + char *end = NULL;
  39494. +
  39495. + *value = strtol(str, &end, 0);
  39496. + if (*end == '\0') {
  39497. + return 0;
  39498. + }
  39499. +
  39500. + return -1;
  39501. +}
  39502. +
  39503. +int DWC_ATOUI(char *str, uint32_t *value)
  39504. +{
  39505. + char *end = NULL;
  39506. +
  39507. + *value = strtoul(str, &end, 0);
  39508. + if (*end == '\0') {
  39509. + return 0;
  39510. + }
  39511. +
  39512. + return -1;
  39513. +}
  39514. +
  39515. +
  39516. +#ifdef DWC_UTFLIB
  39517. +/* From usbstring.c */
  39518. +
  39519. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  39520. +{
  39521. + int count = 0;
  39522. + u8 c;
  39523. + u16 uchar;
  39524. +
  39525. + /* this insists on correct encodings, though not minimal ones.
  39526. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  39527. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  39528. + */
  39529. + while (len != 0 && (c = (u8) *s++) != 0) {
  39530. + if (unlikely(c & 0x80)) {
  39531. + // 2-byte sequence:
  39532. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  39533. + if ((c & 0xe0) == 0xc0) {
  39534. + uchar = (c & 0x1f) << 6;
  39535. +
  39536. + c = (u8) *s++;
  39537. + if ((c & 0xc0) != 0xc0)
  39538. + goto fail;
  39539. + c &= 0x3f;
  39540. + uchar |= c;
  39541. +
  39542. + // 3-byte sequence (most CJKV characters):
  39543. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  39544. + } else if ((c & 0xf0) == 0xe0) {
  39545. + uchar = (c & 0x0f) << 12;
  39546. +
  39547. + c = (u8) *s++;
  39548. + if ((c & 0xc0) != 0xc0)
  39549. + goto fail;
  39550. + c &= 0x3f;
  39551. + uchar |= c << 6;
  39552. +
  39553. + c = (u8) *s++;
  39554. + if ((c & 0xc0) != 0xc0)
  39555. + goto fail;
  39556. + c &= 0x3f;
  39557. + uchar |= c;
  39558. +
  39559. + /* no bogus surrogates */
  39560. + if (0xd800 <= uchar && uchar <= 0xdfff)
  39561. + goto fail;
  39562. +
  39563. + // 4-byte sequence (surrogate pairs, currently rare):
  39564. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  39565. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  39566. + // (uuuuu = wwww + 1)
  39567. + // FIXME accept the surrogate code points (only)
  39568. + } else
  39569. + goto fail;
  39570. + } else
  39571. + uchar = c;
  39572. + put_unaligned (cpu_to_le16 (uchar), cp++);
  39573. + count++;
  39574. + len--;
  39575. + }
  39576. + return count;
  39577. +fail:
  39578. + return -1;
  39579. +}
  39580. +
  39581. +#endif /* DWC_UTFLIB */
  39582. +
  39583. +
  39584. +/* dwc_debug.h */
  39585. +
  39586. +dwc_bool_t DWC_IN_IRQ(void)
  39587. +{
  39588. +// return in_irq();
  39589. + return 0;
  39590. +}
  39591. +
  39592. +dwc_bool_t DWC_IN_BH(void)
  39593. +{
  39594. +// return in_softirq();
  39595. + return 0;
  39596. +}
  39597. +
  39598. +void DWC_VPRINTF(char *format, va_list args)
  39599. +{
  39600. + vprintf(format, args);
  39601. +}
  39602. +
  39603. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  39604. +{
  39605. + return vsnprintf(str, size, format, args);
  39606. +}
  39607. +
  39608. +void DWC_PRINTF(char *format, ...)
  39609. +{
  39610. + va_list args;
  39611. +
  39612. + va_start(args, format);
  39613. + DWC_VPRINTF(format, args);
  39614. + va_end(args);
  39615. +}
  39616. +
  39617. +int DWC_SPRINTF(char *buffer, char *format, ...)
  39618. +{
  39619. + int retval;
  39620. + va_list args;
  39621. +
  39622. + va_start(args, format);
  39623. + retval = vsprintf(buffer, format, args);
  39624. + va_end(args);
  39625. + return retval;
  39626. +}
  39627. +
  39628. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  39629. +{
  39630. + int retval;
  39631. + va_list args;
  39632. +
  39633. + va_start(args, format);
  39634. + retval = vsnprintf(buffer, size, format, args);
  39635. + va_end(args);
  39636. + return retval;
  39637. +}
  39638. +
  39639. +void __DWC_WARN(char *format, ...)
  39640. +{
  39641. + va_list args;
  39642. +
  39643. + va_start(args, format);
  39644. + DWC_VPRINTF(format, args);
  39645. + va_end(args);
  39646. +}
  39647. +
  39648. +void __DWC_ERROR(char *format, ...)
  39649. +{
  39650. + va_list args;
  39651. +
  39652. + va_start(args, format);
  39653. + DWC_VPRINTF(format, args);
  39654. + va_end(args);
  39655. +}
  39656. +
  39657. +void DWC_EXCEPTION(char *format, ...)
  39658. +{
  39659. + va_list args;
  39660. +
  39661. + va_start(args, format);
  39662. + DWC_VPRINTF(format, args);
  39663. + va_end(args);
  39664. +// BUG_ON(1); ???
  39665. +}
  39666. +
  39667. +#ifdef DEBUG
  39668. +void __DWC_DEBUG(char *format, ...)
  39669. +{
  39670. + va_list args;
  39671. +
  39672. + va_start(args, format);
  39673. + DWC_VPRINTF(format, args);
  39674. + va_end(args);
  39675. +}
  39676. +#endif
  39677. +
  39678. +
  39679. +/* dwc_mem.h */
  39680. +
  39681. +#if 0
  39682. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  39683. + uint32_t align,
  39684. + uint32_t alloc)
  39685. +{
  39686. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  39687. + size, align, alloc);
  39688. + return (dwc_pool_t *)pool;
  39689. +}
  39690. +
  39691. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  39692. +{
  39693. + dma_pool_destroy((struct dma_pool *)pool);
  39694. +}
  39695. +
  39696. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39697. +{
  39698. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  39699. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  39700. +}
  39701. +
  39702. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39703. +{
  39704. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  39705. + memset(..);
  39706. +}
  39707. +
  39708. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  39709. +{
  39710. + dma_pool_free(pool, vaddr, daddr);
  39711. +}
  39712. +#endif
  39713. +
  39714. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  39715. +{
  39716. + if (error)
  39717. + return;
  39718. + *(bus_addr_t *)arg = segs[0].ds_addr;
  39719. +}
  39720. +
  39721. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  39722. +{
  39723. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39724. + int error;
  39725. +
  39726. + error = bus_dma_tag_create(
  39727. +#if __FreeBSD_version >= 700000
  39728. + bus_get_dma_tag(dma->dev), /* parent */
  39729. +#else
  39730. + NULL, /* parent */
  39731. +#endif
  39732. + 4, 0, /* alignment, bounds */
  39733. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  39734. + BUS_SPACE_MAXADDR, /* highaddr */
  39735. + NULL, NULL, /* filter, filterarg */
  39736. + size, /* maxsize */
  39737. + 1, /* nsegments */
  39738. + size, /* maxsegsize */
  39739. + 0, /* flags */
  39740. + NULL, /* lockfunc */
  39741. + NULL, /* lockarg */
  39742. + &dma->dma_tag);
  39743. + if (error) {
  39744. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  39745. + __func__, error);
  39746. + goto fail_0;
  39747. + }
  39748. +
  39749. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  39750. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  39751. + if (error) {
  39752. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  39753. + __func__, (uintmax_t)size, error);
  39754. + goto fail_1;
  39755. + }
  39756. +
  39757. + dma->dma_paddr = 0;
  39758. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  39759. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  39760. + if (error || dma->dma_paddr == 0) {
  39761. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  39762. + __func__, error);
  39763. + goto fail_2;
  39764. + }
  39765. +
  39766. + *dma_addr = dma->dma_paddr;
  39767. + return dma->dma_vaddr;
  39768. +
  39769. +fail_2:
  39770. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39771. +fail_1:
  39772. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39773. + bus_dma_tag_destroy(dma->dma_tag);
  39774. +fail_0:
  39775. + dma->dma_map = NULL;
  39776. + dma->dma_tag = NULL;
  39777. +
  39778. + return NULL;
  39779. +}
  39780. +
  39781. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  39782. +{
  39783. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39784. +
  39785. + if (dma->dma_tag == NULL)
  39786. + return;
  39787. + if (dma->dma_map != NULL) {
  39788. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  39789. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  39790. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39791. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39792. + dma->dma_map = NULL;
  39793. + }
  39794. +
  39795. + bus_dma_tag_destroy(dma->dma_tag);
  39796. + dma->dma_tag = NULL;
  39797. +}
  39798. +
  39799. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  39800. +{
  39801. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  39802. +}
  39803. +
  39804. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  39805. +{
  39806. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  39807. +}
  39808. +
  39809. +void __DWC_FREE(void *mem_ctx, void *addr)
  39810. +{
  39811. + free(addr, M_DEVBUF);
  39812. +}
  39813. +
  39814. +
  39815. +#ifdef DWC_CRYPTOLIB
  39816. +/* dwc_crypto.h */
  39817. +
  39818. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  39819. +{
  39820. + get_random_bytes(buffer, length);
  39821. +}
  39822. +
  39823. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  39824. +{
  39825. + struct crypto_blkcipher *tfm;
  39826. + struct blkcipher_desc desc;
  39827. + struct scatterlist sgd;
  39828. + struct scatterlist sgs;
  39829. +
  39830. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  39831. + if (tfm == NULL) {
  39832. + printk("failed to load transform for aes CBC\n");
  39833. + return -1;
  39834. + }
  39835. +
  39836. + crypto_blkcipher_setkey(tfm, key, keylen);
  39837. + crypto_blkcipher_set_iv(tfm, iv, 16);
  39838. +
  39839. + sg_init_one(&sgd, out, messagelen);
  39840. + sg_init_one(&sgs, message, messagelen);
  39841. +
  39842. + desc.tfm = tfm;
  39843. + desc.flags = 0;
  39844. +
  39845. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  39846. + crypto_free_blkcipher(tfm);
  39847. + DWC_ERROR("AES CBC encryption failed");
  39848. + return -1;
  39849. + }
  39850. +
  39851. + crypto_free_blkcipher(tfm);
  39852. + return 0;
  39853. +}
  39854. +
  39855. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  39856. +{
  39857. + struct crypto_hash *tfm;
  39858. + struct hash_desc desc;
  39859. + struct scatterlist sg;
  39860. +
  39861. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  39862. + if (IS_ERR(tfm)) {
  39863. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  39864. + return 0;
  39865. + }
  39866. + desc.tfm = tfm;
  39867. + desc.flags = 0;
  39868. +
  39869. + sg_init_one(&sg, message, len);
  39870. + crypto_hash_digest(&desc, &sg, len, out);
  39871. + crypto_free_hash(tfm);
  39872. +
  39873. + return 1;
  39874. +}
  39875. +
  39876. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  39877. + uint8_t *key, uint32_t keylen, uint8_t *out)
  39878. +{
  39879. + struct crypto_hash *tfm;
  39880. + struct hash_desc desc;
  39881. + struct scatterlist sg;
  39882. +
  39883. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  39884. + if (IS_ERR(tfm)) {
  39885. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  39886. + return 0;
  39887. + }
  39888. + desc.tfm = tfm;
  39889. + desc.flags = 0;
  39890. +
  39891. + sg_init_one(&sg, message, messagelen);
  39892. + crypto_hash_setkey(tfm, key, keylen);
  39893. + crypto_hash_digest(&desc, &sg, messagelen, out);
  39894. + crypto_free_hash(tfm);
  39895. +
  39896. + return 1;
  39897. +}
  39898. +
  39899. +#endif /* DWC_CRYPTOLIB */
  39900. +
  39901. +
  39902. +/* Byte Ordering Conversions */
  39903. +
  39904. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  39905. +{
  39906. +#ifdef __LITTLE_ENDIAN
  39907. + return *p;
  39908. +#else
  39909. + uint8_t *u_p = (uint8_t *)p;
  39910. +
  39911. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39912. +#endif
  39913. +}
  39914. +
  39915. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  39916. +{
  39917. +#ifdef __BIG_ENDIAN
  39918. + return *p;
  39919. +#else
  39920. + uint8_t *u_p = (uint8_t *)p;
  39921. +
  39922. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39923. +#endif
  39924. +}
  39925. +
  39926. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  39927. +{
  39928. +#ifdef __LITTLE_ENDIAN
  39929. + return *p;
  39930. +#else
  39931. + uint8_t *u_p = (uint8_t *)p;
  39932. +
  39933. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39934. +#endif
  39935. +}
  39936. +
  39937. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  39938. +{
  39939. +#ifdef __BIG_ENDIAN
  39940. + return *p;
  39941. +#else
  39942. + uint8_t *u_p = (uint8_t *)p;
  39943. +
  39944. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39945. +#endif
  39946. +}
  39947. +
  39948. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  39949. +{
  39950. +#ifdef __LITTLE_ENDIAN
  39951. + return *p;
  39952. +#else
  39953. + uint8_t *u_p = (uint8_t *)p;
  39954. + return (u_p[1] | (u_p[0] << 8));
  39955. +#endif
  39956. +}
  39957. +
  39958. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  39959. +{
  39960. +#ifdef __BIG_ENDIAN
  39961. + return *p;
  39962. +#else
  39963. + uint8_t *u_p = (uint8_t *)p;
  39964. + return (u_p[1] | (u_p[0] << 8));
  39965. +#endif
  39966. +}
  39967. +
  39968. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  39969. +{
  39970. +#ifdef __LITTLE_ENDIAN
  39971. + return *p;
  39972. +#else
  39973. + uint8_t *u_p = (uint8_t *)p;
  39974. + return (u_p[1] | (u_p[0] << 8));
  39975. +#endif
  39976. +}
  39977. +
  39978. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  39979. +{
  39980. +#ifdef __BIG_ENDIAN
  39981. + return *p;
  39982. +#else
  39983. + uint8_t *u_p = (uint8_t *)p;
  39984. + return (u_p[1] | (u_p[0] << 8));
  39985. +#endif
  39986. +}
  39987. +
  39988. +
  39989. +/* Registers */
  39990. +
  39991. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  39992. +{
  39993. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39994. + bus_size_t ior = (bus_size_t)reg;
  39995. +
  39996. + return bus_space_read_4(io->iot, io->ioh, ior);
  39997. +}
  39998. +
  39999. +#if 0
  40000. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  40001. +{
  40002. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40003. + bus_size_t ior = (bus_size_t)reg;
  40004. +
  40005. + return bus_space_read_8(io->iot, io->ioh, ior);
  40006. +}
  40007. +#endif
  40008. +
  40009. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  40010. +{
  40011. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40012. + bus_size_t ior = (bus_size_t)reg;
  40013. +
  40014. + bus_space_write_4(io->iot, io->ioh, ior, value);
  40015. +}
  40016. +
  40017. +#if 0
  40018. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  40019. +{
  40020. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40021. + bus_size_t ior = (bus_size_t)reg;
  40022. +
  40023. + bus_space_write_8(io->iot, io->ioh, ior, value);
  40024. +}
  40025. +#endif
  40026. +
  40027. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  40028. + uint32_t set_mask)
  40029. +{
  40030. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40031. + bus_size_t ior = (bus_size_t)reg;
  40032. +
  40033. + bus_space_write_4(io->iot, io->ioh, ior,
  40034. + (bus_space_read_4(io->iot, io->ioh, ior) &
  40035. + ~clear_mask) | set_mask);
  40036. +}
  40037. +
  40038. +#if 0
  40039. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  40040. + uint64_t set_mask)
  40041. +{
  40042. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40043. + bus_size_t ior = (bus_size_t)reg;
  40044. +
  40045. + bus_space_write_8(io->iot, io->ioh, ior,
  40046. + (bus_space_read_8(io->iot, io->ioh, ior) &
  40047. + ~clear_mask) | set_mask);
  40048. +}
  40049. +#endif
  40050. +
  40051. +
  40052. +/* Locking */
  40053. +
  40054. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40055. +{
  40056. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  40057. +
  40058. + if (!sl) {
  40059. + DWC_ERROR("Cannot allocate memory for spinlock");
  40060. + return NULL;
  40061. + }
  40062. +
  40063. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  40064. + return (dwc_spinlock_t *)sl;
  40065. +}
  40066. +
  40067. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40068. +{
  40069. + struct mtx *sl = (struct mtx *)lock;
  40070. +
  40071. + mtx_destroy(sl);
  40072. + DWC_FREE(sl);
  40073. +}
  40074. +
  40075. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  40076. +{
  40077. + mtx_lock_spin((struct mtx *)lock); // ???
  40078. +}
  40079. +
  40080. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  40081. +{
  40082. + mtx_unlock_spin((struct mtx *)lock); // ???
  40083. +}
  40084. +
  40085. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  40086. +{
  40087. + mtx_lock_spin((struct mtx *)lock);
  40088. +}
  40089. +
  40090. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  40091. +{
  40092. + mtx_unlock_spin((struct mtx *)lock);
  40093. +}
  40094. +
  40095. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  40096. +{
  40097. + struct mtx *m;
  40098. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  40099. +
  40100. + if (!mutex) {
  40101. + DWC_ERROR("Cannot allocate memory for mutex");
  40102. + return NULL;
  40103. + }
  40104. +
  40105. + m = (struct mtx *)mutex;
  40106. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  40107. + return mutex;
  40108. +}
  40109. +
  40110. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40111. +#else
  40112. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  40113. +{
  40114. + mtx_destroy((struct mtx *)mutex);
  40115. + DWC_FREE(mutex);
  40116. +}
  40117. +#endif
  40118. +
  40119. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  40120. +{
  40121. + struct mtx *m = (struct mtx *)mutex;
  40122. +
  40123. + mtx_lock(m);
  40124. +}
  40125. +
  40126. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  40127. +{
  40128. + struct mtx *m = (struct mtx *)mutex;
  40129. +
  40130. + return mtx_trylock(m);
  40131. +}
  40132. +
  40133. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  40134. +{
  40135. + struct mtx *m = (struct mtx *)mutex;
  40136. +
  40137. + mtx_unlock(m);
  40138. +}
  40139. +
  40140. +
  40141. +/* Timing */
  40142. +
  40143. +void DWC_UDELAY(uint32_t usecs)
  40144. +{
  40145. + DELAY(usecs);
  40146. +}
  40147. +
  40148. +void DWC_MDELAY(uint32_t msecs)
  40149. +{
  40150. + do {
  40151. + DELAY(1000);
  40152. + } while (--msecs);
  40153. +}
  40154. +
  40155. +void DWC_MSLEEP(uint32_t msecs)
  40156. +{
  40157. + struct timeval tv;
  40158. +
  40159. + tv.tv_sec = msecs / 1000;
  40160. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40161. + pause("dw3slp", tvtohz(&tv));
  40162. +}
  40163. +
  40164. +uint32_t DWC_TIME(void)
  40165. +{
  40166. + struct timeval tv;
  40167. +
  40168. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  40169. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  40170. +}
  40171. +
  40172. +
  40173. +/* Timers */
  40174. +
  40175. +struct dwc_timer {
  40176. + struct callout t;
  40177. + char *name;
  40178. + dwc_spinlock_t *lock;
  40179. + dwc_timer_callback_t cb;
  40180. + void *data;
  40181. +};
  40182. +
  40183. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  40184. +{
  40185. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  40186. +
  40187. + if (!t) {
  40188. + DWC_ERROR("Cannot allocate memory for timer");
  40189. + return NULL;
  40190. + }
  40191. +
  40192. + callout_init(&t->t, 1);
  40193. +
  40194. + t->name = DWC_STRDUP(name);
  40195. + if (!t->name) {
  40196. + DWC_ERROR("Cannot allocate memory for timer->name");
  40197. + goto no_name;
  40198. + }
  40199. +
  40200. + t->lock = DWC_SPINLOCK_ALLOC();
  40201. + if (!t->lock) {
  40202. + DWC_ERROR("Cannot allocate memory for lock");
  40203. + goto no_lock;
  40204. + }
  40205. +
  40206. + t->cb = cb;
  40207. + t->data = data;
  40208. +
  40209. + return t;
  40210. +
  40211. + no_lock:
  40212. + DWC_FREE(t->name);
  40213. + no_name:
  40214. + DWC_FREE(t);
  40215. +
  40216. + return NULL;
  40217. +}
  40218. +
  40219. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  40220. +{
  40221. + callout_stop(&timer->t);
  40222. + DWC_SPINLOCK_FREE(timer->lock);
  40223. + DWC_FREE(timer->name);
  40224. + DWC_FREE(timer);
  40225. +}
  40226. +
  40227. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  40228. +{
  40229. + struct timeval tv;
  40230. +
  40231. + tv.tv_sec = time / 1000;
  40232. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40233. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  40234. +}
  40235. +
  40236. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  40237. +{
  40238. + callout_stop(&timer->t);
  40239. +}
  40240. +
  40241. +
  40242. +/* Wait Queues */
  40243. +
  40244. +struct dwc_waitq {
  40245. + struct mtx lock;
  40246. + int abort;
  40247. +};
  40248. +
  40249. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  40250. +{
  40251. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  40252. +
  40253. + if (!wq) {
  40254. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40255. + return NULL;
  40256. + }
  40257. +
  40258. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  40259. + wq->abort = 0;
  40260. +
  40261. + return wq;
  40262. +}
  40263. +
  40264. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  40265. +{
  40266. + mtx_destroy(&wq->lock);
  40267. + DWC_FREE(wq);
  40268. +}
  40269. +
  40270. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  40271. +{
  40272. +// intrmask_t ipl;
  40273. + int result = 0;
  40274. +
  40275. + mtx_lock(&wq->lock);
  40276. +// ipl = splbio();
  40277. +
  40278. + /* Skip the sleep if already aborted or triggered */
  40279. + if (!wq->abort && !cond(data)) {
  40280. +// splx(ipl);
  40281. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  40282. +// ipl = splbio();
  40283. + }
  40284. +
  40285. + if (result == ERESTART) { // signaled - restart
  40286. + result = -DWC_E_RESTART;
  40287. +
  40288. + } else if (result == EINTR) { // signaled - interrupt
  40289. + result = -DWC_E_ABORT;
  40290. +
  40291. + } else if (wq->abort) {
  40292. + result = -DWC_E_ABORT;
  40293. +
  40294. + } else {
  40295. + result = 0;
  40296. + }
  40297. +
  40298. + wq->abort = 0;
  40299. +// splx(ipl);
  40300. + mtx_unlock(&wq->lock);
  40301. + return result;
  40302. +}
  40303. +
  40304. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  40305. + void *data, int32_t msecs)
  40306. +{
  40307. + struct timeval tv, tv1, tv2;
  40308. +// intrmask_t ipl;
  40309. + int result = 0;
  40310. +
  40311. + tv.tv_sec = msecs / 1000;
  40312. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40313. +
  40314. + mtx_lock(&wq->lock);
  40315. +// ipl = splbio();
  40316. +
  40317. + /* Skip the sleep if already aborted or triggered */
  40318. + if (!wq->abort && !cond(data)) {
  40319. +// splx(ipl);
  40320. + getmicrouptime(&tv1);
  40321. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  40322. + getmicrouptime(&tv2);
  40323. +// ipl = splbio();
  40324. + }
  40325. +
  40326. + if (result == 0) { // awoken
  40327. + if (wq->abort) {
  40328. + result = -DWC_E_ABORT;
  40329. + } else {
  40330. + tv2.tv_usec -= tv1.tv_usec;
  40331. + if (tv2.tv_usec < 0) {
  40332. + tv2.tv_usec += 1000000;
  40333. + tv2.tv_sec--;
  40334. + }
  40335. +
  40336. + tv2.tv_sec -= tv1.tv_sec;
  40337. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  40338. + result = msecs - result;
  40339. + if (result <= 0)
  40340. + result = 1;
  40341. + }
  40342. + } else if (result == ERESTART) { // signaled - restart
  40343. + result = -DWC_E_RESTART;
  40344. +
  40345. + } else if (result == EINTR) { // signaled - interrupt
  40346. + result = -DWC_E_ABORT;
  40347. +
  40348. + } else { // timed out
  40349. + result = -DWC_E_TIMEOUT;
  40350. + }
  40351. +
  40352. + wq->abort = 0;
  40353. +// splx(ipl);
  40354. + mtx_unlock(&wq->lock);
  40355. + return result;
  40356. +}
  40357. +
  40358. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  40359. +{
  40360. + wakeup(wq);
  40361. +}
  40362. +
  40363. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  40364. +{
  40365. +// intrmask_t ipl;
  40366. +
  40367. + mtx_lock(&wq->lock);
  40368. +// ipl = splbio();
  40369. + wq->abort = 1;
  40370. + wakeup(wq);
  40371. +// splx(ipl);
  40372. + mtx_unlock(&wq->lock);
  40373. +}
  40374. +
  40375. +
  40376. +/* Threading */
  40377. +
  40378. +struct dwc_thread {
  40379. + struct proc *proc;
  40380. + int abort;
  40381. +};
  40382. +
  40383. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  40384. +{
  40385. + int retval;
  40386. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  40387. +
  40388. + if (!thread) {
  40389. + return NULL;
  40390. + }
  40391. +
  40392. + thread->abort = 0;
  40393. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  40394. + RFPROC | RFNOWAIT, 0, "%s", name);
  40395. + if (retval) {
  40396. + DWC_FREE(thread);
  40397. + return NULL;
  40398. + }
  40399. +
  40400. + return thread;
  40401. +}
  40402. +
  40403. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  40404. +{
  40405. + int retval;
  40406. +
  40407. + thread->abort = 1;
  40408. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  40409. +
  40410. + if (retval == 0) {
  40411. + /* DWC_THREAD_EXIT() will free the thread struct */
  40412. + return 0;
  40413. + }
  40414. +
  40415. + /* NOTE: We leak the thread struct if thread doesn't die */
  40416. +
  40417. + if (retval == EWOULDBLOCK) {
  40418. + return -DWC_E_TIMEOUT;
  40419. + }
  40420. +
  40421. + return -DWC_E_UNKNOWN;
  40422. +}
  40423. +
  40424. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  40425. +{
  40426. + return thread->abort;
  40427. +}
  40428. +
  40429. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  40430. +{
  40431. + wakeup(&thread->abort);
  40432. + DWC_FREE(thread);
  40433. + kthread_exit(0);
  40434. +}
  40435. +
  40436. +
  40437. +/* tasklets
  40438. + - Runs in interrupt context (cannot sleep)
  40439. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  40440. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  40441. + */
  40442. +struct dwc_tasklet {
  40443. + struct task t;
  40444. + dwc_tasklet_callback_t cb;
  40445. + void *data;
  40446. +};
  40447. +
  40448. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  40449. +{
  40450. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  40451. +
  40452. + task->cb(task->data);
  40453. +}
  40454. +
  40455. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  40456. +{
  40457. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  40458. +
  40459. + if (task) {
  40460. + task->cb = cb;
  40461. + task->data = data;
  40462. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  40463. + } else {
  40464. + DWC_ERROR("Cannot allocate memory for tasklet");
  40465. + }
  40466. +
  40467. + return task;
  40468. +}
  40469. +
  40470. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  40471. +{
  40472. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  40473. + DWC_FREE(task);
  40474. +}
  40475. +
  40476. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  40477. +{
  40478. + /* Uses predefined system queue */
  40479. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  40480. +}
  40481. +
  40482. +
  40483. +/* workqueues
  40484. + - Runs in process context (can sleep)
  40485. + */
  40486. +typedef struct work_container {
  40487. + dwc_work_callback_t cb;
  40488. + void *data;
  40489. + dwc_workq_t *wq;
  40490. + char *name;
  40491. + int hz;
  40492. +
  40493. +#ifdef DEBUG
  40494. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  40495. +#endif
  40496. + struct task task;
  40497. +} work_container_t;
  40498. +
  40499. +#ifdef DEBUG
  40500. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  40501. +#endif
  40502. +
  40503. +struct dwc_workq {
  40504. + struct taskqueue *taskq;
  40505. + dwc_spinlock_t *lock;
  40506. + dwc_waitq_t *waitq;
  40507. + int pending;
  40508. +
  40509. +#ifdef DEBUG
  40510. + struct work_container_queue entries;
  40511. +#endif
  40512. +};
  40513. +
  40514. +static void do_work(void *data, int pending) // what to do with pending ???
  40515. +{
  40516. + work_container_t *container = (work_container_t *)data;
  40517. + dwc_workq_t *wq = container->wq;
  40518. + dwc_irqflags_t flags;
  40519. +
  40520. + if (container->hz) {
  40521. + pause("dw3wrk", container->hz);
  40522. + }
  40523. +
  40524. + container->cb(container->data);
  40525. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  40526. +
  40527. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40528. +
  40529. +#ifdef DEBUG
  40530. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  40531. +#endif
  40532. + if (container->name)
  40533. + DWC_FREE(container->name);
  40534. + DWC_FREE(container);
  40535. + wq->pending--;
  40536. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40537. + DWC_WAITQ_TRIGGER(wq->waitq);
  40538. +}
  40539. +
  40540. +static int work_done(void *data)
  40541. +{
  40542. + dwc_workq_t *workq = (dwc_workq_t *)data;
  40543. +
  40544. + return workq->pending == 0;
  40545. +}
  40546. +
  40547. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  40548. +{
  40549. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  40550. +}
  40551. +
  40552. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  40553. +{
  40554. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  40555. +
  40556. + if (!wq) {
  40557. + DWC_ERROR("Cannot allocate memory for workqueue");
  40558. + return NULL;
  40559. + }
  40560. +
  40561. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  40562. + if (!wq->taskq) {
  40563. + DWC_ERROR("Cannot allocate memory for taskqueue");
  40564. + goto no_taskq;
  40565. + }
  40566. +
  40567. + wq->pending = 0;
  40568. +
  40569. + wq->lock = DWC_SPINLOCK_ALLOC();
  40570. + if (!wq->lock) {
  40571. + DWC_ERROR("Cannot allocate memory for spinlock");
  40572. + goto no_lock;
  40573. + }
  40574. +
  40575. + wq->waitq = DWC_WAITQ_ALLOC();
  40576. + if (!wq->waitq) {
  40577. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40578. + goto no_waitq;
  40579. + }
  40580. +
  40581. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  40582. +
  40583. +#ifdef DEBUG
  40584. + DWC_CIRCLEQ_INIT(&wq->entries);
  40585. +#endif
  40586. + return wq;
  40587. +
  40588. + no_waitq:
  40589. + DWC_SPINLOCK_FREE(wq->lock);
  40590. + no_lock:
  40591. + taskqueue_free(wq->taskq);
  40592. + no_taskq:
  40593. + DWC_FREE(wq);
  40594. +
  40595. + return NULL;
  40596. +}
  40597. +
  40598. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  40599. +{
  40600. +#ifdef DEBUG
  40601. + dwc_irqflags_t flags;
  40602. +
  40603. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40604. +
  40605. + if (wq->pending != 0) {
  40606. + struct work_container *container;
  40607. +
  40608. + DWC_ERROR("Destroying work queue with pending work");
  40609. +
  40610. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  40611. + DWC_ERROR("Work %s still pending", container->name);
  40612. + }
  40613. + }
  40614. +
  40615. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40616. +#endif
  40617. + DWC_WAITQ_FREE(wq->waitq);
  40618. + DWC_SPINLOCK_FREE(wq->lock);
  40619. + taskqueue_free(wq->taskq);
  40620. + DWC_FREE(wq);
  40621. +}
  40622. +
  40623. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  40624. + char *format, ...)
  40625. +{
  40626. + dwc_irqflags_t flags;
  40627. + work_container_t *container;
  40628. + static char name[128];
  40629. + va_list args;
  40630. +
  40631. + va_start(args, format);
  40632. + DWC_VSNPRINTF(name, 128, format, args);
  40633. + va_end(args);
  40634. +
  40635. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40636. + wq->pending++;
  40637. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40638. + DWC_WAITQ_TRIGGER(wq->waitq);
  40639. +
  40640. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40641. + if (!container) {
  40642. + DWC_ERROR("Cannot allocate memory for container");
  40643. + return;
  40644. + }
  40645. +
  40646. + container->name = DWC_STRDUP(name);
  40647. + if (!container->name) {
  40648. + DWC_ERROR("Cannot allocate memory for container->name");
  40649. + DWC_FREE(container);
  40650. + return;
  40651. + }
  40652. +
  40653. + container->cb = cb;
  40654. + container->data = data;
  40655. + container->wq = wq;
  40656. + container->hz = 0;
  40657. +
  40658. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40659. +
  40660. + TASK_INIT(&container->task, 0, do_work, container);
  40661. +
  40662. +#ifdef DEBUG
  40663. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40664. +#endif
  40665. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40666. +}
  40667. +
  40668. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  40669. + void *data, uint32_t time, char *format, ...)
  40670. +{
  40671. + dwc_irqflags_t flags;
  40672. + work_container_t *container;
  40673. + static char name[128];
  40674. + struct timeval tv;
  40675. + va_list args;
  40676. +
  40677. + va_start(args, format);
  40678. + DWC_VSNPRINTF(name, 128, format, args);
  40679. + va_end(args);
  40680. +
  40681. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40682. + wq->pending++;
  40683. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40684. + DWC_WAITQ_TRIGGER(wq->waitq);
  40685. +
  40686. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40687. + if (!container) {
  40688. + DWC_ERROR("Cannot allocate memory for container");
  40689. + return;
  40690. + }
  40691. +
  40692. + container->name = DWC_STRDUP(name);
  40693. + if (!container->name) {
  40694. + DWC_ERROR("Cannot allocate memory for container->name");
  40695. + DWC_FREE(container);
  40696. + return;
  40697. + }
  40698. +
  40699. + container->cb = cb;
  40700. + container->data = data;
  40701. + container->wq = wq;
  40702. +
  40703. + tv.tv_sec = time / 1000;
  40704. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40705. + container->hz = tvtohz(&tv);
  40706. +
  40707. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40708. +
  40709. + TASK_INIT(&container->task, 0, do_work, container);
  40710. +
  40711. +#ifdef DEBUG
  40712. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40713. +#endif
  40714. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40715. +}
  40716. +
  40717. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  40718. +{
  40719. + return wq->pending;
  40720. +}
  40721. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  40722. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  40723. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-02-07 19:57:30.000000000 +0100
  40724. @@ -0,0 +1,1431 @@
  40725. +#include <linux/kernel.h>
  40726. +#include <linux/init.h>
  40727. +#include <linux/module.h>
  40728. +#include <linux/kthread.h>
  40729. +
  40730. +#ifdef DWC_CCLIB
  40731. +# include "dwc_cc.h"
  40732. +#endif
  40733. +
  40734. +#ifdef DWC_CRYPTOLIB
  40735. +# include "dwc_modpow.h"
  40736. +# include "dwc_dh.h"
  40737. +# include "dwc_crypto.h"
  40738. +#endif
  40739. +
  40740. +#ifdef DWC_NOTIFYLIB
  40741. +# include "dwc_notifier.h"
  40742. +#endif
  40743. +
  40744. +/* OS-Level Implementations */
  40745. +
  40746. +/* This is the Linux kernel implementation of the DWC platform library. */
  40747. +#include <linux/moduleparam.h>
  40748. +#include <linux/ctype.h>
  40749. +#include <linux/crypto.h>
  40750. +#include <linux/delay.h>
  40751. +#include <linux/device.h>
  40752. +#include <linux/dma-mapping.h>
  40753. +#include <linux/cdev.h>
  40754. +#include <linux/errno.h>
  40755. +#include <linux/interrupt.h>
  40756. +#include <linux/jiffies.h>
  40757. +#include <linux/list.h>
  40758. +#include <linux/pci.h>
  40759. +#include <linux/random.h>
  40760. +#include <linux/scatterlist.h>
  40761. +#include <linux/slab.h>
  40762. +#include <linux/stat.h>
  40763. +#include <linux/string.h>
  40764. +#include <linux/timer.h>
  40765. +#include <linux/usb.h>
  40766. +
  40767. +#include <linux/version.h>
  40768. +
  40769. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  40770. +# include <linux/usb/gadget.h>
  40771. +#else
  40772. +# include <linux/usb_gadget.h>
  40773. +#endif
  40774. +
  40775. +#include <asm/io.h>
  40776. +#include <asm/page.h>
  40777. +#include <asm/uaccess.h>
  40778. +#include <asm/unaligned.h>
  40779. +
  40780. +#include "dwc_os.h"
  40781. +#include "dwc_list.h"
  40782. +
  40783. +
  40784. +/* MISC */
  40785. +
  40786. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40787. +{
  40788. + return memset(dest, byte, size);
  40789. +}
  40790. +
  40791. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40792. +{
  40793. + return memcpy(dest, src, size);
  40794. +}
  40795. +
  40796. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40797. +{
  40798. + return memmove(dest, src, size);
  40799. +}
  40800. +
  40801. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40802. +{
  40803. + return memcmp(m1, m2, size);
  40804. +}
  40805. +
  40806. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40807. +{
  40808. + return strncmp(s1, s2, size);
  40809. +}
  40810. +
  40811. +int DWC_STRCMP(void *s1, void *s2)
  40812. +{
  40813. + return strcmp(s1, s2);
  40814. +}
  40815. +
  40816. +int DWC_STRLEN(char const *str)
  40817. +{
  40818. + return strlen(str);
  40819. +}
  40820. +
  40821. +char *DWC_STRCPY(char *to, char const *from)
  40822. +{
  40823. + return strcpy(to, from);
  40824. +}
  40825. +
  40826. +char *DWC_STRDUP(char const *str)
  40827. +{
  40828. + int len = DWC_STRLEN(str) + 1;
  40829. + char *new = DWC_ALLOC_ATOMIC(len);
  40830. +
  40831. + if (!new) {
  40832. + return NULL;
  40833. + }
  40834. +
  40835. + DWC_MEMCPY(new, str, len);
  40836. + return new;
  40837. +}
  40838. +
  40839. +int DWC_ATOI(const char *str, int32_t *value)
  40840. +{
  40841. + char *end = NULL;
  40842. +
  40843. + *value = simple_strtol(str, &end, 0);
  40844. + if (*end == '\0') {
  40845. + return 0;
  40846. + }
  40847. +
  40848. + return -1;
  40849. +}
  40850. +
  40851. +int DWC_ATOUI(const char *str, uint32_t *value)
  40852. +{
  40853. + char *end = NULL;
  40854. +
  40855. + *value = simple_strtoul(str, &end, 0);
  40856. + if (*end == '\0') {
  40857. + return 0;
  40858. + }
  40859. +
  40860. + return -1;
  40861. +}
  40862. +
  40863. +
  40864. +#ifdef DWC_UTFLIB
  40865. +/* From usbstring.c */
  40866. +
  40867. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40868. +{
  40869. + int count = 0;
  40870. + u8 c;
  40871. + u16 uchar;
  40872. +
  40873. + /* this insists on correct encodings, though not minimal ones.
  40874. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40875. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40876. + */
  40877. + while (len != 0 && (c = (u8) *s++) != 0) {
  40878. + if (unlikely(c & 0x80)) {
  40879. + // 2-byte sequence:
  40880. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40881. + if ((c & 0xe0) == 0xc0) {
  40882. + uchar = (c & 0x1f) << 6;
  40883. +
  40884. + c = (u8) *s++;
  40885. + if ((c & 0xc0) != 0xc0)
  40886. + goto fail;
  40887. + c &= 0x3f;
  40888. + uchar |= c;
  40889. +
  40890. + // 3-byte sequence (most CJKV characters):
  40891. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40892. + } else if ((c & 0xf0) == 0xe0) {
  40893. + uchar = (c & 0x0f) << 12;
  40894. +
  40895. + c = (u8) *s++;
  40896. + if ((c & 0xc0) != 0xc0)
  40897. + goto fail;
  40898. + c &= 0x3f;
  40899. + uchar |= c << 6;
  40900. +
  40901. + c = (u8) *s++;
  40902. + if ((c & 0xc0) != 0xc0)
  40903. + goto fail;
  40904. + c &= 0x3f;
  40905. + uchar |= c;
  40906. +
  40907. + /* no bogus surrogates */
  40908. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40909. + goto fail;
  40910. +
  40911. + // 4-byte sequence (surrogate pairs, currently rare):
  40912. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40913. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40914. + // (uuuuu = wwww + 1)
  40915. + // FIXME accept the surrogate code points (only)
  40916. + } else
  40917. + goto fail;
  40918. + } else
  40919. + uchar = c;
  40920. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40921. + count++;
  40922. + len--;
  40923. + }
  40924. + return count;
  40925. +fail:
  40926. + return -1;
  40927. +}
  40928. +#endif /* DWC_UTFLIB */
  40929. +
  40930. +
  40931. +/* dwc_debug.h */
  40932. +
  40933. +dwc_bool_t DWC_IN_IRQ(void)
  40934. +{
  40935. + return in_irq();
  40936. +}
  40937. +
  40938. +dwc_bool_t DWC_IN_BH(void)
  40939. +{
  40940. + return in_softirq();
  40941. +}
  40942. +
  40943. +void DWC_VPRINTF(char *format, va_list args)
  40944. +{
  40945. + vprintk(format, args);
  40946. +}
  40947. +
  40948. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40949. +{
  40950. + return vsnprintf(str, size, format, args);
  40951. +}
  40952. +
  40953. +void DWC_PRINTF(char *format, ...)
  40954. +{
  40955. + va_list args;
  40956. +
  40957. + va_start(args, format);
  40958. + DWC_VPRINTF(format, args);
  40959. + va_end(args);
  40960. +}
  40961. +
  40962. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40963. +{
  40964. + int retval;
  40965. + va_list args;
  40966. +
  40967. + va_start(args, format);
  40968. + retval = vsprintf(buffer, format, args);
  40969. + va_end(args);
  40970. + return retval;
  40971. +}
  40972. +
  40973. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40974. +{
  40975. + int retval;
  40976. + va_list args;
  40977. +
  40978. + va_start(args, format);
  40979. + retval = vsnprintf(buffer, size, format, args);
  40980. + va_end(args);
  40981. + return retval;
  40982. +}
  40983. +
  40984. +void __DWC_WARN(char *format, ...)
  40985. +{
  40986. + va_list args;
  40987. +
  40988. + va_start(args, format);
  40989. + DWC_PRINTF(KERN_WARNING);
  40990. + DWC_VPRINTF(format, args);
  40991. + va_end(args);
  40992. +}
  40993. +
  40994. +void __DWC_ERROR(char *format, ...)
  40995. +{
  40996. + va_list args;
  40997. +
  40998. + va_start(args, format);
  40999. + DWC_PRINTF(KERN_ERR);
  41000. + DWC_VPRINTF(format, args);
  41001. + va_end(args);
  41002. +}
  41003. +
  41004. +void DWC_EXCEPTION(char *format, ...)
  41005. +{
  41006. + va_list args;
  41007. +
  41008. + va_start(args, format);
  41009. + DWC_PRINTF(KERN_ERR);
  41010. + DWC_VPRINTF(format, args);
  41011. + va_end(args);
  41012. + BUG_ON(1);
  41013. +}
  41014. +
  41015. +#ifdef DEBUG
  41016. +void __DWC_DEBUG(char *format, ...)
  41017. +{
  41018. + va_list args;
  41019. +
  41020. + va_start(args, format);
  41021. + DWC_PRINTF(KERN_DEBUG);
  41022. + DWC_VPRINTF(format, args);
  41023. + va_end(args);
  41024. +}
  41025. +#endif
  41026. +
  41027. +
  41028. +/* dwc_mem.h */
  41029. +
  41030. +#if 0
  41031. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41032. + uint32_t align,
  41033. + uint32_t alloc)
  41034. +{
  41035. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41036. + size, align, alloc);
  41037. + return (dwc_pool_t *)pool;
  41038. +}
  41039. +
  41040. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41041. +{
  41042. + dma_pool_destroy((struct dma_pool *)pool);
  41043. +}
  41044. +
  41045. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41046. +{
  41047. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41048. +}
  41049. +
  41050. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41051. +{
  41052. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41053. + memset(..);
  41054. +}
  41055. +
  41056. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41057. +{
  41058. + dma_pool_free(pool, vaddr, daddr);
  41059. +}
  41060. +#endif
  41061. +
  41062. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41063. +{
  41064. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  41065. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  41066. +#else
  41067. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  41068. +#endif
  41069. + if (!buf) {
  41070. + return NULL;
  41071. + }
  41072. +
  41073. + memset(buf, 0, (size_t)size);
  41074. + return buf;
  41075. +}
  41076. +
  41077. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41078. +{
  41079. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  41080. + if (!buf) {
  41081. + return NULL;
  41082. + }
  41083. + memset(buf, 0, (size_t)size);
  41084. + return buf;
  41085. +}
  41086. +
  41087. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41088. +{
  41089. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  41090. +}
  41091. +
  41092. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41093. +{
  41094. + return kzalloc(size, GFP_KERNEL);
  41095. +}
  41096. +
  41097. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41098. +{
  41099. + return kzalloc(size, GFP_ATOMIC);
  41100. +}
  41101. +
  41102. +void __DWC_FREE(void *mem_ctx, void *addr)
  41103. +{
  41104. + kfree(addr);
  41105. +}
  41106. +
  41107. +
  41108. +#ifdef DWC_CRYPTOLIB
  41109. +/* dwc_crypto.h */
  41110. +
  41111. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41112. +{
  41113. + get_random_bytes(buffer, length);
  41114. +}
  41115. +
  41116. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41117. +{
  41118. + struct crypto_blkcipher *tfm;
  41119. + struct blkcipher_desc desc;
  41120. + struct scatterlist sgd;
  41121. + struct scatterlist sgs;
  41122. +
  41123. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41124. + if (tfm == NULL) {
  41125. + printk("failed to load transform for aes CBC\n");
  41126. + return -1;
  41127. + }
  41128. +
  41129. + crypto_blkcipher_setkey(tfm, key, keylen);
  41130. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41131. +
  41132. + sg_init_one(&sgd, out, messagelen);
  41133. + sg_init_one(&sgs, message, messagelen);
  41134. +
  41135. + desc.tfm = tfm;
  41136. + desc.flags = 0;
  41137. +
  41138. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41139. + crypto_free_blkcipher(tfm);
  41140. + DWC_ERROR("AES CBC encryption failed");
  41141. + return -1;
  41142. + }
  41143. +
  41144. + crypto_free_blkcipher(tfm);
  41145. + return 0;
  41146. +}
  41147. +
  41148. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41149. +{
  41150. + struct crypto_hash *tfm;
  41151. + struct hash_desc desc;
  41152. + struct scatterlist sg;
  41153. +
  41154. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41155. + if (IS_ERR(tfm)) {
  41156. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  41157. + return 0;
  41158. + }
  41159. + desc.tfm = tfm;
  41160. + desc.flags = 0;
  41161. +
  41162. + sg_init_one(&sg, message, len);
  41163. + crypto_hash_digest(&desc, &sg, len, out);
  41164. + crypto_free_hash(tfm);
  41165. +
  41166. + return 1;
  41167. +}
  41168. +
  41169. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41170. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41171. +{
  41172. + struct crypto_hash *tfm;
  41173. + struct hash_desc desc;
  41174. + struct scatterlist sg;
  41175. +
  41176. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41177. + if (IS_ERR(tfm)) {
  41178. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  41179. + return 0;
  41180. + }
  41181. + desc.tfm = tfm;
  41182. + desc.flags = 0;
  41183. +
  41184. + sg_init_one(&sg, message, messagelen);
  41185. + crypto_hash_setkey(tfm, key, keylen);
  41186. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41187. + crypto_free_hash(tfm);
  41188. +
  41189. + return 1;
  41190. +}
  41191. +#endif /* DWC_CRYPTOLIB */
  41192. +
  41193. +
  41194. +/* Byte Ordering Conversions */
  41195. +
  41196. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41197. +{
  41198. +#ifdef __LITTLE_ENDIAN
  41199. + return *p;
  41200. +#else
  41201. + uint8_t *u_p = (uint8_t *)p;
  41202. +
  41203. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41204. +#endif
  41205. +}
  41206. +
  41207. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41208. +{
  41209. +#ifdef __BIG_ENDIAN
  41210. + return *p;
  41211. +#else
  41212. + uint8_t *u_p = (uint8_t *)p;
  41213. +
  41214. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41215. +#endif
  41216. +}
  41217. +
  41218. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41219. +{
  41220. +#ifdef __LITTLE_ENDIAN
  41221. + return *p;
  41222. +#else
  41223. + uint8_t *u_p = (uint8_t *)p;
  41224. +
  41225. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41226. +#endif
  41227. +}
  41228. +
  41229. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41230. +{
  41231. +#ifdef __BIG_ENDIAN
  41232. + return *p;
  41233. +#else
  41234. + uint8_t *u_p = (uint8_t *)p;
  41235. +
  41236. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41237. +#endif
  41238. +}
  41239. +
  41240. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41241. +{
  41242. +#ifdef __LITTLE_ENDIAN
  41243. + return *p;
  41244. +#else
  41245. + uint8_t *u_p = (uint8_t *)p;
  41246. + return (u_p[1] | (u_p[0] << 8));
  41247. +#endif
  41248. +}
  41249. +
  41250. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41251. +{
  41252. +#ifdef __BIG_ENDIAN
  41253. + return *p;
  41254. +#else
  41255. + uint8_t *u_p = (uint8_t *)p;
  41256. + return (u_p[1] | (u_p[0] << 8));
  41257. +#endif
  41258. +}
  41259. +
  41260. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41261. +{
  41262. +#ifdef __LITTLE_ENDIAN
  41263. + return *p;
  41264. +#else
  41265. + uint8_t *u_p = (uint8_t *)p;
  41266. + return (u_p[1] | (u_p[0] << 8));
  41267. +#endif
  41268. +}
  41269. +
  41270. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41271. +{
  41272. +#ifdef __BIG_ENDIAN
  41273. + return *p;
  41274. +#else
  41275. + uint8_t *u_p = (uint8_t *)p;
  41276. + return (u_p[1] | (u_p[0] << 8));
  41277. +#endif
  41278. +}
  41279. +
  41280. +
  41281. +/* Registers */
  41282. +
  41283. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  41284. +{
  41285. + return readl(reg);
  41286. +}
  41287. +
  41288. +#if 0
  41289. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  41290. +{
  41291. +}
  41292. +#endif
  41293. +
  41294. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  41295. +{
  41296. + writel(value, reg);
  41297. +}
  41298. +
  41299. +#if 0
  41300. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  41301. +{
  41302. +}
  41303. +#endif
  41304. +
  41305. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  41306. +{
  41307. + unsigned long flags;
  41308. +
  41309. + local_irq_save(flags);
  41310. + local_fiq_disable();
  41311. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  41312. + local_irq_restore(flags);
  41313. +}
  41314. +
  41315. +#if 0
  41316. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  41317. +{
  41318. +}
  41319. +#endif
  41320. +
  41321. +
  41322. +/* Locking */
  41323. +
  41324. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41325. +{
  41326. + spinlock_t *sl = (spinlock_t *)1;
  41327. +
  41328. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41329. + sl = DWC_ALLOC(sizeof(*sl));
  41330. + if (!sl) {
  41331. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  41332. + return NULL;
  41333. + }
  41334. +
  41335. + spin_lock_init(sl);
  41336. +#endif
  41337. + return (dwc_spinlock_t *)sl;
  41338. +}
  41339. +
  41340. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41341. +{
  41342. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41343. + DWC_FREE(lock);
  41344. +#endif
  41345. +}
  41346. +
  41347. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41348. +{
  41349. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41350. + spin_lock((spinlock_t *)lock);
  41351. +#endif
  41352. +}
  41353. +
  41354. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41355. +{
  41356. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41357. + spin_unlock((spinlock_t *)lock);
  41358. +#endif
  41359. +}
  41360. +
  41361. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41362. +{
  41363. + dwc_irqflags_t f;
  41364. +
  41365. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41366. + spin_lock_irqsave((spinlock_t *)lock, f);
  41367. +#else
  41368. + local_irq_save(f);
  41369. +#endif
  41370. + *flags = f;
  41371. +}
  41372. +
  41373. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41374. +{
  41375. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41376. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  41377. +#else
  41378. + local_irq_restore(flags);
  41379. +#endif
  41380. +}
  41381. +
  41382. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41383. +{
  41384. + struct mutex *m;
  41385. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  41386. +
  41387. + if (!mutex) {
  41388. + DWC_ERROR("Cannot allocate memory for mutex\n");
  41389. + return NULL;
  41390. + }
  41391. +
  41392. + m = (struct mutex *)mutex;
  41393. + mutex_init(m);
  41394. + return mutex;
  41395. +}
  41396. +
  41397. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41398. +#else
  41399. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41400. +{
  41401. + mutex_destroy((struct mutex *)mutex);
  41402. + DWC_FREE(mutex);
  41403. +}
  41404. +#endif
  41405. +
  41406. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41407. +{
  41408. + struct mutex *m = (struct mutex *)mutex;
  41409. + mutex_lock(m);
  41410. +}
  41411. +
  41412. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41413. +{
  41414. + struct mutex *m = (struct mutex *)mutex;
  41415. + return mutex_trylock(m);
  41416. +}
  41417. +
  41418. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41419. +{
  41420. + struct mutex *m = (struct mutex *)mutex;
  41421. + mutex_unlock(m);
  41422. +}
  41423. +
  41424. +
  41425. +/* Timing */
  41426. +
  41427. +void DWC_UDELAY(uint32_t usecs)
  41428. +{
  41429. + udelay(usecs);
  41430. +}
  41431. +
  41432. +void DWC_MDELAY(uint32_t msecs)
  41433. +{
  41434. + mdelay(msecs);
  41435. +}
  41436. +
  41437. +void DWC_MSLEEP(uint32_t msecs)
  41438. +{
  41439. + msleep(msecs);
  41440. +}
  41441. +
  41442. +uint32_t DWC_TIME(void)
  41443. +{
  41444. + return jiffies_to_msecs(jiffies);
  41445. +}
  41446. +
  41447. +
  41448. +/* Timers */
  41449. +
  41450. +struct dwc_timer {
  41451. + struct timer_list *t;
  41452. + char *name;
  41453. + dwc_timer_callback_t cb;
  41454. + void *data;
  41455. + uint8_t scheduled;
  41456. + dwc_spinlock_t *lock;
  41457. +};
  41458. +
  41459. +static void timer_callback(unsigned long data)
  41460. +{
  41461. + dwc_timer_t *timer = (dwc_timer_t *)data;
  41462. + dwc_irqflags_t flags;
  41463. +
  41464. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41465. + timer->scheduled = 0;
  41466. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41467. + DWC_DEBUGC("Timer %s callback", timer->name);
  41468. + timer->cb(timer->data);
  41469. +}
  41470. +
  41471. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41472. +{
  41473. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41474. +
  41475. + if (!t) {
  41476. + DWC_ERROR("Cannot allocate memory for timer");
  41477. + return NULL;
  41478. + }
  41479. +
  41480. + t->t = DWC_ALLOC(sizeof(*t->t));
  41481. + if (!t->t) {
  41482. + DWC_ERROR("Cannot allocate memory for timer->t");
  41483. + goto no_timer;
  41484. + }
  41485. +
  41486. + t->name = DWC_STRDUP(name);
  41487. + if (!t->name) {
  41488. + DWC_ERROR("Cannot allocate memory for timer->name");
  41489. + goto no_name;
  41490. + }
  41491. +
  41492. + t->lock = DWC_SPINLOCK_ALLOC();
  41493. + if (!t->lock) {
  41494. + DWC_ERROR("Cannot allocate memory for lock");
  41495. + goto no_lock;
  41496. + }
  41497. +
  41498. + t->scheduled = 0;
  41499. + t->t->base = &boot_tvec_bases;
  41500. + t->t->expires = jiffies;
  41501. + setup_timer(t->t, timer_callback, (unsigned long)t);
  41502. +
  41503. + t->cb = cb;
  41504. + t->data = data;
  41505. +
  41506. + return t;
  41507. +
  41508. + no_lock:
  41509. + DWC_FREE(t->name);
  41510. + no_name:
  41511. + DWC_FREE(t->t);
  41512. + no_timer:
  41513. + DWC_FREE(t);
  41514. + return NULL;
  41515. +}
  41516. +
  41517. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41518. +{
  41519. + dwc_irqflags_t flags;
  41520. +
  41521. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41522. +
  41523. + if (timer->scheduled) {
  41524. + del_timer(timer->t);
  41525. + timer->scheduled = 0;
  41526. + }
  41527. +
  41528. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41529. + DWC_SPINLOCK_FREE(timer->lock);
  41530. + DWC_FREE(timer->t);
  41531. + DWC_FREE(timer->name);
  41532. + DWC_FREE(timer);
  41533. +}
  41534. +
  41535. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41536. +{
  41537. + dwc_irqflags_t flags;
  41538. +
  41539. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41540. +
  41541. + if (!timer->scheduled) {
  41542. + timer->scheduled = 1;
  41543. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  41544. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  41545. + add_timer(timer->t);
  41546. + } else {
  41547. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  41548. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  41549. + }
  41550. +
  41551. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41552. +}
  41553. +
  41554. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41555. +{
  41556. + del_timer(timer->t);
  41557. +}
  41558. +
  41559. +
  41560. +/* Wait Queues */
  41561. +
  41562. +struct dwc_waitq {
  41563. + wait_queue_head_t queue;
  41564. + int abort;
  41565. +};
  41566. +
  41567. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41568. +{
  41569. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41570. +
  41571. + if (!wq) {
  41572. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  41573. + return NULL;
  41574. + }
  41575. +
  41576. + init_waitqueue_head(&wq->queue);
  41577. + wq->abort = 0;
  41578. + return wq;
  41579. +}
  41580. +
  41581. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41582. +{
  41583. + DWC_FREE(wq);
  41584. +}
  41585. +
  41586. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41587. +{
  41588. + int result = wait_event_interruptible(wq->queue,
  41589. + cond(data) || wq->abort);
  41590. + if (result == -ERESTARTSYS) {
  41591. + wq->abort = 0;
  41592. + return -DWC_E_RESTART;
  41593. + }
  41594. +
  41595. + if (wq->abort == 1) {
  41596. + wq->abort = 0;
  41597. + return -DWC_E_ABORT;
  41598. + }
  41599. +
  41600. + wq->abort = 0;
  41601. +
  41602. + if (result == 0) {
  41603. + return 0;
  41604. + }
  41605. +
  41606. + return -DWC_E_UNKNOWN;
  41607. +}
  41608. +
  41609. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41610. + void *data, int32_t msecs)
  41611. +{
  41612. + int32_t tmsecs;
  41613. + int result = wait_event_interruptible_timeout(wq->queue,
  41614. + cond(data) || wq->abort,
  41615. + msecs_to_jiffies(msecs));
  41616. + if (result == -ERESTARTSYS) {
  41617. + wq->abort = 0;
  41618. + return -DWC_E_RESTART;
  41619. + }
  41620. +
  41621. + if (wq->abort == 1) {
  41622. + wq->abort = 0;
  41623. + return -DWC_E_ABORT;
  41624. + }
  41625. +
  41626. + wq->abort = 0;
  41627. +
  41628. + if (result > 0) {
  41629. + tmsecs = jiffies_to_msecs(result);
  41630. + if (!tmsecs) {
  41631. + return 1;
  41632. + }
  41633. +
  41634. + return tmsecs;
  41635. + }
  41636. +
  41637. + if (result == 0) {
  41638. + return -DWC_E_TIMEOUT;
  41639. + }
  41640. +
  41641. + return -DWC_E_UNKNOWN;
  41642. +}
  41643. +
  41644. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41645. +{
  41646. + wq->abort = 0;
  41647. + wake_up_interruptible(&wq->queue);
  41648. +}
  41649. +
  41650. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41651. +{
  41652. + wq->abort = 1;
  41653. + wake_up_interruptible(&wq->queue);
  41654. +}
  41655. +
  41656. +
  41657. +/* Threading */
  41658. +
  41659. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41660. +{
  41661. + struct task_struct *thread = kthread_run(func, data, name);
  41662. +
  41663. + if (thread == ERR_PTR(-ENOMEM)) {
  41664. + return NULL;
  41665. + }
  41666. +
  41667. + return (dwc_thread_t *)thread;
  41668. +}
  41669. +
  41670. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41671. +{
  41672. + return kthread_stop((struct task_struct *)thread);
  41673. +}
  41674. +
  41675. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  41676. +{
  41677. + return kthread_should_stop();
  41678. +}
  41679. +
  41680. +
  41681. +/* tasklets
  41682. + - run in interrupt context (cannot sleep)
  41683. + - each tasklet runs on a single CPU
  41684. + - different tasklets can be running simultaneously on different CPUs
  41685. + */
  41686. +struct dwc_tasklet {
  41687. + struct tasklet_struct t;
  41688. + dwc_tasklet_callback_t cb;
  41689. + void *data;
  41690. +};
  41691. +
  41692. +static void tasklet_callback(unsigned long data)
  41693. +{
  41694. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  41695. + t->cb(t->data);
  41696. +}
  41697. +
  41698. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41699. +{
  41700. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  41701. +
  41702. + if (t) {
  41703. + t->cb = cb;
  41704. + t->data = data;
  41705. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  41706. + } else {
  41707. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  41708. + }
  41709. +
  41710. + return t;
  41711. +}
  41712. +
  41713. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41714. +{
  41715. + DWC_FREE(task);
  41716. +}
  41717. +
  41718. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41719. +{
  41720. + tasklet_schedule(&task->t);
  41721. +}
  41722. +
  41723. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  41724. +{
  41725. + tasklet_hi_schedule(&task->t);
  41726. +}
  41727. +
  41728. +
  41729. +/* workqueues
  41730. + - run in process context (can sleep)
  41731. + */
  41732. +typedef struct work_container {
  41733. + dwc_work_callback_t cb;
  41734. + void *data;
  41735. + dwc_workq_t *wq;
  41736. + char *name;
  41737. +
  41738. +#ifdef DEBUG
  41739. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41740. +#endif
  41741. + struct delayed_work work;
  41742. +} work_container_t;
  41743. +
  41744. +#ifdef DEBUG
  41745. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41746. +#endif
  41747. +
  41748. +struct dwc_workq {
  41749. + struct workqueue_struct *wq;
  41750. + dwc_spinlock_t *lock;
  41751. + dwc_waitq_t *waitq;
  41752. + int pending;
  41753. +
  41754. +#ifdef DEBUG
  41755. + struct work_container_queue entries;
  41756. +#endif
  41757. +};
  41758. +
  41759. +static void do_work(struct work_struct *work)
  41760. +{
  41761. + dwc_irqflags_t flags;
  41762. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  41763. + work_container_t *container = container_of(dw, struct work_container, work);
  41764. + dwc_workq_t *wq = container->wq;
  41765. +
  41766. + container->cb(container->data);
  41767. +
  41768. +#ifdef DEBUG
  41769. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41770. +#endif
  41771. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  41772. + if (container->name) {
  41773. + DWC_FREE(container->name);
  41774. + }
  41775. + DWC_FREE(container);
  41776. +
  41777. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41778. + wq->pending--;
  41779. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41780. + DWC_WAITQ_TRIGGER(wq->waitq);
  41781. +}
  41782. +
  41783. +static int work_done(void *data)
  41784. +{
  41785. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41786. + return workq->pending == 0;
  41787. +}
  41788. +
  41789. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41790. +{
  41791. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41792. +}
  41793. +
  41794. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41795. +{
  41796. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41797. +
  41798. + if (!wq) {
  41799. + return NULL;
  41800. + }
  41801. +
  41802. + wq->wq = create_singlethread_workqueue(name);
  41803. + if (!wq->wq) {
  41804. + goto no_wq;
  41805. + }
  41806. +
  41807. + wq->pending = 0;
  41808. +
  41809. + wq->lock = DWC_SPINLOCK_ALLOC();
  41810. + if (!wq->lock) {
  41811. + goto no_lock;
  41812. + }
  41813. +
  41814. + wq->waitq = DWC_WAITQ_ALLOC();
  41815. + if (!wq->waitq) {
  41816. + goto no_waitq;
  41817. + }
  41818. +
  41819. +#ifdef DEBUG
  41820. + DWC_CIRCLEQ_INIT(&wq->entries);
  41821. +#endif
  41822. + return wq;
  41823. +
  41824. + no_waitq:
  41825. + DWC_SPINLOCK_FREE(wq->lock);
  41826. + no_lock:
  41827. + destroy_workqueue(wq->wq);
  41828. + no_wq:
  41829. + DWC_FREE(wq);
  41830. +
  41831. + return NULL;
  41832. +}
  41833. +
  41834. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41835. +{
  41836. +#ifdef DEBUG
  41837. + if (wq->pending != 0) {
  41838. + struct work_container *wc;
  41839. + DWC_ERROR("Destroying work queue with pending work");
  41840. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  41841. + DWC_ERROR("Work %s still pending", wc->name);
  41842. + }
  41843. + }
  41844. +#endif
  41845. + destroy_workqueue(wq->wq);
  41846. + DWC_SPINLOCK_FREE(wq->lock);
  41847. + DWC_WAITQ_FREE(wq->waitq);
  41848. + DWC_FREE(wq);
  41849. +}
  41850. +
  41851. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41852. + char *format, ...)
  41853. +{
  41854. + dwc_irqflags_t flags;
  41855. + work_container_t *container;
  41856. + static char name[128];
  41857. + va_list args;
  41858. +
  41859. + va_start(args, format);
  41860. + DWC_VSNPRINTF(name, 128, format, args);
  41861. + va_end(args);
  41862. +
  41863. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41864. + wq->pending++;
  41865. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41866. + DWC_WAITQ_TRIGGER(wq->waitq);
  41867. +
  41868. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41869. + if (!container) {
  41870. + DWC_ERROR("Cannot allocate memory for container\n");
  41871. + return;
  41872. + }
  41873. +
  41874. + container->name = DWC_STRDUP(name);
  41875. + if (!container->name) {
  41876. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41877. + DWC_FREE(container);
  41878. + return;
  41879. + }
  41880. +
  41881. + container->cb = cb;
  41882. + container->data = data;
  41883. + container->wq = wq;
  41884. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41885. + INIT_WORK(&container->work.work, do_work);
  41886. +
  41887. +#ifdef DEBUG
  41888. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41889. +#endif
  41890. + queue_work(wq->wq, &container->work.work);
  41891. +}
  41892. +
  41893. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41894. + void *data, uint32_t time, char *format, ...)
  41895. +{
  41896. + dwc_irqflags_t flags;
  41897. + work_container_t *container;
  41898. + static char name[128];
  41899. + va_list args;
  41900. +
  41901. + va_start(args, format);
  41902. + DWC_VSNPRINTF(name, 128, format, args);
  41903. + va_end(args);
  41904. +
  41905. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41906. + wq->pending++;
  41907. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41908. + DWC_WAITQ_TRIGGER(wq->waitq);
  41909. +
  41910. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41911. + if (!container) {
  41912. + DWC_ERROR("Cannot allocate memory for container\n");
  41913. + return;
  41914. + }
  41915. +
  41916. + container->name = DWC_STRDUP(name);
  41917. + if (!container->name) {
  41918. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41919. + DWC_FREE(container);
  41920. + return;
  41921. + }
  41922. +
  41923. + container->cb = cb;
  41924. + container->data = data;
  41925. + container->wq = wq;
  41926. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41927. + INIT_DELAYED_WORK(&container->work, do_work);
  41928. +
  41929. +#ifdef DEBUG
  41930. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41931. +#endif
  41932. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  41933. +}
  41934. +
  41935. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41936. +{
  41937. + return wq->pending;
  41938. +}
  41939. +
  41940. +
  41941. +#ifdef DWC_LIBMODULE
  41942. +
  41943. +#ifdef DWC_CCLIB
  41944. +/* CC */
  41945. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  41946. +EXPORT_SYMBOL(dwc_cc_if_free);
  41947. +EXPORT_SYMBOL(dwc_cc_clear);
  41948. +EXPORT_SYMBOL(dwc_cc_add);
  41949. +EXPORT_SYMBOL(dwc_cc_remove);
  41950. +EXPORT_SYMBOL(dwc_cc_change);
  41951. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  41952. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  41953. +EXPORT_SYMBOL(dwc_cc_match_chid);
  41954. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  41955. +EXPORT_SYMBOL(dwc_cc_ck);
  41956. +EXPORT_SYMBOL(dwc_cc_chid);
  41957. +EXPORT_SYMBOL(dwc_cc_cdid);
  41958. +EXPORT_SYMBOL(dwc_cc_name);
  41959. +#endif /* DWC_CCLIB */
  41960. +
  41961. +#ifdef DWC_CRYPTOLIB
  41962. +# ifndef CONFIG_MACH_IPMATE
  41963. +/* Modpow */
  41964. +EXPORT_SYMBOL(dwc_modpow);
  41965. +
  41966. +/* DH */
  41967. +EXPORT_SYMBOL(dwc_dh_modpow);
  41968. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  41969. +EXPORT_SYMBOL(dwc_dh_pk);
  41970. +# endif /* CONFIG_MACH_IPMATE */
  41971. +
  41972. +/* Crypto */
  41973. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  41974. +EXPORT_SYMBOL(dwc_wusb_cmf);
  41975. +EXPORT_SYMBOL(dwc_wusb_prf);
  41976. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  41977. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  41978. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  41979. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  41980. +#endif /* DWC_CRYPTOLIB */
  41981. +
  41982. +/* Notification */
  41983. +#ifdef DWC_NOTIFYLIB
  41984. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  41985. +EXPORT_SYMBOL(dwc_free_notification_manager);
  41986. +EXPORT_SYMBOL(dwc_register_notifier);
  41987. +EXPORT_SYMBOL(dwc_unregister_notifier);
  41988. +EXPORT_SYMBOL(dwc_add_observer);
  41989. +EXPORT_SYMBOL(dwc_remove_observer);
  41990. +EXPORT_SYMBOL(dwc_notify);
  41991. +#endif
  41992. +
  41993. +/* Memory Debugging Routines */
  41994. +#ifdef DWC_DEBUG_MEMORY
  41995. +EXPORT_SYMBOL(dwc_alloc_debug);
  41996. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  41997. +EXPORT_SYMBOL(dwc_free_debug);
  41998. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  41999. +EXPORT_SYMBOL(dwc_dma_free_debug);
  42000. +#endif
  42001. +
  42002. +EXPORT_SYMBOL(DWC_MEMSET);
  42003. +EXPORT_SYMBOL(DWC_MEMCPY);
  42004. +EXPORT_SYMBOL(DWC_MEMMOVE);
  42005. +EXPORT_SYMBOL(DWC_MEMCMP);
  42006. +EXPORT_SYMBOL(DWC_STRNCMP);
  42007. +EXPORT_SYMBOL(DWC_STRCMP);
  42008. +EXPORT_SYMBOL(DWC_STRLEN);
  42009. +EXPORT_SYMBOL(DWC_STRCPY);
  42010. +EXPORT_SYMBOL(DWC_STRDUP);
  42011. +EXPORT_SYMBOL(DWC_ATOI);
  42012. +EXPORT_SYMBOL(DWC_ATOUI);
  42013. +
  42014. +#ifdef DWC_UTFLIB
  42015. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  42016. +#endif /* DWC_UTFLIB */
  42017. +
  42018. +EXPORT_SYMBOL(DWC_IN_IRQ);
  42019. +EXPORT_SYMBOL(DWC_IN_BH);
  42020. +EXPORT_SYMBOL(DWC_VPRINTF);
  42021. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  42022. +EXPORT_SYMBOL(DWC_PRINTF);
  42023. +EXPORT_SYMBOL(DWC_SPRINTF);
  42024. +EXPORT_SYMBOL(DWC_SNPRINTF);
  42025. +EXPORT_SYMBOL(__DWC_WARN);
  42026. +EXPORT_SYMBOL(__DWC_ERROR);
  42027. +EXPORT_SYMBOL(DWC_EXCEPTION);
  42028. +
  42029. +#ifdef DEBUG
  42030. +EXPORT_SYMBOL(__DWC_DEBUG);
  42031. +#endif
  42032. +
  42033. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  42034. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  42035. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  42036. +EXPORT_SYMBOL(__DWC_ALLOC);
  42037. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  42038. +EXPORT_SYMBOL(__DWC_FREE);
  42039. +
  42040. +#ifdef DWC_CRYPTOLIB
  42041. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  42042. +EXPORT_SYMBOL(DWC_AES_CBC);
  42043. +EXPORT_SYMBOL(DWC_SHA256);
  42044. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  42045. +#endif
  42046. +
  42047. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  42048. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  42049. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  42050. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  42051. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  42052. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  42053. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  42054. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  42055. +EXPORT_SYMBOL(DWC_READ_REG32);
  42056. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  42057. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  42058. +
  42059. +#if 0
  42060. +EXPORT_SYMBOL(DWC_READ_REG64);
  42061. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  42062. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  42063. +#endif
  42064. +
  42065. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  42066. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  42067. +EXPORT_SYMBOL(DWC_SPINLOCK);
  42068. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  42069. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  42070. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  42071. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  42072. +
  42073. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  42074. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  42075. +#endif
  42076. +
  42077. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  42078. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  42079. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  42080. +EXPORT_SYMBOL(DWC_UDELAY);
  42081. +EXPORT_SYMBOL(DWC_MDELAY);
  42082. +EXPORT_SYMBOL(DWC_MSLEEP);
  42083. +EXPORT_SYMBOL(DWC_TIME);
  42084. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  42085. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  42086. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  42087. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  42088. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  42089. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  42090. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  42091. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  42092. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  42093. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  42094. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  42095. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  42096. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  42097. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  42098. +EXPORT_SYMBOL(DWC_TASK_FREE);
  42099. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  42100. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  42101. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  42102. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  42103. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  42104. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  42105. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  42106. +
  42107. +static int dwc_common_port_init_module(void)
  42108. +{
  42109. + int result = 0;
  42110. +
  42111. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  42112. +
  42113. +#ifdef DWC_DEBUG_MEMORY
  42114. + result = dwc_memory_debug_start(NULL);
  42115. + if (result) {
  42116. + printk(KERN_ERR
  42117. + "dwc_memory_debug_start() failed with error %d\n",
  42118. + result);
  42119. + return result;
  42120. + }
  42121. +#endif
  42122. +
  42123. +#ifdef DWC_NOTIFYLIB
  42124. + result = dwc_alloc_notification_manager(NULL, NULL);
  42125. + if (result) {
  42126. + printk(KERN_ERR
  42127. + "dwc_alloc_notification_manager() failed with error %d\n",
  42128. + result);
  42129. + return result;
  42130. + }
  42131. +#endif
  42132. + return result;
  42133. +}
  42134. +
  42135. +static void dwc_common_port_exit_module(void)
  42136. +{
  42137. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  42138. +
  42139. +#ifdef DWC_NOTIFYLIB
  42140. + dwc_free_notification_manager();
  42141. +#endif
  42142. +
  42143. +#ifdef DWC_DEBUG_MEMORY
  42144. + dwc_memory_debug_stop();
  42145. +#endif
  42146. +}
  42147. +
  42148. +module_init(dwc_common_port_init_module);
  42149. +module_exit(dwc_common_port_exit_module);
  42150. +
  42151. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  42152. +MODULE_AUTHOR("Synopsys Inc.");
  42153. +MODULE_LICENSE ("GPL");
  42154. +
  42155. +#endif /* DWC_LIBMODULE */
  42156. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  42157. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  42158. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-02-07 19:57:30.000000000 +0100
  42159. @@ -0,0 +1,1275 @@
  42160. +#include "dwc_os.h"
  42161. +#include "dwc_list.h"
  42162. +
  42163. +#ifdef DWC_CCLIB
  42164. +# include "dwc_cc.h"
  42165. +#endif
  42166. +
  42167. +#ifdef DWC_CRYPTOLIB
  42168. +# include "dwc_modpow.h"
  42169. +# include "dwc_dh.h"
  42170. +# include "dwc_crypto.h"
  42171. +#endif
  42172. +
  42173. +#ifdef DWC_NOTIFYLIB
  42174. +# include "dwc_notifier.h"
  42175. +#endif
  42176. +
  42177. +/* OS-Level Implementations */
  42178. +
  42179. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  42180. +
  42181. +
  42182. +/* MISC */
  42183. +
  42184. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  42185. +{
  42186. + return memset(dest, byte, size);
  42187. +}
  42188. +
  42189. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  42190. +{
  42191. + return memcpy(dest, src, size);
  42192. +}
  42193. +
  42194. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  42195. +{
  42196. + bcopy(src, dest, size);
  42197. + return dest;
  42198. +}
  42199. +
  42200. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  42201. +{
  42202. + return memcmp(m1, m2, size);
  42203. +}
  42204. +
  42205. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  42206. +{
  42207. + return strncmp(s1, s2, size);
  42208. +}
  42209. +
  42210. +int DWC_STRCMP(void *s1, void *s2)
  42211. +{
  42212. + return strcmp(s1, s2);
  42213. +}
  42214. +
  42215. +int DWC_STRLEN(char const *str)
  42216. +{
  42217. + return strlen(str);
  42218. +}
  42219. +
  42220. +char *DWC_STRCPY(char *to, char const *from)
  42221. +{
  42222. + return strcpy(to, from);
  42223. +}
  42224. +
  42225. +char *DWC_STRDUP(char const *str)
  42226. +{
  42227. + int len = DWC_STRLEN(str) + 1;
  42228. + char *new = DWC_ALLOC_ATOMIC(len);
  42229. +
  42230. + if (!new) {
  42231. + return NULL;
  42232. + }
  42233. +
  42234. + DWC_MEMCPY(new, str, len);
  42235. + return new;
  42236. +}
  42237. +
  42238. +int DWC_ATOI(char *str, int32_t *value)
  42239. +{
  42240. + char *end = NULL;
  42241. +
  42242. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  42243. + * should be equivalent on 2's complement machines
  42244. + */
  42245. + *value = strtoul(str, &end, 0);
  42246. + if (*end == '\0') {
  42247. + return 0;
  42248. + }
  42249. +
  42250. + return -1;
  42251. +}
  42252. +
  42253. +int DWC_ATOUI(char *str, uint32_t *value)
  42254. +{
  42255. + char *end = NULL;
  42256. +
  42257. + *value = strtoul(str, &end, 0);
  42258. + if (*end == '\0') {
  42259. + return 0;
  42260. + }
  42261. +
  42262. + return -1;
  42263. +}
  42264. +
  42265. +
  42266. +#ifdef DWC_UTFLIB
  42267. +/* From usbstring.c */
  42268. +
  42269. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  42270. +{
  42271. + int count = 0;
  42272. + u8 c;
  42273. + u16 uchar;
  42274. +
  42275. + /* this insists on correct encodings, though not minimal ones.
  42276. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  42277. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  42278. + */
  42279. + while (len != 0 && (c = (u8) *s++) != 0) {
  42280. + if (unlikely(c & 0x80)) {
  42281. + // 2-byte sequence:
  42282. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  42283. + if ((c & 0xe0) == 0xc0) {
  42284. + uchar = (c & 0x1f) << 6;
  42285. +
  42286. + c = (u8) *s++;
  42287. + if ((c & 0xc0) != 0xc0)
  42288. + goto fail;
  42289. + c &= 0x3f;
  42290. + uchar |= c;
  42291. +
  42292. + // 3-byte sequence (most CJKV characters):
  42293. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  42294. + } else if ((c & 0xf0) == 0xe0) {
  42295. + uchar = (c & 0x0f) << 12;
  42296. +
  42297. + c = (u8) *s++;
  42298. + if ((c & 0xc0) != 0xc0)
  42299. + goto fail;
  42300. + c &= 0x3f;
  42301. + uchar |= c << 6;
  42302. +
  42303. + c = (u8) *s++;
  42304. + if ((c & 0xc0) != 0xc0)
  42305. + goto fail;
  42306. + c &= 0x3f;
  42307. + uchar |= c;
  42308. +
  42309. + /* no bogus surrogates */
  42310. + if (0xd800 <= uchar && uchar <= 0xdfff)
  42311. + goto fail;
  42312. +
  42313. + // 4-byte sequence (surrogate pairs, currently rare):
  42314. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  42315. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  42316. + // (uuuuu = wwww + 1)
  42317. + // FIXME accept the surrogate code points (only)
  42318. + } else
  42319. + goto fail;
  42320. + } else
  42321. + uchar = c;
  42322. + put_unaligned (cpu_to_le16 (uchar), cp++);
  42323. + count++;
  42324. + len--;
  42325. + }
  42326. + return count;
  42327. +fail:
  42328. + return -1;
  42329. +}
  42330. +
  42331. +#endif /* DWC_UTFLIB */
  42332. +
  42333. +
  42334. +/* dwc_debug.h */
  42335. +
  42336. +dwc_bool_t DWC_IN_IRQ(void)
  42337. +{
  42338. +// return in_irq();
  42339. + return 0;
  42340. +}
  42341. +
  42342. +dwc_bool_t DWC_IN_BH(void)
  42343. +{
  42344. +// return in_softirq();
  42345. + return 0;
  42346. +}
  42347. +
  42348. +void DWC_VPRINTF(char *format, va_list args)
  42349. +{
  42350. + vprintf(format, args);
  42351. +}
  42352. +
  42353. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42354. +{
  42355. + return vsnprintf(str, size, format, args);
  42356. +}
  42357. +
  42358. +void DWC_PRINTF(char *format, ...)
  42359. +{
  42360. + va_list args;
  42361. +
  42362. + va_start(args, format);
  42363. + DWC_VPRINTF(format, args);
  42364. + va_end(args);
  42365. +}
  42366. +
  42367. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42368. +{
  42369. + int retval;
  42370. + va_list args;
  42371. +
  42372. + va_start(args, format);
  42373. + retval = vsprintf(buffer, format, args);
  42374. + va_end(args);
  42375. + return retval;
  42376. +}
  42377. +
  42378. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42379. +{
  42380. + int retval;
  42381. + va_list args;
  42382. +
  42383. + va_start(args, format);
  42384. + retval = vsnprintf(buffer, size, format, args);
  42385. + va_end(args);
  42386. + return retval;
  42387. +}
  42388. +
  42389. +void __DWC_WARN(char *format, ...)
  42390. +{
  42391. + va_list args;
  42392. +
  42393. + va_start(args, format);
  42394. + DWC_VPRINTF(format, args);
  42395. + va_end(args);
  42396. +}
  42397. +
  42398. +void __DWC_ERROR(char *format, ...)
  42399. +{
  42400. + va_list args;
  42401. +
  42402. + va_start(args, format);
  42403. + DWC_VPRINTF(format, args);
  42404. + va_end(args);
  42405. +}
  42406. +
  42407. +void DWC_EXCEPTION(char *format, ...)
  42408. +{
  42409. + va_list args;
  42410. +
  42411. + va_start(args, format);
  42412. + DWC_VPRINTF(format, args);
  42413. + va_end(args);
  42414. +// BUG_ON(1); ???
  42415. +}
  42416. +
  42417. +#ifdef DEBUG
  42418. +void __DWC_DEBUG(char *format, ...)
  42419. +{
  42420. + va_list args;
  42421. +
  42422. + va_start(args, format);
  42423. + DWC_VPRINTF(format, args);
  42424. + va_end(args);
  42425. +}
  42426. +#endif
  42427. +
  42428. +
  42429. +/* dwc_mem.h */
  42430. +
  42431. +#if 0
  42432. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42433. + uint32_t align,
  42434. + uint32_t alloc)
  42435. +{
  42436. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42437. + size, align, alloc);
  42438. + return (dwc_pool_t *)pool;
  42439. +}
  42440. +
  42441. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42442. +{
  42443. + dma_pool_destroy((struct dma_pool *)pool);
  42444. +}
  42445. +
  42446. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42447. +{
  42448. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42449. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  42450. +}
  42451. +
  42452. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42453. +{
  42454. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42455. + memset(..);
  42456. +}
  42457. +
  42458. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42459. +{
  42460. + dma_pool_free(pool, vaddr, daddr);
  42461. +}
  42462. +#endif
  42463. +
  42464. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42465. +{
  42466. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42467. + int error;
  42468. +
  42469. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  42470. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  42471. + &dma->nsegs, BUS_DMA_NOWAIT);
  42472. + if (error) {
  42473. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  42474. + (uintmax_t)size, error);
  42475. + goto fail_0;
  42476. + }
  42477. +
  42478. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  42479. + (caddr_t *)&dma->dma_vaddr,
  42480. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  42481. + if (error) {
  42482. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  42483. + goto fail_1;
  42484. + }
  42485. +
  42486. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  42487. + BUS_DMA_NOWAIT, &dma->dma_map);
  42488. + if (error) {
  42489. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  42490. + goto fail_2;
  42491. + }
  42492. +
  42493. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  42494. + size, NULL, BUS_DMA_NOWAIT);
  42495. + if (error) {
  42496. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  42497. + goto fail_3;
  42498. + }
  42499. +
  42500. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  42501. + *dma_addr = dma->dma_paddr;
  42502. + return dma->dma_vaddr;
  42503. +
  42504. +fail_3:
  42505. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42506. +fail_2:
  42507. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42508. +fail_1:
  42509. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42510. +fail_0:
  42511. + dma->dma_map = NULL;
  42512. + dma->dma_vaddr = NULL;
  42513. + dma->nsegs = 0;
  42514. +
  42515. + return NULL;
  42516. +}
  42517. +
  42518. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42519. +{
  42520. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42521. +
  42522. + if (dma->dma_map != NULL) {
  42523. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  42524. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  42525. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  42526. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42527. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42528. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42529. + dma->dma_paddr = 0;
  42530. + dma->dma_map = NULL;
  42531. + dma->dma_vaddr = NULL;
  42532. + dma->nsegs = 0;
  42533. + }
  42534. +}
  42535. +
  42536. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42537. +{
  42538. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  42539. +}
  42540. +
  42541. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42542. +{
  42543. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  42544. +}
  42545. +
  42546. +void __DWC_FREE(void *mem_ctx, void *addr)
  42547. +{
  42548. + free(addr, M_DEVBUF);
  42549. +}
  42550. +
  42551. +
  42552. +#ifdef DWC_CRYPTOLIB
  42553. +/* dwc_crypto.h */
  42554. +
  42555. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42556. +{
  42557. + get_random_bytes(buffer, length);
  42558. +}
  42559. +
  42560. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42561. +{
  42562. + struct crypto_blkcipher *tfm;
  42563. + struct blkcipher_desc desc;
  42564. + struct scatterlist sgd;
  42565. + struct scatterlist sgs;
  42566. +
  42567. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42568. + if (tfm == NULL) {
  42569. + printk("failed to load transform for aes CBC\n");
  42570. + return -1;
  42571. + }
  42572. +
  42573. + crypto_blkcipher_setkey(tfm, key, keylen);
  42574. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42575. +
  42576. + sg_init_one(&sgd, out, messagelen);
  42577. + sg_init_one(&sgs, message, messagelen);
  42578. +
  42579. + desc.tfm = tfm;
  42580. + desc.flags = 0;
  42581. +
  42582. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42583. + crypto_free_blkcipher(tfm);
  42584. + DWC_ERROR("AES CBC encryption failed");
  42585. + return -1;
  42586. + }
  42587. +
  42588. + crypto_free_blkcipher(tfm);
  42589. + return 0;
  42590. +}
  42591. +
  42592. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42593. +{
  42594. + struct crypto_hash *tfm;
  42595. + struct hash_desc desc;
  42596. + struct scatterlist sg;
  42597. +
  42598. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42599. + if (IS_ERR(tfm)) {
  42600. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  42601. + return 0;
  42602. + }
  42603. + desc.tfm = tfm;
  42604. + desc.flags = 0;
  42605. +
  42606. + sg_init_one(&sg, message, len);
  42607. + crypto_hash_digest(&desc, &sg, len, out);
  42608. + crypto_free_hash(tfm);
  42609. +
  42610. + return 1;
  42611. +}
  42612. +
  42613. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42614. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42615. +{
  42616. + struct crypto_hash *tfm;
  42617. + struct hash_desc desc;
  42618. + struct scatterlist sg;
  42619. +
  42620. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42621. + if (IS_ERR(tfm)) {
  42622. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  42623. + return 0;
  42624. + }
  42625. + desc.tfm = tfm;
  42626. + desc.flags = 0;
  42627. +
  42628. + sg_init_one(&sg, message, messagelen);
  42629. + crypto_hash_setkey(tfm, key, keylen);
  42630. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42631. + crypto_free_hash(tfm);
  42632. +
  42633. + return 1;
  42634. +}
  42635. +
  42636. +#endif /* DWC_CRYPTOLIB */
  42637. +
  42638. +
  42639. +/* Byte Ordering Conversions */
  42640. +
  42641. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42642. +{
  42643. +#ifdef __LITTLE_ENDIAN
  42644. + return *p;
  42645. +#else
  42646. + uint8_t *u_p = (uint8_t *)p;
  42647. +
  42648. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42649. +#endif
  42650. +}
  42651. +
  42652. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42653. +{
  42654. +#ifdef __BIG_ENDIAN
  42655. + return *p;
  42656. +#else
  42657. + uint8_t *u_p = (uint8_t *)p;
  42658. +
  42659. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42660. +#endif
  42661. +}
  42662. +
  42663. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42664. +{
  42665. +#ifdef __LITTLE_ENDIAN
  42666. + return *p;
  42667. +#else
  42668. + uint8_t *u_p = (uint8_t *)p;
  42669. +
  42670. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42671. +#endif
  42672. +}
  42673. +
  42674. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42675. +{
  42676. +#ifdef __BIG_ENDIAN
  42677. + return *p;
  42678. +#else
  42679. + uint8_t *u_p = (uint8_t *)p;
  42680. +
  42681. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42682. +#endif
  42683. +}
  42684. +
  42685. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42686. +{
  42687. +#ifdef __LITTLE_ENDIAN
  42688. + return *p;
  42689. +#else
  42690. + uint8_t *u_p = (uint8_t *)p;
  42691. + return (u_p[1] | (u_p[0] << 8));
  42692. +#endif
  42693. +}
  42694. +
  42695. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42696. +{
  42697. +#ifdef __BIG_ENDIAN
  42698. + return *p;
  42699. +#else
  42700. + uint8_t *u_p = (uint8_t *)p;
  42701. + return (u_p[1] | (u_p[0] << 8));
  42702. +#endif
  42703. +}
  42704. +
  42705. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42706. +{
  42707. +#ifdef __LITTLE_ENDIAN
  42708. + return *p;
  42709. +#else
  42710. + uint8_t *u_p = (uint8_t *)p;
  42711. + return (u_p[1] | (u_p[0] << 8));
  42712. +#endif
  42713. +}
  42714. +
  42715. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42716. +{
  42717. +#ifdef __BIG_ENDIAN
  42718. + return *p;
  42719. +#else
  42720. + uint8_t *u_p = (uint8_t *)p;
  42721. + return (u_p[1] | (u_p[0] << 8));
  42722. +#endif
  42723. +}
  42724. +
  42725. +
  42726. +/* Registers */
  42727. +
  42728. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  42729. +{
  42730. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42731. + bus_size_t ior = (bus_size_t)reg;
  42732. +
  42733. + return bus_space_read_4(io->iot, io->ioh, ior);
  42734. +}
  42735. +
  42736. +#if 0
  42737. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  42738. +{
  42739. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42740. + bus_size_t ior = (bus_size_t)reg;
  42741. +
  42742. + return bus_space_read_8(io->iot, io->ioh, ior);
  42743. +}
  42744. +#endif
  42745. +
  42746. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  42747. +{
  42748. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42749. + bus_size_t ior = (bus_size_t)reg;
  42750. +
  42751. + bus_space_write_4(io->iot, io->ioh, ior, value);
  42752. +}
  42753. +
  42754. +#if 0
  42755. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  42756. +{
  42757. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42758. + bus_size_t ior = (bus_size_t)reg;
  42759. +
  42760. + bus_space_write_8(io->iot, io->ioh, ior, value);
  42761. +}
  42762. +#endif
  42763. +
  42764. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  42765. + uint32_t set_mask)
  42766. +{
  42767. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42768. + bus_size_t ior = (bus_size_t)reg;
  42769. +
  42770. + bus_space_write_4(io->iot, io->ioh, ior,
  42771. + (bus_space_read_4(io->iot, io->ioh, ior) &
  42772. + ~clear_mask) | set_mask);
  42773. +}
  42774. +
  42775. +#if 0
  42776. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  42777. + uint64_t set_mask)
  42778. +{
  42779. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42780. + bus_size_t ior = (bus_size_t)reg;
  42781. +
  42782. + bus_space_write_8(io->iot, io->ioh, ior,
  42783. + (bus_space_read_8(io->iot, io->ioh, ior) &
  42784. + ~clear_mask) | set_mask);
  42785. +}
  42786. +#endif
  42787. +
  42788. +
  42789. +/* Locking */
  42790. +
  42791. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42792. +{
  42793. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  42794. +
  42795. + if (!sl) {
  42796. + DWC_ERROR("Cannot allocate memory for spinlock");
  42797. + return NULL;
  42798. + }
  42799. +
  42800. + simple_lock_init(sl);
  42801. + return (dwc_spinlock_t *)sl;
  42802. +}
  42803. +
  42804. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42805. +{
  42806. + struct simplelock *sl = (struct simplelock *)lock;
  42807. +
  42808. + DWC_FREE(sl);
  42809. +}
  42810. +
  42811. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42812. +{
  42813. + simple_lock((struct simplelock *)lock);
  42814. +}
  42815. +
  42816. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42817. +{
  42818. + simple_unlock((struct simplelock *)lock);
  42819. +}
  42820. +
  42821. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42822. +{
  42823. + simple_lock((struct simplelock *)lock);
  42824. + *flags = splbio();
  42825. +}
  42826. +
  42827. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42828. +{
  42829. + splx(flags);
  42830. + simple_unlock((struct simplelock *)lock);
  42831. +}
  42832. +
  42833. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42834. +{
  42835. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  42836. +
  42837. + if (!mutex) {
  42838. + DWC_ERROR("Cannot allocate memory for mutex");
  42839. + return NULL;
  42840. + }
  42841. +
  42842. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  42843. + return mutex;
  42844. +}
  42845. +
  42846. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42847. +#else
  42848. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42849. +{
  42850. + DWC_FREE(mutex);
  42851. +}
  42852. +#endif
  42853. +
  42854. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42855. +{
  42856. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  42857. +}
  42858. +
  42859. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42860. +{
  42861. + int status;
  42862. +
  42863. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  42864. + return status == 0;
  42865. +}
  42866. +
  42867. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42868. +{
  42869. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  42870. +}
  42871. +
  42872. +
  42873. +/* Timing */
  42874. +
  42875. +void DWC_UDELAY(uint32_t usecs)
  42876. +{
  42877. + DELAY(usecs);
  42878. +}
  42879. +
  42880. +void DWC_MDELAY(uint32_t msecs)
  42881. +{
  42882. + do {
  42883. + DELAY(1000);
  42884. + } while (--msecs);
  42885. +}
  42886. +
  42887. +void DWC_MSLEEP(uint32_t msecs)
  42888. +{
  42889. + struct timeval tv;
  42890. +
  42891. + tv.tv_sec = msecs / 1000;
  42892. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42893. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  42894. +}
  42895. +
  42896. +uint32_t DWC_TIME(void)
  42897. +{
  42898. + struct timeval tv;
  42899. +
  42900. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  42901. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  42902. +}
  42903. +
  42904. +
  42905. +/* Timers */
  42906. +
  42907. +struct dwc_timer {
  42908. + struct callout t;
  42909. + char *name;
  42910. + dwc_spinlock_t *lock;
  42911. + dwc_timer_callback_t cb;
  42912. + void *data;
  42913. +};
  42914. +
  42915. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42916. +{
  42917. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42918. +
  42919. + if (!t) {
  42920. + DWC_ERROR("Cannot allocate memory for timer");
  42921. + return NULL;
  42922. + }
  42923. +
  42924. + callout_init(&t->t);
  42925. +
  42926. + t->name = DWC_STRDUP(name);
  42927. + if (!t->name) {
  42928. + DWC_ERROR("Cannot allocate memory for timer->name");
  42929. + goto no_name;
  42930. + }
  42931. +
  42932. + t->lock = DWC_SPINLOCK_ALLOC();
  42933. + if (!t->lock) {
  42934. + DWC_ERROR("Cannot allocate memory for timer->lock");
  42935. + goto no_lock;
  42936. + }
  42937. +
  42938. + t->cb = cb;
  42939. + t->data = data;
  42940. +
  42941. + return t;
  42942. +
  42943. + no_lock:
  42944. + DWC_FREE(t->name);
  42945. + no_name:
  42946. + DWC_FREE(t);
  42947. +
  42948. + return NULL;
  42949. +}
  42950. +
  42951. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42952. +{
  42953. + callout_stop(&timer->t);
  42954. + DWC_SPINLOCK_FREE(timer->lock);
  42955. + DWC_FREE(timer->name);
  42956. + DWC_FREE(timer);
  42957. +}
  42958. +
  42959. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42960. +{
  42961. + struct timeval tv;
  42962. +
  42963. + tv.tv_sec = time / 1000;
  42964. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  42965. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  42966. +}
  42967. +
  42968. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42969. +{
  42970. + callout_stop(&timer->t);
  42971. +}
  42972. +
  42973. +
  42974. +/* Wait Queues */
  42975. +
  42976. +struct dwc_waitq {
  42977. + struct simplelock lock;
  42978. + int abort;
  42979. +};
  42980. +
  42981. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42982. +{
  42983. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42984. +
  42985. + if (!wq) {
  42986. + DWC_ERROR("Cannot allocate memory for waitqueue");
  42987. + return NULL;
  42988. + }
  42989. +
  42990. + simple_lock_init(&wq->lock);
  42991. + wq->abort = 0;
  42992. +
  42993. + return wq;
  42994. +}
  42995. +
  42996. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42997. +{
  42998. + DWC_FREE(wq);
  42999. +}
  43000. +
  43001. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43002. +{
  43003. + int ipl;
  43004. + int result = 0;
  43005. +
  43006. + simple_lock(&wq->lock);
  43007. + ipl = splbio();
  43008. +
  43009. + /* Skip the sleep if already aborted or triggered */
  43010. + if (!wq->abort && !cond(data)) {
  43011. + splx(ipl);
  43012. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  43013. + ipl = splbio();
  43014. + }
  43015. +
  43016. + if (result == 0) { // awoken
  43017. + if (wq->abort) {
  43018. + wq->abort = 0;
  43019. + result = -DWC_E_ABORT;
  43020. + } else {
  43021. + result = 0;
  43022. + }
  43023. +
  43024. + splx(ipl);
  43025. + simple_unlock(&wq->lock);
  43026. + } else {
  43027. + wq->abort = 0;
  43028. + splx(ipl);
  43029. + simple_unlock(&wq->lock);
  43030. +
  43031. + if (result == ERESTART) { // signaled - restart
  43032. + result = -DWC_E_RESTART;
  43033. + } else { // signaled - must be EINTR
  43034. + result = -DWC_E_ABORT;
  43035. + }
  43036. + }
  43037. +
  43038. + return result;
  43039. +}
  43040. +
  43041. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43042. + void *data, int32_t msecs)
  43043. +{
  43044. + struct timeval tv, tv1, tv2;
  43045. + int ipl;
  43046. + int result = 0;
  43047. +
  43048. + tv.tv_sec = msecs / 1000;
  43049. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43050. +
  43051. + simple_lock(&wq->lock);
  43052. + ipl = splbio();
  43053. +
  43054. + /* Skip the sleep if already aborted or triggered */
  43055. + if (!wq->abort && !cond(data)) {
  43056. + splx(ipl);
  43057. + getmicrouptime(&tv1);
  43058. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  43059. + getmicrouptime(&tv2);
  43060. + ipl = splbio();
  43061. + }
  43062. +
  43063. + if (result == 0) { // awoken
  43064. + if (wq->abort) {
  43065. + wq->abort = 0;
  43066. + splx(ipl);
  43067. + simple_unlock(&wq->lock);
  43068. + result = -DWC_E_ABORT;
  43069. + } else {
  43070. + splx(ipl);
  43071. + simple_unlock(&wq->lock);
  43072. +
  43073. + tv2.tv_usec -= tv1.tv_usec;
  43074. + if (tv2.tv_usec < 0) {
  43075. + tv2.tv_usec += 1000000;
  43076. + tv2.tv_sec--;
  43077. + }
  43078. +
  43079. + tv2.tv_sec -= tv1.tv_sec;
  43080. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  43081. + result = msecs - result;
  43082. + if (result <= 0)
  43083. + result = 1;
  43084. + }
  43085. + } else {
  43086. + wq->abort = 0;
  43087. + splx(ipl);
  43088. + simple_unlock(&wq->lock);
  43089. +
  43090. + if (result == ERESTART) { // signaled - restart
  43091. + result = -DWC_E_RESTART;
  43092. +
  43093. + } else if (result == EINTR) { // signaled - interrupt
  43094. + result = -DWC_E_ABORT;
  43095. +
  43096. + } else { // timed out
  43097. + result = -DWC_E_TIMEOUT;
  43098. + }
  43099. + }
  43100. +
  43101. + return result;
  43102. +}
  43103. +
  43104. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  43105. +{
  43106. + wakeup(wq);
  43107. +}
  43108. +
  43109. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  43110. +{
  43111. + int ipl;
  43112. +
  43113. + simple_lock(&wq->lock);
  43114. + ipl = splbio();
  43115. + wq->abort = 1;
  43116. + wakeup(wq);
  43117. + splx(ipl);
  43118. + simple_unlock(&wq->lock);
  43119. +}
  43120. +
  43121. +
  43122. +/* Threading */
  43123. +
  43124. +struct dwc_thread {
  43125. + struct proc *proc;
  43126. + int abort;
  43127. +};
  43128. +
  43129. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  43130. +{
  43131. + int retval;
  43132. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  43133. +
  43134. + if (!thread) {
  43135. + return NULL;
  43136. + }
  43137. +
  43138. + thread->abort = 0;
  43139. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  43140. + "%s", name);
  43141. + if (retval) {
  43142. + DWC_FREE(thread);
  43143. + return NULL;
  43144. + }
  43145. +
  43146. + return thread;
  43147. +}
  43148. +
  43149. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  43150. +{
  43151. + int retval;
  43152. +
  43153. + thread->abort = 1;
  43154. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  43155. +
  43156. + if (retval == 0) {
  43157. + /* DWC_THREAD_EXIT() will free the thread struct */
  43158. + return 0;
  43159. + }
  43160. +
  43161. + /* NOTE: We leak the thread struct if thread doesn't die */
  43162. +
  43163. + if (retval == EWOULDBLOCK) {
  43164. + return -DWC_E_TIMEOUT;
  43165. + }
  43166. +
  43167. + return -DWC_E_UNKNOWN;
  43168. +}
  43169. +
  43170. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  43171. +{
  43172. + return thread->abort;
  43173. +}
  43174. +
  43175. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  43176. +{
  43177. + wakeup(&thread->abort);
  43178. + DWC_FREE(thread);
  43179. + kthread_exit(0);
  43180. +}
  43181. +
  43182. +/* tasklets
  43183. + - Runs in interrupt context (cannot sleep)
  43184. + - Each tasklet runs on a single CPU
  43185. + - Different tasklets can be running simultaneously on different CPUs
  43186. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  43187. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  43188. + */
  43189. +struct dwc_tasklet {
  43190. + dwc_tasklet_callback_t cb;
  43191. + void *data;
  43192. +};
  43193. +
  43194. +static void tasklet_callback(void *data)
  43195. +{
  43196. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  43197. +
  43198. + task->cb(task->data);
  43199. +}
  43200. +
  43201. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  43202. +{
  43203. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  43204. +
  43205. + if (task) {
  43206. + task->cb = cb;
  43207. + task->data = data;
  43208. + } else {
  43209. + DWC_ERROR("Cannot allocate memory for tasklet");
  43210. + }
  43211. +
  43212. + return task;
  43213. +}
  43214. +
  43215. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  43216. +{
  43217. + DWC_FREE(task);
  43218. +}
  43219. +
  43220. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  43221. +{
  43222. + tasklet_callback(task);
  43223. +}
  43224. +
  43225. +
  43226. +/* workqueues
  43227. + - Runs in process context (can sleep)
  43228. + */
  43229. +typedef struct work_container {
  43230. + dwc_work_callback_t cb;
  43231. + void *data;
  43232. + dwc_workq_t *wq;
  43233. + char *name;
  43234. + int hz;
  43235. + struct work task;
  43236. +} work_container_t;
  43237. +
  43238. +struct dwc_workq {
  43239. + struct workqueue *taskq;
  43240. + dwc_spinlock_t *lock;
  43241. + dwc_waitq_t *waitq;
  43242. + int pending;
  43243. + struct work_container *container;
  43244. +};
  43245. +
  43246. +static void do_work(struct work *task, void *data)
  43247. +{
  43248. + dwc_workq_t *wq = (dwc_workq_t *)data;
  43249. + work_container_t *container = wq->container;
  43250. + dwc_irqflags_t flags;
  43251. +
  43252. + if (container->hz) {
  43253. + tsleep(container, 0, "dw3wrk", container->hz);
  43254. + }
  43255. +
  43256. + container->cb(container->data);
  43257. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  43258. +
  43259. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43260. + if (container->name)
  43261. + DWC_FREE(container->name);
  43262. + DWC_FREE(container);
  43263. + wq->pending--;
  43264. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43265. + DWC_WAITQ_TRIGGER(wq->waitq);
  43266. +}
  43267. +
  43268. +static int work_done(void *data)
  43269. +{
  43270. + dwc_workq_t *workq = (dwc_workq_t *)data;
  43271. +
  43272. + return workq->pending == 0;
  43273. +}
  43274. +
  43275. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  43276. +{
  43277. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  43278. +}
  43279. +
  43280. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  43281. +{
  43282. + int result;
  43283. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  43284. +
  43285. + if (!wq) {
  43286. + DWC_ERROR("Cannot allocate memory for workqueue");
  43287. + return NULL;
  43288. + }
  43289. +
  43290. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  43291. + IPL_BIO, 0);
  43292. + if (result) {
  43293. + DWC_ERROR("Cannot create workqueue");
  43294. + goto no_taskq;
  43295. + }
  43296. +
  43297. + wq->pending = 0;
  43298. +
  43299. + wq->lock = DWC_SPINLOCK_ALLOC();
  43300. + if (!wq->lock) {
  43301. + DWC_ERROR("Cannot allocate memory for spinlock");
  43302. + goto no_lock;
  43303. + }
  43304. +
  43305. + wq->waitq = DWC_WAITQ_ALLOC();
  43306. + if (!wq->waitq) {
  43307. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43308. + goto no_waitq;
  43309. + }
  43310. +
  43311. + return wq;
  43312. +
  43313. + no_waitq:
  43314. + DWC_SPINLOCK_FREE(wq->lock);
  43315. + no_lock:
  43316. + workqueue_destroy(wq->taskq);
  43317. + no_taskq:
  43318. + DWC_FREE(wq);
  43319. +
  43320. + return NULL;
  43321. +}
  43322. +
  43323. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  43324. +{
  43325. +#ifdef DEBUG
  43326. + dwc_irqflags_t flags;
  43327. +
  43328. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43329. +
  43330. + if (wq->pending != 0) {
  43331. + struct work_container *container = wq->container;
  43332. +
  43333. + DWC_ERROR("Destroying work queue with pending work");
  43334. +
  43335. + if (container && container->name) {
  43336. + DWC_ERROR("Work %s still pending", container->name);
  43337. + }
  43338. + }
  43339. +
  43340. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43341. +#endif
  43342. + DWC_WAITQ_FREE(wq->waitq);
  43343. + DWC_SPINLOCK_FREE(wq->lock);
  43344. + workqueue_destroy(wq->taskq);
  43345. + DWC_FREE(wq);
  43346. +}
  43347. +
  43348. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  43349. + char *format, ...)
  43350. +{
  43351. + dwc_irqflags_t flags;
  43352. + work_container_t *container;
  43353. + static char name[128];
  43354. + va_list args;
  43355. +
  43356. + va_start(args, format);
  43357. + DWC_VSNPRINTF(name, 128, format, args);
  43358. + va_end(args);
  43359. +
  43360. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43361. + wq->pending++;
  43362. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43363. + DWC_WAITQ_TRIGGER(wq->waitq);
  43364. +
  43365. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43366. + if (!container) {
  43367. + DWC_ERROR("Cannot allocate memory for container");
  43368. + return;
  43369. + }
  43370. +
  43371. + container->name = DWC_STRDUP(name);
  43372. + if (!container->name) {
  43373. + DWC_ERROR("Cannot allocate memory for container->name");
  43374. + DWC_FREE(container);
  43375. + return;
  43376. + }
  43377. +
  43378. + container->cb = cb;
  43379. + container->data = data;
  43380. + container->wq = wq;
  43381. + container->hz = 0;
  43382. + wq->container = container;
  43383. +
  43384. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43385. + workqueue_enqueue(wq->taskq, &container->task);
  43386. +}
  43387. +
  43388. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  43389. + void *data, uint32_t time, char *format, ...)
  43390. +{
  43391. + dwc_irqflags_t flags;
  43392. + work_container_t *container;
  43393. + static char name[128];
  43394. + struct timeval tv;
  43395. + va_list args;
  43396. +
  43397. + va_start(args, format);
  43398. + DWC_VSNPRINTF(name, 128, format, args);
  43399. + va_end(args);
  43400. +
  43401. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43402. + wq->pending++;
  43403. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43404. + DWC_WAITQ_TRIGGER(wq->waitq);
  43405. +
  43406. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43407. + if (!container) {
  43408. + DWC_ERROR("Cannot allocate memory for container");
  43409. + return;
  43410. + }
  43411. +
  43412. + container->name = DWC_STRDUP(name);
  43413. + if (!container->name) {
  43414. + DWC_ERROR("Cannot allocate memory for container->name");
  43415. + DWC_FREE(container);
  43416. + return;
  43417. + }
  43418. +
  43419. + container->cb = cb;
  43420. + container->data = data;
  43421. + container->wq = wq;
  43422. + tv.tv_sec = time / 1000;
  43423. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43424. + container->hz = tvtohz(&tv);
  43425. + wq->container = container;
  43426. +
  43427. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43428. + workqueue_enqueue(wq->taskq, &container->task);
  43429. +}
  43430. +
  43431. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43432. +{
  43433. + return wq->pending;
  43434. +}
  43435. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_crypto.c
  43436. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  43437. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-02-07 19:57:30.000000000 +0100
  43438. @@ -0,0 +1,308 @@
  43439. +/* =========================================================================
  43440. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  43441. + * $Revision: #5 $
  43442. + * $Date: 2010/09/28 $
  43443. + * $Change: 1596182 $
  43444. + *
  43445. + * Synopsys Portability Library Software and documentation
  43446. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43447. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43448. + * between Synopsys and you.
  43449. + *
  43450. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43451. + * under any End User Software License Agreement or Agreement for
  43452. + * Licensed Product with Synopsys or any supplement thereto. You are
  43453. + * permitted to use and redistribute this Software in source and binary
  43454. + * forms, with or without modification, provided that redistributions
  43455. + * of source code must retain this notice. You may not view, use,
  43456. + * disclose, copy or distribute this file or any information contained
  43457. + * herein except pursuant to this license grant from Synopsys. If you
  43458. + * do not agree with this notice, including the disclaimer below, then
  43459. + * you are not authorized to use the Software.
  43460. + *
  43461. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43462. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43463. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43464. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43465. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43466. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43467. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43468. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43469. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43470. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43471. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43472. + * DAMAGE.
  43473. + * ========================================================================= */
  43474. +
  43475. +/** @file
  43476. + * This file contains the WUSB cryptographic routines.
  43477. + */
  43478. +
  43479. +#ifdef DWC_CRYPTOLIB
  43480. +
  43481. +#include "dwc_crypto.h"
  43482. +#include "usb.h"
  43483. +
  43484. +#ifdef DEBUG
  43485. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  43486. +{
  43487. + int i;
  43488. + DWC_PRINTF("%s: ", name);
  43489. + for (i=0; i<len; i++) {
  43490. + DWC_PRINTF("%02x ", bytes[i]);
  43491. + }
  43492. + DWC_PRINTF("\n");
  43493. +}
  43494. +#else
  43495. +#define dump_bytes(x...)
  43496. +#endif
  43497. +
  43498. +/* Display a block */
  43499. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  43500. +{
  43501. +#ifdef DWC_DEBUG_CRYPTO
  43502. + int i, blksize = 16;
  43503. +
  43504. + DWC_DEBUG("%s", prefix);
  43505. +
  43506. + if (suffix == NULL) {
  43507. + suffix = "\n";
  43508. + blksize = a;
  43509. + }
  43510. +
  43511. + for (i = 0; i < blksize; i++)
  43512. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  43513. + DWC_PRINT(suffix);
  43514. +#endif
  43515. +}
  43516. +
  43517. +/**
  43518. + * Encrypts an array of bytes using the AES encryption engine.
  43519. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  43520. + * in-place.
  43521. + *
  43522. + * @return 0 on success, negative error code on error.
  43523. + */
  43524. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  43525. +{
  43526. + u8 block_t[16];
  43527. + DWC_MEMSET(block_t, 0, 16);
  43528. +
  43529. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  43530. +}
  43531. +
  43532. +/**
  43533. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  43534. + * This function takes a data string and returns the encrypted CBC
  43535. + * Counter-mode MIC.
  43536. + *
  43537. + * @param key The 128-bit symmetric key.
  43538. + * @param nonce The CCM nonce.
  43539. + * @param label The unique 14-byte ASCII text label.
  43540. + * @param bytes The byte array to be encrypted.
  43541. + * @param len Length of the byte array.
  43542. + * @param result Byte array to receive the 8-byte encrypted MIC.
  43543. + */
  43544. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43545. + char *label, u8 *bytes, int len, u8 *result)
  43546. +{
  43547. + u8 block_m[16];
  43548. + u8 block_x[16];
  43549. + u8 block_t[8];
  43550. + int idx, blkNum;
  43551. + u16 la = (u16)(len + 14);
  43552. +
  43553. + /* Set the AES-128 key */
  43554. + //dwc_aes_setkey(tfm, key, 16);
  43555. +
  43556. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  43557. + block_m[0] = 0x59;
  43558. + for (idx = 0; idx < 13; idx++)
  43559. + block_m[idx + 1] = nonce[idx];
  43560. + block_m[14] = 0;
  43561. + block_m[15] = 0;
  43562. +
  43563. + /* Produce the CBC IV */
  43564. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43565. + show_block(block_m, "CBC IV in: ", "\n", 0);
  43566. + show_block(block_x, "CBC IV out:", "\n", 0);
  43567. +
  43568. + /* Fill block B1 from l(a) = Blen + 14, and A */
  43569. + block_x[0] ^= (u8)(la >> 8);
  43570. + block_x[1] ^= (u8)la;
  43571. + for (idx = 0; idx < 14; idx++)
  43572. + block_x[idx + 2] ^= label[idx];
  43573. + show_block(block_x, "After xor: ", "b1\n", 16);
  43574. +
  43575. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43576. + show_block(block_x, "After AES: ", "b1\n", 16);
  43577. +
  43578. + idx = 0;
  43579. + blkNum = 0;
  43580. +
  43581. + /* Fill remaining blocks with B */
  43582. + while (len-- > 0) {
  43583. + block_x[idx] ^= *bytes++;
  43584. + if (++idx >= 16) {
  43585. + idx = 0;
  43586. + show_block(block_x, "After xor: ", "\n", blkNum);
  43587. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43588. + show_block(block_x, "After AES: ", "\n", blkNum);
  43589. + blkNum++;
  43590. + }
  43591. + }
  43592. +
  43593. + /* Handle partial last block */
  43594. + if (idx > 0) {
  43595. + show_block(block_x, "After xor: ", "\n", blkNum);
  43596. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43597. + show_block(block_x, "After AES: ", "\n", blkNum);
  43598. + }
  43599. +
  43600. + /* Save the MIC tag */
  43601. + DWC_MEMCPY(block_t, block_x, 8);
  43602. + show_block(block_t, "MIC tag : ", NULL, 8);
  43603. +
  43604. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  43605. + block_m[0] = 0x01;
  43606. + block_m[14] = 0;
  43607. + block_m[15] = 0;
  43608. +
  43609. + /* Encrypt the counter */
  43610. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43611. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  43612. +
  43613. + /* XOR with MIC tag */
  43614. + for (idx = 0; idx < 8; idx++) {
  43615. + block_t[idx] ^= block_x[idx];
  43616. + }
  43617. +
  43618. + /* Return result to caller */
  43619. + DWC_MEMCPY(result, block_t, 8);
  43620. + show_block(result, "CCM-MIC : ", NULL, 8);
  43621. +
  43622. +}
  43623. +
  43624. +/**
  43625. + * The PRF function described in section 6.5 of the WUSB spec. This function
  43626. + * concatenates MIC values returned from dwc_cmf() to create a value of
  43627. + * the requested length.
  43628. + *
  43629. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  43630. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  43631. + * @param result Byte array to receive the result.
  43632. + */
  43633. +void dwc_wusb_prf(int prf_len, u8 *key,
  43634. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  43635. +{
  43636. + int i;
  43637. +
  43638. + nonce[0] = 0;
  43639. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  43640. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  43641. + result += 8;
  43642. + }
  43643. +}
  43644. +
  43645. +/**
  43646. + * Fills in CCM Nonce per the WUSB spec.
  43647. + *
  43648. + * @param[in] haddr Host address.
  43649. + * @param[in] daddr Device address.
  43650. + * @param[in] tkid Session Key(PTK) identifier.
  43651. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  43652. + */
  43653. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43654. + uint8_t *nonce)
  43655. +{
  43656. +
  43657. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  43658. +
  43659. + DWC_MEMSET(&nonce[0], 0, 16);
  43660. +
  43661. + DWC_MEMCPY(&nonce[6], tkid, 3);
  43662. + nonce[9] = daddr & 0xFF;
  43663. + nonce[10] = (daddr >> 8) & 0xFF;
  43664. + nonce[11] = haddr & 0xFF;
  43665. + nonce[12] = (haddr >> 8) & 0xFF;
  43666. +
  43667. + dump_bytes("CCM nonce", nonce, 16);
  43668. +}
  43669. +
  43670. +/**
  43671. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  43672. + * Nonce.
  43673. + */
  43674. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  43675. +{
  43676. + uint8_t inonce[16];
  43677. + uint32_t temp[4];
  43678. +
  43679. + /* Fill in the Nonce */
  43680. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  43681. + inonce[9] = addr & 0xFF;
  43682. + inonce[10] = (addr >> 8) & 0xFF;
  43683. + inonce[11] = inonce[9];
  43684. + inonce[12] = inonce[10];
  43685. +
  43686. + /* Collect "randomness samples" */
  43687. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  43688. +
  43689. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  43690. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  43691. + nonce);
  43692. +}
  43693. +
  43694. +/**
  43695. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  43696. + * WUSB spec.
  43697. + *
  43698. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  43699. + * @param[in] mk Master Key to derive the session from
  43700. + * @param[in] hnonce Pointer to Host Nonce.
  43701. + * @param[in] dnonce Pointer to Device Nonce.
  43702. + * @param[out] kck Pointer to where the KCK output is to be written.
  43703. + * @param[out] ptk Pointer to where the PTK output is to be written.
  43704. + */
  43705. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  43706. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  43707. +{
  43708. + uint8_t idata[32];
  43709. + uint8_t odata[32];
  43710. +
  43711. + dump_bytes("ck", mk, 16);
  43712. + dump_bytes("hnonce", hnonce, 16);
  43713. + dump_bytes("dnonce", dnonce, 16);
  43714. +
  43715. + /* The data is the HNonce and DNonce concatenated */
  43716. + DWC_MEMCPY(&idata[0], hnonce, 16);
  43717. + DWC_MEMCPY(&idata[16], dnonce, 16);
  43718. +
  43719. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  43720. +
  43721. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  43722. + DWC_MEMCPY(kck, &odata[0], 16);
  43723. + DWC_MEMCPY(ptk, &odata[16], 16);
  43724. +
  43725. + dump_bytes("kck", kck, 16);
  43726. + dump_bytes("ptk", ptk, 16);
  43727. +}
  43728. +
  43729. +/**
  43730. + * Generates the Message Integrity Code over the Handshake data per the
  43731. + * WUSB spec.
  43732. + *
  43733. + * @param ccm_nonce Pointer to CCM Nonce.
  43734. + * @param kck Pointer to Key Confirmation Key.
  43735. + * @param data Pointer to Handshake data to be checked.
  43736. + * @param mic Pointer to where the MIC output is to be written.
  43737. + */
  43738. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  43739. + uint8_t *data, uint8_t *mic)
  43740. +{
  43741. +
  43742. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  43743. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  43744. +}
  43745. +
  43746. +#endif /* DWC_CRYPTOLIB */
  43747. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_crypto.h
  43748. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  43749. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-02-07 19:57:30.000000000 +0100
  43750. @@ -0,0 +1,111 @@
  43751. +/* =========================================================================
  43752. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  43753. + * $Revision: #3 $
  43754. + * $Date: 2010/09/28 $
  43755. + * $Change: 1596182 $
  43756. + *
  43757. + * Synopsys Portability Library Software and documentation
  43758. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43759. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43760. + * between Synopsys and you.
  43761. + *
  43762. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43763. + * under any End User Software License Agreement or Agreement for
  43764. + * Licensed Product with Synopsys or any supplement thereto. You are
  43765. + * permitted to use and redistribute this Software in source and binary
  43766. + * forms, with or without modification, provided that redistributions
  43767. + * of source code must retain this notice. You may not view, use,
  43768. + * disclose, copy or distribute this file or any information contained
  43769. + * herein except pursuant to this license grant from Synopsys. If you
  43770. + * do not agree with this notice, including the disclaimer below, then
  43771. + * you are not authorized to use the Software.
  43772. + *
  43773. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43774. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43775. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43776. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43777. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43778. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43779. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43780. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43781. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43782. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43783. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43784. + * DAMAGE.
  43785. + * ========================================================================= */
  43786. +
  43787. +#ifndef _DWC_CRYPTO_H_
  43788. +#define _DWC_CRYPTO_H_
  43789. +
  43790. +#ifdef __cplusplus
  43791. +extern "C" {
  43792. +#endif
  43793. +
  43794. +/** @file
  43795. + *
  43796. + * This file contains declarations for the WUSB Cryptographic routines as
  43797. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  43798. + * modules.
  43799. + */
  43800. +
  43801. +#include "dwc_os.h"
  43802. +
  43803. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  43804. +
  43805. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43806. + char *label, u8 *bytes, int len, u8 *result);
  43807. +void dwc_wusb_prf(int prf_len, u8 *key,
  43808. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  43809. +
  43810. +/**
  43811. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  43812. + *
  43813. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43814. + */
  43815. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  43816. + char *label, u8 *bytes, int len, u8 *result)
  43817. +{
  43818. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  43819. +}
  43820. +
  43821. +/**
  43822. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  43823. + *
  43824. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43825. + */
  43826. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  43827. + char *label, u8 *bytes, int len, u8 *result)
  43828. +{
  43829. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  43830. +}
  43831. +
  43832. +/**
  43833. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  43834. + *
  43835. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43836. + */
  43837. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  43838. + char *label, u8 *bytes, int len, u8 *result)
  43839. +{
  43840. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  43841. +}
  43842. +
  43843. +
  43844. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43845. + uint8_t *nonce);
  43846. +void dwc_wusb_gen_nonce(uint16_t addr,
  43847. + uint8_t *nonce);
  43848. +
  43849. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  43850. + uint8_t *hnonce, uint8_t *dnonce,
  43851. + uint8_t *kck, uint8_t *ptk);
  43852. +
  43853. +
  43854. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  43855. + *kck, uint8_t *data, uint8_t *mic);
  43856. +
  43857. +#ifdef __cplusplus
  43858. +}
  43859. +#endif
  43860. +
  43861. +#endif /* _DWC_CRYPTO_H_ */
  43862. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_dh.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_dh.c
  43863. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  43864. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-02-07 19:57:30.000000000 +0100
  43865. @@ -0,0 +1,291 @@
  43866. +/* =========================================================================
  43867. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  43868. + * $Revision: #3 $
  43869. + * $Date: 2010/09/28 $
  43870. + * $Change: 1596182 $
  43871. + *
  43872. + * Synopsys Portability Library Software and documentation
  43873. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43874. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43875. + * between Synopsys and you.
  43876. + *
  43877. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43878. + * under any End User Software License Agreement or Agreement for
  43879. + * Licensed Product with Synopsys or any supplement thereto. You are
  43880. + * permitted to use and redistribute this Software in source and binary
  43881. + * forms, with or without modification, provided that redistributions
  43882. + * of source code must retain this notice. You may not view, use,
  43883. + * disclose, copy or distribute this file or any information contained
  43884. + * herein except pursuant to this license grant from Synopsys. If you
  43885. + * do not agree with this notice, including the disclaimer below, then
  43886. + * you are not authorized to use the Software.
  43887. + *
  43888. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43889. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43890. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43891. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43892. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43893. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43894. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43895. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43896. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43897. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43898. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43899. + * DAMAGE.
  43900. + * ========================================================================= */
  43901. +#ifdef DWC_CRYPTOLIB
  43902. +
  43903. +#ifndef CONFIG_MACH_IPMATE
  43904. +
  43905. +#include "dwc_dh.h"
  43906. +#include "dwc_modpow.h"
  43907. +
  43908. +#ifdef DEBUG
  43909. +/* This function prints out a buffer in the format described in the Association
  43910. + * Model specification. */
  43911. +static void dh_dump(char *str, void *_num, int len)
  43912. +{
  43913. + uint8_t *num = _num;
  43914. + int i;
  43915. + DWC_PRINTF("%s\n", str);
  43916. + for (i = 0; i < len; i ++) {
  43917. + DWC_PRINTF("%02x", num[i]);
  43918. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  43919. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  43920. + }
  43921. +
  43922. + DWC_PRINTF("\n");
  43923. +}
  43924. +#else
  43925. +#define dh_dump(_x...) do {; } while(0)
  43926. +#endif
  43927. +
  43928. +/* Constant g value */
  43929. +static __u32 dh_g[] = {
  43930. + 0x02000000,
  43931. +};
  43932. +
  43933. +/* Constant p value */
  43934. +static __u32 dh_p[] = {
  43935. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  43936. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  43937. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  43938. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  43939. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  43940. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  43941. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  43942. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  43943. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  43944. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  43945. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  43946. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  43947. +};
  43948. +
  43949. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  43950. +{
  43951. + uint8_t *in = _in;
  43952. + uint8_t *out = _out;
  43953. + int i;
  43954. + for (i=0; i<len; i++) {
  43955. + out[i] = in[len-1-i];
  43956. + }
  43957. +}
  43958. +
  43959. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  43960. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  43961. + * of 4. */
  43962. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  43963. + void *exp, uint32_t exp_len,
  43964. + void *mod, uint32_t mod_len,
  43965. + void *out)
  43966. +{
  43967. + /* modpow() takes little endian numbers. AM uses big-endian. This
  43968. + * function swaps bytes of numbers before passing onto modpow. */
  43969. +
  43970. + int retval = 0;
  43971. + uint32_t *result;
  43972. +
  43973. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  43974. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  43975. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  43976. +
  43977. + dh_swap_bytes(num, &bignum_num[1], num_len);
  43978. + bignum_num[0] = num_len / 4;
  43979. +
  43980. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  43981. + bignum_exp[0] = exp_len / 4;
  43982. +
  43983. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  43984. + bignum_mod[0] = mod_len / 4;
  43985. +
  43986. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  43987. + if (!result) {
  43988. + retval = -1;
  43989. + goto dh_modpow_nomem;
  43990. + }
  43991. +
  43992. + dh_swap_bytes(&result[1], out, result[0] * 4);
  43993. + dwc_free(mem_ctx, result);
  43994. +
  43995. + dh_modpow_nomem:
  43996. + dwc_free(mem_ctx, bignum_num);
  43997. + dwc_free(mem_ctx, bignum_exp);
  43998. + dwc_free(mem_ctx, bignum_mod);
  43999. + return retval;
  44000. +}
  44001. +
  44002. +
  44003. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  44004. +{
  44005. + int retval;
  44006. + uint8_t m3[385];
  44007. +
  44008. +#ifndef DH_TEST_VECTORS
  44009. + DWC_RANDOM_BYTES(exp, 32);
  44010. +#endif
  44011. +
  44012. + /* Compute the pkd */
  44013. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  44014. + exp, 32,
  44015. + dh_p, 384, pk))) {
  44016. + return retval;
  44017. + }
  44018. +
  44019. + m3[384] = nd;
  44020. + DWC_MEMCPY(&m3[0], pk, 384);
  44021. + DWC_SHA256(m3, 385, hash);
  44022. +
  44023. + dh_dump("PK", pk, 384);
  44024. + dh_dump("SHA-256(M3)", hash, 32);
  44025. + return 0;
  44026. +}
  44027. +
  44028. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44029. + uint8_t *exp, int is_host,
  44030. + char *dd, uint8_t *ck, uint8_t *kdk)
  44031. +{
  44032. + int retval;
  44033. + uint8_t mv[784];
  44034. + uint8_t sha_result[32];
  44035. + uint8_t dhkey[384];
  44036. + uint8_t shared_secret[384];
  44037. + char *message;
  44038. + uint32_t vd;
  44039. +
  44040. + uint8_t *pk;
  44041. +
  44042. + if (is_host) {
  44043. + pk = pkd;
  44044. + }
  44045. + else {
  44046. + pk = pkh;
  44047. + }
  44048. +
  44049. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  44050. + exp, 32,
  44051. + dh_p, 384, shared_secret))) {
  44052. + return retval;
  44053. + }
  44054. + dh_dump("Shared Secret", shared_secret, 384);
  44055. +
  44056. + DWC_SHA256(shared_secret, 384, dhkey);
  44057. + dh_dump("DHKEY", dhkey, 384);
  44058. +
  44059. + DWC_MEMCPY(&mv[0], pkd, 384);
  44060. + DWC_MEMCPY(&mv[384], pkh, 384);
  44061. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  44062. + dh_dump("MV", mv, 784);
  44063. +
  44064. + DWC_SHA256(mv, 784, sha_result);
  44065. + dh_dump("SHA-256(MV)", sha_result, 32);
  44066. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  44067. +
  44068. + dh_swap_bytes(sha_result, &vd, 4);
  44069. +#ifdef DEBUG
  44070. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  44071. +#endif
  44072. +
  44073. + switch (nd) {
  44074. + case 2:
  44075. + vd = vd % 100;
  44076. + DWC_SPRINTF(dd, "%02d", vd);
  44077. + break;
  44078. + case 3:
  44079. + vd = vd % 1000;
  44080. + DWC_SPRINTF(dd, "%03d", vd);
  44081. + break;
  44082. + case 4:
  44083. + vd = vd % 10000;
  44084. + DWC_SPRINTF(dd, "%04d", vd);
  44085. + break;
  44086. + }
  44087. +#ifdef DEBUG
  44088. + DWC_PRINTF("Display Digits: %s\n", dd);
  44089. +#endif
  44090. +
  44091. + message = "connection key";
  44092. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44093. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  44094. + DWC_MEMCPY(ck, sha_result, 16);
  44095. +
  44096. + message = "key derivation key";
  44097. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44098. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  44099. + DWC_MEMCPY(kdk, sha_result, 32);
  44100. +
  44101. + return 0;
  44102. +}
  44103. +
  44104. +
  44105. +#ifdef DH_TEST_VECTORS
  44106. +
  44107. +static __u8 dh_a[] = {
  44108. + 0x44, 0x00, 0x51, 0xd6,
  44109. + 0xf0, 0xb5, 0x5e, 0xa9,
  44110. + 0x67, 0xab, 0x31, 0xc6,
  44111. + 0x8a, 0x8b, 0x5e, 0x37,
  44112. + 0xd9, 0x10, 0xda, 0xe0,
  44113. + 0xe2, 0xd4, 0x59, 0xa4,
  44114. + 0x86, 0x45, 0x9c, 0xaa,
  44115. + 0xdf, 0x36, 0x75, 0x16,
  44116. +};
  44117. +
  44118. +static __u8 dh_b[] = {
  44119. + 0x5d, 0xae, 0xc7, 0x86,
  44120. + 0x79, 0x80, 0xa3, 0x24,
  44121. + 0x8c, 0xe3, 0x57, 0x8f,
  44122. + 0xc7, 0x5f, 0x1b, 0x0f,
  44123. + 0x2d, 0xf8, 0x9d, 0x30,
  44124. + 0x6f, 0xa4, 0x52, 0xcd,
  44125. + 0xe0, 0x7a, 0x04, 0x8a,
  44126. + 0xde, 0xd9, 0x26, 0x56,
  44127. +};
  44128. +
  44129. +void dwc_run_dh_test_vectors(void *mem_ctx)
  44130. +{
  44131. + uint8_t pkd[384];
  44132. + uint8_t pkh[384];
  44133. + uint8_t hashd[32];
  44134. + uint8_t hashh[32];
  44135. + uint8_t ck[16];
  44136. + uint8_t kdk[32];
  44137. + char dd[5];
  44138. +
  44139. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  44140. +
  44141. + /* compute the PKd and SHA-256(PKd || Nd) */
  44142. + DWC_PRINTF("Computing PKd\n");
  44143. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  44144. +
  44145. + /* compute the PKd and SHA-256(PKh || Nd) */
  44146. + DWC_PRINTF("Computing PKh\n");
  44147. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  44148. +
  44149. + /* compute the dhkey */
  44150. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  44151. +}
  44152. +#endif /* DH_TEST_VECTORS */
  44153. +
  44154. +#endif /* !CONFIG_MACH_IPMATE */
  44155. +
  44156. +#endif /* DWC_CRYPTOLIB */
  44157. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_dh.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_dh.h
  44158. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  44159. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-02-07 19:57:30.000000000 +0100
  44160. @@ -0,0 +1,106 @@
  44161. +/* =========================================================================
  44162. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  44163. + * $Revision: #4 $
  44164. + * $Date: 2010/09/28 $
  44165. + * $Change: 1596182 $
  44166. + *
  44167. + * Synopsys Portability Library Software and documentation
  44168. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44169. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44170. + * between Synopsys and you.
  44171. + *
  44172. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44173. + * under any End User Software License Agreement or Agreement for
  44174. + * Licensed Product with Synopsys or any supplement thereto. You are
  44175. + * permitted to use and redistribute this Software in source and binary
  44176. + * forms, with or without modification, provided that redistributions
  44177. + * of source code must retain this notice. You may not view, use,
  44178. + * disclose, copy or distribute this file or any information contained
  44179. + * herein except pursuant to this license grant from Synopsys. If you
  44180. + * do not agree with this notice, including the disclaimer below, then
  44181. + * you are not authorized to use the Software.
  44182. + *
  44183. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44184. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44185. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44186. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44187. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44188. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44189. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44190. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44191. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44192. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44193. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44194. + * DAMAGE.
  44195. + * ========================================================================= */
  44196. +#ifndef _DWC_DH_H_
  44197. +#define _DWC_DH_H_
  44198. +
  44199. +#ifdef __cplusplus
  44200. +extern "C" {
  44201. +#endif
  44202. +
  44203. +#include "dwc_os.h"
  44204. +
  44205. +/** @file
  44206. + *
  44207. + * This file defines the common functions on device and host for performing
  44208. + * numeric association as defined in the WUSB spec. They are only to be
  44209. + * used internally by the DWC UWB modules. */
  44210. +
  44211. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  44212. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  44213. + uint8_t *key, uint32_t keylen,
  44214. + uint8_t *out);
  44215. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44216. + void *exp, uint32_t exp_len,
  44217. + void *mod, uint32_t mod_len,
  44218. + void *out);
  44219. +
  44220. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  44221. + *
  44222. + * PK = g^exp mod p.
  44223. + *
  44224. + * Input:
  44225. + * Nd = Number of digits on the device.
  44226. + *
  44227. + * Output:
  44228. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  44229. + * used as either A or B.
  44230. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  44231. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  44232. + */
  44233. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  44234. +
  44235. +/** Computes the DHKEY, and VD.
  44236. + *
  44237. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  44238. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  44239. + *
  44240. + * Input:
  44241. + * pkd = The PKD value.
  44242. + * pkh = The PKH value.
  44243. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  44244. + * is_host = Set to non zero if a WUSB host is calling this function.
  44245. + *
  44246. + * Output:
  44247. +
  44248. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  44249. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  44250. + * null termination character. This buffer can be used directly for display.
  44251. + * ck = A 16-byte buffer to be filled with the CK.
  44252. + * kdk = A 32-byte buffer to be filled with the KDK.
  44253. + */
  44254. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44255. + uint8_t *exp, int is_host,
  44256. + char *dd, uint8_t *ck, uint8_t *kdk);
  44257. +
  44258. +#ifdef DH_TEST_VECTORS
  44259. +extern void dwc_run_dh_test_vectors(void);
  44260. +#endif
  44261. +
  44262. +#ifdef __cplusplus
  44263. +}
  44264. +#endif
  44265. +
  44266. +#endif /* _DWC_DH_H_ */
  44267. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_list.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_list.h
  44268. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  44269. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_list.h 2014-02-07 19:57:30.000000000 +0100
  44270. @@ -0,0 +1,594 @@
  44271. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  44272. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  44273. +
  44274. +/*
  44275. + * Copyright (c) 1991, 1993
  44276. + * The Regents of the University of California. All rights reserved.
  44277. + *
  44278. + * Redistribution and use in source and binary forms, with or without
  44279. + * modification, are permitted provided that the following conditions
  44280. + * are met:
  44281. + * 1. Redistributions of source code must retain the above copyright
  44282. + * notice, this list of conditions and the following disclaimer.
  44283. + * 2. Redistributions in binary form must reproduce the above copyright
  44284. + * notice, this list of conditions and the following disclaimer in the
  44285. + * documentation and/or other materials provided with the distribution.
  44286. + * 3. Neither the name of the University nor the names of its contributors
  44287. + * may be used to endorse or promote products derived from this software
  44288. + * without specific prior written permission.
  44289. + *
  44290. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  44291. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44292. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44293. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  44294. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  44295. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44296. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44297. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44298. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44299. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44300. + * SUCH DAMAGE.
  44301. + *
  44302. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  44303. + */
  44304. +
  44305. +#ifndef _DWC_LIST_H_
  44306. +#define _DWC_LIST_H_
  44307. +
  44308. +#ifdef __cplusplus
  44309. +extern "C" {
  44310. +#endif
  44311. +
  44312. +/** @file
  44313. + *
  44314. + * This file defines linked list operations. It is derived from BSD with
  44315. + * only the MACRO names being prefixed with DWC_. This is because a few of
  44316. + * these names conflict with those on Linux. For documentation on use, see the
  44317. + * inline comments in the source code. The original license for this source
  44318. + * code applies and is preserved in the dwc_list.h source file.
  44319. + */
  44320. +
  44321. +/*
  44322. + * This file defines five types of data structures: singly-linked lists,
  44323. + * lists, simple queues, tail queues, and circular queues.
  44324. + *
  44325. + *
  44326. + * A singly-linked list is headed by a single forward pointer. The elements
  44327. + * are singly linked for minimum space and pointer manipulation overhead at
  44328. + * the expense of O(n) removal for arbitrary elements. New elements can be
  44329. + * added to the list after an existing element or at the head of the list.
  44330. + * Elements being removed from the head of the list should use the explicit
  44331. + * macro for this purpose for optimum efficiency. A singly-linked list may
  44332. + * only be traversed in the forward direction. Singly-linked lists are ideal
  44333. + * for applications with large datasets and few or no removals or for
  44334. + * implementing a LIFO queue.
  44335. + *
  44336. + * A list is headed by a single forward pointer (or an array of forward
  44337. + * pointers for a hash table header). The elements are doubly linked
  44338. + * so that an arbitrary element can be removed without a need to
  44339. + * traverse the list. New elements can be added to the list before
  44340. + * or after an existing element or at the head of the list. A list
  44341. + * may only be traversed in the forward direction.
  44342. + *
  44343. + * A simple queue is headed by a pair of pointers, one the head of the
  44344. + * list and the other to the tail of the list. The elements are singly
  44345. + * linked to save space, so elements can only be removed from the
  44346. + * head of the list. New elements can be added to the list before or after
  44347. + * an existing element, at the head of the list, or at the end of the
  44348. + * list. A simple queue may only be traversed in the forward direction.
  44349. + *
  44350. + * A tail queue is headed by a pair of pointers, one to the head of the
  44351. + * list and the other to the tail of the list. The elements are doubly
  44352. + * linked so that an arbitrary element can be removed without a need to
  44353. + * traverse the list. New elements can be added to the list before or
  44354. + * after an existing element, at the head of the list, or at the end of
  44355. + * the list. A tail queue may be traversed in either direction.
  44356. + *
  44357. + * A circle queue is headed by a pair of pointers, one to the head of the
  44358. + * list and the other to the tail of the list. The elements are doubly
  44359. + * linked so that an arbitrary element can be removed without a need to
  44360. + * traverse the list. New elements can be added to the list before or after
  44361. + * an existing element, at the head of the list, or at the end of the list.
  44362. + * A circle queue may be traversed in either direction, but has a more
  44363. + * complex end of list detection.
  44364. + *
  44365. + * For details on the use of these macros, see the queue(3) manual page.
  44366. + */
  44367. +
  44368. +/*
  44369. + * Double-linked List.
  44370. + */
  44371. +
  44372. +typedef struct dwc_list_link {
  44373. + struct dwc_list_link *next;
  44374. + struct dwc_list_link *prev;
  44375. +} dwc_list_link_t;
  44376. +
  44377. +#define DWC_LIST_INIT(link) do { \
  44378. + (link)->next = (link); \
  44379. + (link)->prev = (link); \
  44380. +} while (0)
  44381. +
  44382. +#define DWC_LIST_FIRST(link) ((link)->next)
  44383. +#define DWC_LIST_LAST(link) ((link)->prev)
  44384. +#define DWC_LIST_END(link) (link)
  44385. +#define DWC_LIST_NEXT(link) ((link)->next)
  44386. +#define DWC_LIST_PREV(link) ((link)->prev)
  44387. +#define DWC_LIST_EMPTY(link) \
  44388. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  44389. +#define DWC_LIST_ENTRY(link, type, field) \
  44390. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  44391. +
  44392. +#if 0
  44393. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44394. + (link)->next = (list)->next; \
  44395. + (link)->prev = (list); \
  44396. + (list)->next->prev = (link); \
  44397. + (list)->next = (link); \
  44398. +} while (0)
  44399. +
  44400. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44401. + (link)->next = (list); \
  44402. + (link)->prev = (list)->prev; \
  44403. + (list)->prev->next = (link); \
  44404. + (list)->prev = (link); \
  44405. +} while (0)
  44406. +#else
  44407. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44408. + dwc_list_link_t *__next__ = (list)->next; \
  44409. + __next__->prev = (link); \
  44410. + (link)->next = __next__; \
  44411. + (link)->prev = (list); \
  44412. + (list)->next = (link); \
  44413. +} while (0)
  44414. +
  44415. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44416. + dwc_list_link_t *__prev__ = (list)->prev; \
  44417. + (list)->prev = (link); \
  44418. + (link)->next = (list); \
  44419. + (link)->prev = __prev__; \
  44420. + __prev__->next = (link); \
  44421. +} while (0)
  44422. +#endif
  44423. +
  44424. +#if 0
  44425. +static inline void __list_add(struct list_head *new,
  44426. + struct list_head *prev,
  44427. + struct list_head *next)
  44428. +{
  44429. + next->prev = new;
  44430. + new->next = next;
  44431. + new->prev = prev;
  44432. + prev->next = new;
  44433. +}
  44434. +
  44435. +static inline void list_add(struct list_head *new, struct list_head *head)
  44436. +{
  44437. + __list_add(new, head, head->next);
  44438. +}
  44439. +
  44440. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  44441. +{
  44442. + __list_add(new, head->prev, head);
  44443. +}
  44444. +
  44445. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  44446. +{
  44447. + next->prev = prev;
  44448. + prev->next = next;
  44449. +}
  44450. +
  44451. +static inline void list_del(struct list_head *entry)
  44452. +{
  44453. + __list_del(entry->prev, entry->next);
  44454. + entry->next = LIST_POISON1;
  44455. + entry->prev = LIST_POISON2;
  44456. +}
  44457. +#endif
  44458. +
  44459. +#define DWC_LIST_REMOVE(link) do { \
  44460. + (link)->next->prev = (link)->prev; \
  44461. + (link)->prev->next = (link)->next; \
  44462. +} while (0)
  44463. +
  44464. +#define DWC_LIST_REMOVE_INIT(link) do { \
  44465. + DWC_LIST_REMOVE(link); \
  44466. + DWC_LIST_INIT(link); \
  44467. +} while (0)
  44468. +
  44469. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  44470. + DWC_LIST_REMOVE(link); \
  44471. + DWC_LIST_INSERT_HEAD(list, link); \
  44472. +} while (0)
  44473. +
  44474. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  44475. + DWC_LIST_REMOVE(link); \
  44476. + DWC_LIST_INSERT_TAIL(list, link); \
  44477. +} while (0)
  44478. +
  44479. +#define DWC_LIST_FOREACH(var, list) \
  44480. + for((var) = DWC_LIST_FIRST(list); \
  44481. + (var) != DWC_LIST_END(list); \
  44482. + (var) = DWC_LIST_NEXT(var))
  44483. +
  44484. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  44485. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  44486. + (var) != DWC_LIST_END(list); \
  44487. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  44488. +
  44489. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  44490. + for((var) = DWC_LIST_LAST(list); \
  44491. + (var) != DWC_LIST_END(list); \
  44492. + (var) = DWC_LIST_PREV(var))
  44493. +
  44494. +/*
  44495. + * Singly-linked List definitions.
  44496. + */
  44497. +#define DWC_SLIST_HEAD(name, type) \
  44498. +struct name { \
  44499. + struct type *slh_first; /* first element */ \
  44500. +}
  44501. +
  44502. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  44503. + { NULL }
  44504. +
  44505. +#define DWC_SLIST_ENTRY(type) \
  44506. +struct { \
  44507. + struct type *sle_next; /* next element */ \
  44508. +}
  44509. +
  44510. +/*
  44511. + * Singly-linked List access methods.
  44512. + */
  44513. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  44514. +#define DWC_SLIST_END(head) NULL
  44515. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  44516. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  44517. +
  44518. +#define DWC_SLIST_FOREACH(var, head, field) \
  44519. + for((var) = SLIST_FIRST(head); \
  44520. + (var) != SLIST_END(head); \
  44521. + (var) = SLIST_NEXT(var, field))
  44522. +
  44523. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  44524. + for((varp) = &SLIST_FIRST((head)); \
  44525. + ((var) = *(varp)) != SLIST_END(head); \
  44526. + (varp) = &SLIST_NEXT((var), field))
  44527. +
  44528. +/*
  44529. + * Singly-linked List functions.
  44530. + */
  44531. +#define DWC_SLIST_INIT(head) { \
  44532. + SLIST_FIRST(head) = SLIST_END(head); \
  44533. +}
  44534. +
  44535. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  44536. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  44537. + (slistelm)->field.sle_next = (elm); \
  44538. +} while (0)
  44539. +
  44540. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  44541. + (elm)->field.sle_next = (head)->slh_first; \
  44542. + (head)->slh_first = (elm); \
  44543. +} while (0)
  44544. +
  44545. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  44546. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  44547. +} while (0)
  44548. +
  44549. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  44550. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  44551. +} while (0)
  44552. +
  44553. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  44554. + if ((head)->slh_first == (elm)) { \
  44555. + SLIST_REMOVE_HEAD((head), field); \
  44556. + } \
  44557. + else { \
  44558. + struct type *curelm = (head)->slh_first; \
  44559. + while( curelm->field.sle_next != (elm) ) \
  44560. + curelm = curelm->field.sle_next; \
  44561. + curelm->field.sle_next = \
  44562. + curelm->field.sle_next->field.sle_next; \
  44563. + } \
  44564. +} while (0)
  44565. +
  44566. +/*
  44567. + * Simple queue definitions.
  44568. + */
  44569. +#define DWC_SIMPLEQ_HEAD(name, type) \
  44570. +struct name { \
  44571. + struct type *sqh_first; /* first element */ \
  44572. + struct type **sqh_last; /* addr of last next element */ \
  44573. +}
  44574. +
  44575. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  44576. + { NULL, &(head).sqh_first }
  44577. +
  44578. +#define DWC_SIMPLEQ_ENTRY(type) \
  44579. +struct { \
  44580. + struct type *sqe_next; /* next element */ \
  44581. +}
  44582. +
  44583. +/*
  44584. + * Simple queue access methods.
  44585. + */
  44586. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  44587. +#define DWC_SIMPLEQ_END(head) NULL
  44588. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  44589. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  44590. +
  44591. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  44592. + for((var) = SIMPLEQ_FIRST(head); \
  44593. + (var) != SIMPLEQ_END(head); \
  44594. + (var) = SIMPLEQ_NEXT(var, field))
  44595. +
  44596. +/*
  44597. + * Simple queue functions.
  44598. + */
  44599. +#define DWC_SIMPLEQ_INIT(head) do { \
  44600. + (head)->sqh_first = NULL; \
  44601. + (head)->sqh_last = &(head)->sqh_first; \
  44602. +} while (0)
  44603. +
  44604. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  44605. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  44606. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44607. + (head)->sqh_first = (elm); \
  44608. +} while (0)
  44609. +
  44610. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  44611. + (elm)->field.sqe_next = NULL; \
  44612. + *(head)->sqh_last = (elm); \
  44613. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44614. +} while (0)
  44615. +
  44616. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44617. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  44618. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44619. + (listelm)->field.sqe_next = (elm); \
  44620. +} while (0)
  44621. +
  44622. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  44623. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  44624. + (head)->sqh_last = &(head)->sqh_first; \
  44625. +} while (0)
  44626. +
  44627. +/*
  44628. + * Tail queue definitions.
  44629. + */
  44630. +#define DWC_TAILQ_HEAD(name, type) \
  44631. +struct name { \
  44632. + struct type *tqh_first; /* first element */ \
  44633. + struct type **tqh_last; /* addr of last next element */ \
  44634. +}
  44635. +
  44636. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  44637. + { NULL, &(head).tqh_first }
  44638. +
  44639. +#define DWC_TAILQ_ENTRY(type) \
  44640. +struct { \
  44641. + struct type *tqe_next; /* next element */ \
  44642. + struct type **tqe_prev; /* address of previous next element */ \
  44643. +}
  44644. +
  44645. +/*
  44646. + * tail queue access methods
  44647. + */
  44648. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  44649. +#define DWC_TAILQ_END(head) NULL
  44650. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  44651. +#define DWC_TAILQ_LAST(head, headname) \
  44652. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  44653. +/* XXX */
  44654. +#define DWC_TAILQ_PREV(elm, headname, field) \
  44655. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  44656. +#define DWC_TAILQ_EMPTY(head) \
  44657. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  44658. +
  44659. +#define DWC_TAILQ_FOREACH(var, head, field) \
  44660. + for ((var) = DWC_TAILQ_FIRST(head); \
  44661. + (var) != DWC_TAILQ_END(head); \
  44662. + (var) = DWC_TAILQ_NEXT(var, field))
  44663. +
  44664. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  44665. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  44666. + (var) != DWC_TAILQ_END(head); \
  44667. + (var) = DWC_TAILQ_PREV(var, headname, field))
  44668. +
  44669. +/*
  44670. + * Tail queue functions.
  44671. + */
  44672. +#define DWC_TAILQ_INIT(head) do { \
  44673. + (head)->tqh_first = NULL; \
  44674. + (head)->tqh_last = &(head)->tqh_first; \
  44675. +} while (0)
  44676. +
  44677. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  44678. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  44679. + (head)->tqh_first->field.tqe_prev = \
  44680. + &(elm)->field.tqe_next; \
  44681. + else \
  44682. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44683. + (head)->tqh_first = (elm); \
  44684. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  44685. +} while (0)
  44686. +
  44687. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  44688. + (elm)->field.tqe_next = NULL; \
  44689. + (elm)->field.tqe_prev = (head)->tqh_last; \
  44690. + *(head)->tqh_last = (elm); \
  44691. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44692. +} while (0)
  44693. +
  44694. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44695. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  44696. + (elm)->field.tqe_next->field.tqe_prev = \
  44697. + &(elm)->field.tqe_next; \
  44698. + else \
  44699. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44700. + (listelm)->field.tqe_next = (elm); \
  44701. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  44702. +} while (0)
  44703. +
  44704. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  44705. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  44706. + (elm)->field.tqe_next = (listelm); \
  44707. + *(listelm)->field.tqe_prev = (elm); \
  44708. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  44709. +} while (0)
  44710. +
  44711. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  44712. + if (((elm)->field.tqe_next) != NULL) \
  44713. + (elm)->field.tqe_next->field.tqe_prev = \
  44714. + (elm)->field.tqe_prev; \
  44715. + else \
  44716. + (head)->tqh_last = (elm)->field.tqe_prev; \
  44717. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  44718. +} while (0)
  44719. +
  44720. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  44721. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  44722. + (elm2)->field.tqe_next->field.tqe_prev = \
  44723. + &(elm2)->field.tqe_next; \
  44724. + else \
  44725. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  44726. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  44727. + *(elm2)->field.tqe_prev = (elm2); \
  44728. +} while (0)
  44729. +
  44730. +/*
  44731. + * Circular queue definitions.
  44732. + */
  44733. +#define DWC_CIRCLEQ_HEAD(name, type) \
  44734. +struct name { \
  44735. + struct type *cqh_first; /* first element */ \
  44736. + struct type *cqh_last; /* last element */ \
  44737. +}
  44738. +
  44739. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  44740. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  44741. +
  44742. +#define DWC_CIRCLEQ_ENTRY(type) \
  44743. +struct { \
  44744. + struct type *cqe_next; /* next element */ \
  44745. + struct type *cqe_prev; /* previous element */ \
  44746. +}
  44747. +
  44748. +/*
  44749. + * Circular queue access methods
  44750. + */
  44751. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  44752. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  44753. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  44754. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  44755. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  44756. +#define DWC_CIRCLEQ_EMPTY(head) \
  44757. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  44758. +
  44759. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  44760. +
  44761. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  44762. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  44763. + (var) != DWC_CIRCLEQ_END(head); \
  44764. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  44765. +
  44766. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  44767. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  44768. + (var) != DWC_CIRCLEQ_END(head); \
  44769. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  44770. +
  44771. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  44772. + for((var) = DWC_CIRCLEQ_LAST(head); \
  44773. + (var) != DWC_CIRCLEQ_END(head); \
  44774. + (var) = DWC_CIRCLEQ_PREV(var, field))
  44775. +
  44776. +/*
  44777. + * Circular queue functions.
  44778. + */
  44779. +#define DWC_CIRCLEQ_INIT(head) do { \
  44780. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  44781. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  44782. +} while (0)
  44783. +
  44784. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  44785. + (elm)->field.cqe_next = NULL; \
  44786. + (elm)->field.cqe_prev = NULL; \
  44787. +} while (0)
  44788. +
  44789. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44790. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  44791. + (elm)->field.cqe_prev = (listelm); \
  44792. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44793. + (head)->cqh_last = (elm); \
  44794. + else \
  44795. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  44796. + (listelm)->field.cqe_next = (elm); \
  44797. +} while (0)
  44798. +
  44799. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  44800. + (elm)->field.cqe_next = (listelm); \
  44801. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  44802. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44803. + (head)->cqh_first = (elm); \
  44804. + else \
  44805. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  44806. + (listelm)->field.cqe_prev = (elm); \
  44807. +} while (0)
  44808. +
  44809. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  44810. + (elm)->field.cqe_next = (head)->cqh_first; \
  44811. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  44812. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  44813. + (head)->cqh_last = (elm); \
  44814. + else \
  44815. + (head)->cqh_first->field.cqe_prev = (elm); \
  44816. + (head)->cqh_first = (elm); \
  44817. +} while (0)
  44818. +
  44819. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  44820. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  44821. + (elm)->field.cqe_prev = (head)->cqh_last; \
  44822. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  44823. + (head)->cqh_first = (elm); \
  44824. + else \
  44825. + (head)->cqh_last->field.cqe_next = (elm); \
  44826. + (head)->cqh_last = (elm); \
  44827. +} while (0)
  44828. +
  44829. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  44830. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44831. + (head)->cqh_last = (elm)->field.cqe_prev; \
  44832. + else \
  44833. + (elm)->field.cqe_next->field.cqe_prev = \
  44834. + (elm)->field.cqe_prev; \
  44835. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44836. + (head)->cqh_first = (elm)->field.cqe_next; \
  44837. + else \
  44838. + (elm)->field.cqe_prev->field.cqe_next = \
  44839. + (elm)->field.cqe_next; \
  44840. +} while (0)
  44841. +
  44842. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  44843. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  44844. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  44845. +} while (0)
  44846. +
  44847. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  44848. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  44849. + DWC_CIRCLEQ_END(head)) \
  44850. + (head).cqh_last = (elm2); \
  44851. + else \
  44852. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  44853. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  44854. + DWC_CIRCLEQ_END(head)) \
  44855. + (head).cqh_first = (elm2); \
  44856. + else \
  44857. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  44858. +} while (0)
  44859. +
  44860. +#ifdef __cplusplus
  44861. +}
  44862. +#endif
  44863. +
  44864. +#endif /* _DWC_LIST_H_ */
  44865. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_mem.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_mem.c
  44866. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  44867. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-02-07 19:57:30.000000000 +0100
  44868. @@ -0,0 +1,245 @@
  44869. +/* Memory Debugging */
  44870. +#ifdef DWC_DEBUG_MEMORY
  44871. +
  44872. +#include "dwc_os.h"
  44873. +#include "dwc_list.h"
  44874. +
  44875. +struct allocation {
  44876. + void *addr;
  44877. + void *ctx;
  44878. + char *func;
  44879. + int line;
  44880. + uint32_t size;
  44881. + int dma;
  44882. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  44883. +};
  44884. +
  44885. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  44886. +
  44887. +struct allocation_manager {
  44888. + void *mem_ctx;
  44889. + struct allocation_queue allocations;
  44890. +
  44891. + /* statistics */
  44892. + int num;
  44893. + int num_freed;
  44894. + int num_active;
  44895. + uint32_t total;
  44896. + uint32_t cur;
  44897. + uint32_t max;
  44898. +};
  44899. +
  44900. +static struct allocation_manager *manager = NULL;
  44901. +
  44902. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  44903. + int dma)
  44904. +{
  44905. + struct allocation *a;
  44906. +
  44907. + DWC_ASSERT(manager != NULL, "manager not allocated");
  44908. +
  44909. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  44910. + if (!a) {
  44911. + return -DWC_E_NO_MEMORY;
  44912. + }
  44913. +
  44914. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  44915. + if (!a->func) {
  44916. + __DWC_FREE(manager->mem_ctx, a);
  44917. + return -DWC_E_NO_MEMORY;
  44918. + }
  44919. +
  44920. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  44921. + a->addr = addr;
  44922. + a->ctx = ctx;
  44923. + a->line = line;
  44924. + a->size = size;
  44925. + a->dma = dma;
  44926. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  44927. +
  44928. + /* Update stats */
  44929. + manager->num++;
  44930. + manager->num_active++;
  44931. + manager->total += size;
  44932. + manager->cur += size;
  44933. +
  44934. + if (manager->max < manager->cur) {
  44935. + manager->max = manager->cur;
  44936. + }
  44937. +
  44938. + return 0;
  44939. +}
  44940. +
  44941. +static struct allocation *find_allocation(void *ctx, void *addr)
  44942. +{
  44943. + struct allocation *a;
  44944. +
  44945. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44946. + if (a->ctx == ctx && a->addr == addr) {
  44947. + return a;
  44948. + }
  44949. + }
  44950. +
  44951. + return NULL;
  44952. +}
  44953. +
  44954. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  44955. +{
  44956. + struct allocation *a = find_allocation(ctx, addr);
  44957. +
  44958. + if (!a) {
  44959. + DWC_ASSERT(0,
  44960. + "Free of address %p that was never allocated or already freed %s:%d",
  44961. + addr, func, line);
  44962. + return;
  44963. + }
  44964. +
  44965. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  44966. +
  44967. + manager->num_active--;
  44968. + manager->num_freed++;
  44969. + manager->cur -= a->size;
  44970. + __DWC_FREE(manager->mem_ctx, a->func);
  44971. + __DWC_FREE(manager->mem_ctx, a);
  44972. +}
  44973. +
  44974. +int dwc_memory_debug_start(void *mem_ctx)
  44975. +{
  44976. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  44977. +
  44978. + if (manager) {
  44979. + return -DWC_E_BUSY;
  44980. + }
  44981. +
  44982. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  44983. + if (!manager) {
  44984. + return -DWC_E_NO_MEMORY;
  44985. + }
  44986. +
  44987. + DWC_CIRCLEQ_INIT(&manager->allocations);
  44988. + manager->mem_ctx = mem_ctx;
  44989. + manager->num = 0;
  44990. + manager->num_freed = 0;
  44991. + manager->num_active = 0;
  44992. + manager->total = 0;
  44993. + manager->cur = 0;
  44994. + manager->max = 0;
  44995. +
  44996. + return 0;
  44997. +}
  44998. +
  44999. +void dwc_memory_debug_stop(void)
  45000. +{
  45001. + struct allocation *a;
  45002. +
  45003. + dwc_memory_debug_report();
  45004. +
  45005. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45006. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  45007. + free_allocation(a->ctx, a->addr, NULL, -1);
  45008. + }
  45009. +
  45010. + __DWC_FREE(manager->mem_ctx, manager);
  45011. +}
  45012. +
  45013. +void dwc_memory_debug_report(void)
  45014. +{
  45015. + struct allocation *a;
  45016. +
  45017. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  45018. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  45019. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  45020. + DWC_PRINTF("Active = %d\n", manager->num_active);
  45021. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  45022. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  45023. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  45024. + DWC_PRINTF("Unfreed allocations:\n");
  45025. +
  45026. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45027. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  45028. + a->addr, a->size, a->func, a->line, a->dma);
  45029. + }
  45030. +}
  45031. +
  45032. +/* The replacement functions */
  45033. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  45034. +{
  45035. + void *addr = __DWC_ALLOC(mem_ctx, size);
  45036. +
  45037. + if (!addr) {
  45038. + return NULL;
  45039. + }
  45040. +
  45041. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45042. + __DWC_FREE(mem_ctx, addr);
  45043. + return NULL;
  45044. + }
  45045. +
  45046. + return addr;
  45047. +}
  45048. +
  45049. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  45050. + int line)
  45051. +{
  45052. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  45053. +
  45054. + if (!addr) {
  45055. + return NULL;
  45056. + }
  45057. +
  45058. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45059. + __DWC_FREE(mem_ctx, addr);
  45060. + return NULL;
  45061. + }
  45062. +
  45063. + return addr;
  45064. +}
  45065. +
  45066. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  45067. +{
  45068. + free_allocation(mem_ctx, addr, func, line);
  45069. + __DWC_FREE(mem_ctx, addr);
  45070. +}
  45071. +
  45072. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  45073. + char const *func, int line)
  45074. +{
  45075. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  45076. +
  45077. + if (!addr) {
  45078. + return NULL;
  45079. + }
  45080. +
  45081. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45082. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45083. + return NULL;
  45084. + }
  45085. +
  45086. + return addr;
  45087. +}
  45088. +
  45089. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  45090. + dwc_dma_t *dma_addr, char const *func, int line)
  45091. +{
  45092. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  45093. +
  45094. + if (!addr) {
  45095. + return NULL;
  45096. + }
  45097. +
  45098. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45099. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45100. + return NULL;
  45101. + }
  45102. +
  45103. + return addr;
  45104. +}
  45105. +
  45106. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  45107. + dwc_dma_t dma_addr, char const *func, int line)
  45108. +{
  45109. + free_allocation(dma_ctx, virt_addr, func, line);
  45110. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  45111. +}
  45112. +
  45113. +#endif /* DWC_DEBUG_MEMORY */
  45114. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_modpow.c
  45115. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  45116. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-02-07 19:57:30.000000000 +0100
  45117. @@ -0,0 +1,636 @@
  45118. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  45119. + *
  45120. + * PuTTY is copyright 1997-2007 Simon Tatham.
  45121. + *
  45122. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  45123. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  45124. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  45125. + * Kuhn, and CORE SDI S.A.
  45126. + *
  45127. + * Permission is hereby granted, free of charge, to any person
  45128. + * obtaining a copy of this software and associated documentation files
  45129. + * (the "Software"), to deal in the Software without restriction,
  45130. + * including without limitation the rights to use, copy, modify, merge,
  45131. + * publish, distribute, sublicense, and/or sell copies of the Software,
  45132. + * and to permit persons to whom the Software is furnished to do so,
  45133. + * subject to the following conditions:
  45134. + *
  45135. + * The above copyright notice and this permission notice shall be
  45136. + * included in all copies or substantial portions of the Software.
  45137. +
  45138. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  45139. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  45140. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  45141. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  45142. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  45143. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  45144. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45145. + *
  45146. + */
  45147. +#ifdef DWC_CRYPTOLIB
  45148. +
  45149. +#ifndef CONFIG_MACH_IPMATE
  45150. +
  45151. +#include "dwc_modpow.h"
  45152. +
  45153. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  45154. +#define BIGNUM_TOP_BIT 0x80000000UL
  45155. +#define BIGNUM_INT_BITS 32
  45156. +
  45157. +
  45158. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  45159. +{
  45160. + void *p;
  45161. + size *= n;
  45162. + if (size == 0) size = 1;
  45163. + p = dwc_alloc(mem_ctx, size);
  45164. + return p;
  45165. +}
  45166. +
  45167. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  45168. +#define sfree dwc_free
  45169. +
  45170. +/*
  45171. + * Usage notes:
  45172. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  45173. + * subscripts, as some implementations object to this (see below).
  45174. + * * Note that none of the division methods below will cope if the
  45175. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  45176. + * to avoid this case.
  45177. + * If this condition occurs, in the case of the x86 DIV instruction,
  45178. + * an overflow exception will occur, which (according to a correspondent)
  45179. + * will manifest on Windows as something like
  45180. + * 0xC0000095: Integer overflow
  45181. + * The C variant won't give the right answer, either.
  45182. + */
  45183. +
  45184. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  45185. +
  45186. +#if defined __GNUC__ && defined __i386__
  45187. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  45188. + __asm__("div %2" : \
  45189. + "=d" (r), "=a" (q) : \
  45190. + "r" (w), "d" (hi), "a" (lo))
  45191. +#else
  45192. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  45193. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  45194. + q = n / w; \
  45195. + r = n % w; \
  45196. +} while (0)
  45197. +#endif
  45198. +
  45199. +// q = n / w;
  45200. +// r = n % w;
  45201. +
  45202. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  45203. +
  45204. +#define BIGNUM_INTERNAL
  45205. +
  45206. +static Bignum newbn(void *mem_ctx, int length)
  45207. +{
  45208. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  45209. + //if (!b)
  45210. + //abort(); /* FIXME */
  45211. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  45212. + b[0] = length;
  45213. + return b;
  45214. +}
  45215. +
  45216. +void freebn(void *mem_ctx, Bignum b)
  45217. +{
  45218. + /*
  45219. + * Burn the evidence, just in case.
  45220. + */
  45221. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  45222. + sfree(mem_ctx, b);
  45223. +}
  45224. +
  45225. +/*
  45226. + * Compute c = a * b.
  45227. + * Input is in the first len words of a and b.
  45228. + * Result is returned in the first 2*len words of c.
  45229. + */
  45230. +static void internal_mul(BignumInt *a, BignumInt *b,
  45231. + BignumInt *c, int len)
  45232. +{
  45233. + int i, j;
  45234. + BignumDblInt t;
  45235. +
  45236. + for (j = 0; j < 2 * len; j++)
  45237. + c[j] = 0;
  45238. +
  45239. + for (i = len - 1; i >= 0; i--) {
  45240. + t = 0;
  45241. + for (j = len - 1; j >= 0; j--) {
  45242. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  45243. + t += (BignumDblInt) c[i + j + 1];
  45244. + c[i + j + 1] = (BignumInt) t;
  45245. + t = t >> BIGNUM_INT_BITS;
  45246. + }
  45247. + c[i] = (BignumInt) t;
  45248. + }
  45249. +}
  45250. +
  45251. +static void internal_add_shifted(BignumInt *number,
  45252. + unsigned n, int shift)
  45253. +{
  45254. + int word = 1 + (shift / BIGNUM_INT_BITS);
  45255. + int bshift = shift % BIGNUM_INT_BITS;
  45256. + BignumDblInt addend;
  45257. +
  45258. + addend = (BignumDblInt)n << bshift;
  45259. +
  45260. + while (addend) {
  45261. + addend += number[word];
  45262. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  45263. + addend >>= BIGNUM_INT_BITS;
  45264. + word++;
  45265. + }
  45266. +}
  45267. +
  45268. +/*
  45269. + * Compute a = a % m.
  45270. + * Input in first alen words of a and first mlen words of m.
  45271. + * Output in first alen words of a
  45272. + * (of which first alen-mlen words will be zero).
  45273. + * The MSW of m MUST have its high bit set.
  45274. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  45275. + * rather than the internal bigendian format. Quotient parts are shifted
  45276. + * left by `qshift' before adding into quot.
  45277. + */
  45278. +static void internal_mod(BignumInt *a, int alen,
  45279. + BignumInt *m, int mlen,
  45280. + BignumInt *quot, int qshift)
  45281. +{
  45282. + BignumInt m0, m1;
  45283. + unsigned int h;
  45284. + int i, k;
  45285. +
  45286. + m0 = m[0];
  45287. + if (mlen > 1)
  45288. + m1 = m[1];
  45289. + else
  45290. + m1 = 0;
  45291. +
  45292. + for (i = 0; i <= alen - mlen; i++) {
  45293. + BignumDblInt t;
  45294. + unsigned int q, r, c, ai1;
  45295. +
  45296. + if (i == 0) {
  45297. + h = 0;
  45298. + } else {
  45299. + h = a[i - 1];
  45300. + a[i - 1] = 0;
  45301. + }
  45302. +
  45303. + if (i == alen - 1)
  45304. + ai1 = 0;
  45305. + else
  45306. + ai1 = a[i + 1];
  45307. +
  45308. + /* Find q = h:a[i] / m0 */
  45309. + if (h >= m0) {
  45310. + /*
  45311. + * Special case.
  45312. + *
  45313. + * To illustrate it, suppose a BignumInt is 8 bits, and
  45314. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  45315. + * our initial division will be 0xA123 / 0xA1, which
  45316. + * will give a quotient of 0x100 and a divide overflow.
  45317. + * However, the invariants in this division algorithm
  45318. + * are not violated, since the full number A1:23:... is
  45319. + * _less_ than the quotient prefix A1:B2:... and so the
  45320. + * following correction loop would have sorted it out.
  45321. + *
  45322. + * In this situation we set q to be the largest
  45323. + * quotient we _can_ stomach (0xFF, of course).
  45324. + */
  45325. + q = BIGNUM_INT_MASK;
  45326. + } else {
  45327. + /* Macro doesn't want an array subscript expression passed
  45328. + * into it (see definition), so use a temporary. */
  45329. + BignumInt tmplo = a[i];
  45330. + DIVMOD_WORD(q, r, h, tmplo, m0);
  45331. +
  45332. + /* Refine our estimate of q by looking at
  45333. + h:a[i]:a[i+1] / m0:m1 */
  45334. + t = MUL_WORD(m1, q);
  45335. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  45336. + q--;
  45337. + t -= m1;
  45338. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  45339. + if (r >= (BignumDblInt) m0 &&
  45340. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  45341. + }
  45342. + }
  45343. +
  45344. + /* Subtract q * m from a[i...] */
  45345. + c = 0;
  45346. + for (k = mlen - 1; k >= 0; k--) {
  45347. + t = MUL_WORD(q, m[k]);
  45348. + t += c;
  45349. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  45350. + if ((BignumInt) t > a[i + k])
  45351. + c++;
  45352. + a[i + k] -= (BignumInt) t;
  45353. + }
  45354. +
  45355. + /* Add back m in case of borrow */
  45356. + if (c != h) {
  45357. + t = 0;
  45358. + for (k = mlen - 1; k >= 0; k--) {
  45359. + t += m[k];
  45360. + t += a[i + k];
  45361. + a[i + k] = (BignumInt) t;
  45362. + t = t >> BIGNUM_INT_BITS;
  45363. + }
  45364. + q--;
  45365. + }
  45366. + if (quot)
  45367. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  45368. + }
  45369. +}
  45370. +
  45371. +/*
  45372. + * Compute p % mod.
  45373. + * The most significant word of mod MUST be non-zero.
  45374. + * We assume that the result array is the same size as the mod array.
  45375. + * We optionally write out a quotient if `quotient' is non-NULL.
  45376. + * We can avoid writing out the result if `result' is NULL.
  45377. + */
  45378. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  45379. +{
  45380. + BignumInt *n, *m;
  45381. + int mshift;
  45382. + int plen, mlen, i, j;
  45383. +
  45384. + /* Allocate m of size mlen, copy mod to m */
  45385. + /* We use big endian internally */
  45386. + mlen = mod[0];
  45387. + m = snewn(mem_ctx, mlen, BignumInt);
  45388. + //if (!m)
  45389. + //abort(); /* FIXME */
  45390. + for (j = 0; j < mlen; j++)
  45391. + m[j] = mod[mod[0] - j];
  45392. +
  45393. + /* Shift m left to make msb bit set */
  45394. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  45395. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45396. + break;
  45397. + if (mshift) {
  45398. + for (i = 0; i < mlen - 1; i++)
  45399. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45400. + m[mlen - 1] = m[mlen - 1] << mshift;
  45401. + }
  45402. +
  45403. + plen = p[0];
  45404. + /* Ensure plen > mlen */
  45405. + if (plen <= mlen)
  45406. + plen = mlen + 1;
  45407. +
  45408. + /* Allocate n of size plen, copy p to n */
  45409. + n = snewn(mem_ctx, plen, BignumInt);
  45410. + //if (!n)
  45411. + //abort(); /* FIXME */
  45412. + for (j = 0; j < plen; j++)
  45413. + n[j] = 0;
  45414. + for (j = 1; j <= (int)p[0]; j++)
  45415. + n[plen - j] = p[j];
  45416. +
  45417. + /* Main computation */
  45418. + internal_mod(n, plen, m, mlen, quotient, mshift);
  45419. +
  45420. + /* Fixup result in case the modulus was shifted */
  45421. + if (mshift) {
  45422. + for (i = plen - mlen - 1; i < plen - 1; i++)
  45423. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45424. + n[plen - 1] = n[plen - 1] << mshift;
  45425. + internal_mod(n, plen, m, mlen, quotient, 0);
  45426. + for (i = plen - 1; i >= plen - mlen; i--)
  45427. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  45428. + }
  45429. +
  45430. + /* Copy result to buffer */
  45431. + if (result) {
  45432. + for (i = 1; i <= (int)result[0]; i++) {
  45433. + int j = plen - i;
  45434. + result[i] = j >= 0 ? n[j] : 0;
  45435. + }
  45436. + }
  45437. +
  45438. + /* Free temporary arrays */
  45439. + for (i = 0; i < mlen; i++)
  45440. + m[i] = 0;
  45441. + sfree(mem_ctx, m);
  45442. + for (i = 0; i < plen; i++)
  45443. + n[i] = 0;
  45444. + sfree(mem_ctx, n);
  45445. +}
  45446. +
  45447. +/*
  45448. + * Simple remainder.
  45449. + */
  45450. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  45451. +{
  45452. + Bignum r = newbn(mem_ctx, b[0]);
  45453. + bigdivmod(mem_ctx, a, b, r, NULL);
  45454. + return r;
  45455. +}
  45456. +
  45457. +/*
  45458. + * Compute (base ^ exp) % mod.
  45459. + */
  45460. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  45461. +{
  45462. + BignumInt *a, *b, *n, *m;
  45463. + int mshift;
  45464. + int mlen, i, j;
  45465. + Bignum base, result;
  45466. +
  45467. + /*
  45468. + * The most significant word of mod needs to be non-zero. It
  45469. + * should already be, but let's make sure.
  45470. + */
  45471. + //assert(mod[mod[0]] != 0);
  45472. +
  45473. + /*
  45474. + * Make sure the base is smaller than the modulus, by reducing
  45475. + * it modulo the modulus if not.
  45476. + */
  45477. + base = bigmod(mem_ctx, base_in, mod);
  45478. +
  45479. + /* Allocate m of size mlen, copy mod to m */
  45480. + /* We use big endian internally */
  45481. + mlen = mod[0];
  45482. + m = snewn(mem_ctx, mlen, BignumInt);
  45483. + //if (!m)
  45484. + //abort(); /* FIXME */
  45485. + for (j = 0; j < mlen; j++)
  45486. + m[j] = mod[mod[0] - j];
  45487. +
  45488. + /* Shift m left to make msb bit set */
  45489. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  45490. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45491. + break;
  45492. + if (mshift) {
  45493. + for (i = 0; i < mlen - 1; i++)
  45494. + m[i] =
  45495. + (m[i] << mshift) | (m[i + 1] >>
  45496. + (BIGNUM_INT_BITS - mshift));
  45497. + m[mlen - 1] = m[mlen - 1] << mshift;
  45498. + }
  45499. +
  45500. + /* Allocate n of size mlen, copy base to n */
  45501. + n = snewn(mem_ctx, mlen, BignumInt);
  45502. + //if (!n)
  45503. + //abort(); /* FIXME */
  45504. + i = mlen - base[0];
  45505. + for (j = 0; j < i; j++)
  45506. + n[j] = 0;
  45507. + for (j = 0; j < base[0]; j++)
  45508. + n[i + j] = base[base[0] - j];
  45509. +
  45510. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  45511. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  45512. + //if (!a)
  45513. + //abort(); /* FIXME */
  45514. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  45515. + //if (!b)
  45516. + //abort(); /* FIXME */
  45517. + for (i = 0; i < 2 * mlen; i++)
  45518. + a[i] = 0;
  45519. + a[2 * mlen - 1] = 1;
  45520. +
  45521. + /* Skip leading zero bits of exp. */
  45522. + i = 0;
  45523. + j = BIGNUM_INT_BITS - 1;
  45524. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  45525. + j--;
  45526. + if (j < 0) {
  45527. + i++;
  45528. + j = BIGNUM_INT_BITS - 1;
  45529. + }
  45530. + }
  45531. +
  45532. + /* Main computation */
  45533. + while (i < exp[0]) {
  45534. + while (j >= 0) {
  45535. + internal_mul(a + mlen, a + mlen, b, mlen);
  45536. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  45537. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  45538. + internal_mul(b + mlen, n, a, mlen);
  45539. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45540. + } else {
  45541. + BignumInt *t;
  45542. + t = a;
  45543. + a = b;
  45544. + b = t;
  45545. + }
  45546. + j--;
  45547. + }
  45548. + i++;
  45549. + j = BIGNUM_INT_BITS - 1;
  45550. + }
  45551. +
  45552. + /* Fixup result in case the modulus was shifted */
  45553. + if (mshift) {
  45554. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  45555. + a[i] =
  45556. + (a[i] << mshift) | (a[i + 1] >>
  45557. + (BIGNUM_INT_BITS - mshift));
  45558. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  45559. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45560. + for (i = 2 * mlen - 1; i >= mlen; i--)
  45561. + a[i] =
  45562. + (a[i] >> mshift) | (a[i - 1] <<
  45563. + (BIGNUM_INT_BITS - mshift));
  45564. + }
  45565. +
  45566. + /* Copy result to buffer */
  45567. + result = newbn(mem_ctx, mod[0]);
  45568. + for (i = 0; i < mlen; i++)
  45569. + result[result[0] - i] = a[i + mlen];
  45570. + while (result[0] > 1 && result[result[0]] == 0)
  45571. + result[0]--;
  45572. +
  45573. + /* Free temporary arrays */
  45574. + for (i = 0; i < 2 * mlen; i++)
  45575. + a[i] = 0;
  45576. + sfree(mem_ctx, a);
  45577. + for (i = 0; i < 2 * mlen; i++)
  45578. + b[i] = 0;
  45579. + sfree(mem_ctx, b);
  45580. + for (i = 0; i < mlen; i++)
  45581. + m[i] = 0;
  45582. + sfree(mem_ctx, m);
  45583. + for (i = 0; i < mlen; i++)
  45584. + n[i] = 0;
  45585. + sfree(mem_ctx, n);
  45586. +
  45587. + freebn(mem_ctx, base);
  45588. +
  45589. + return result;
  45590. +}
  45591. +
  45592. +
  45593. +#ifdef UNITTEST
  45594. +
  45595. +static __u32 dh_p[] = {
  45596. + 96,
  45597. + 0xFFFFFFFF,
  45598. + 0xFFFFFFFF,
  45599. + 0xA93AD2CA,
  45600. + 0x4B82D120,
  45601. + 0xE0FD108E,
  45602. + 0x43DB5BFC,
  45603. + 0x74E5AB31,
  45604. + 0x08E24FA0,
  45605. + 0xBAD946E2,
  45606. + 0x770988C0,
  45607. + 0x7A615D6C,
  45608. + 0xBBE11757,
  45609. + 0x177B200C,
  45610. + 0x521F2B18,
  45611. + 0x3EC86A64,
  45612. + 0xD8760273,
  45613. + 0xD98A0864,
  45614. + 0xF12FFA06,
  45615. + 0x1AD2EE6B,
  45616. + 0xCEE3D226,
  45617. + 0x4A25619D,
  45618. + 0x1E8C94E0,
  45619. + 0xDB0933D7,
  45620. + 0xABF5AE8C,
  45621. + 0xA6E1E4C7,
  45622. + 0xB3970F85,
  45623. + 0x5D060C7D,
  45624. + 0x8AEA7157,
  45625. + 0x58DBEF0A,
  45626. + 0xECFB8504,
  45627. + 0xDF1CBA64,
  45628. + 0xA85521AB,
  45629. + 0x04507A33,
  45630. + 0xAD33170D,
  45631. + 0x8AAAC42D,
  45632. + 0x15728E5A,
  45633. + 0x98FA0510,
  45634. + 0x15D22618,
  45635. + 0xEA956AE5,
  45636. + 0x3995497C,
  45637. + 0x95581718,
  45638. + 0xDE2BCBF6,
  45639. + 0x6F4C52C9,
  45640. + 0xB5C55DF0,
  45641. + 0xEC07A28F,
  45642. + 0x9B2783A2,
  45643. + 0x180E8603,
  45644. + 0xE39E772C,
  45645. + 0x2E36CE3B,
  45646. + 0x32905E46,
  45647. + 0xCA18217C,
  45648. + 0xF1746C08,
  45649. + 0x4ABC9804,
  45650. + 0x670C354E,
  45651. + 0x7096966D,
  45652. + 0x9ED52907,
  45653. + 0x208552BB,
  45654. + 0x1C62F356,
  45655. + 0xDCA3AD96,
  45656. + 0x83655D23,
  45657. + 0xFD24CF5F,
  45658. + 0x69163FA8,
  45659. + 0x1C55D39A,
  45660. + 0x98DA4836,
  45661. + 0xA163BF05,
  45662. + 0xC2007CB8,
  45663. + 0xECE45B3D,
  45664. + 0x49286651,
  45665. + 0x7C4B1FE6,
  45666. + 0xAE9F2411,
  45667. + 0x5A899FA5,
  45668. + 0xEE386BFB,
  45669. + 0xF406B7ED,
  45670. + 0x0BFF5CB6,
  45671. + 0xA637ED6B,
  45672. + 0xF44C42E9,
  45673. + 0x625E7EC6,
  45674. + 0xE485B576,
  45675. + 0x6D51C245,
  45676. + 0x4FE1356D,
  45677. + 0xF25F1437,
  45678. + 0x302B0A6D,
  45679. + 0xCD3A431B,
  45680. + 0xEF9519B3,
  45681. + 0x8E3404DD,
  45682. + 0x514A0879,
  45683. + 0x3B139B22,
  45684. + 0x020BBEA6,
  45685. + 0x8A67CC74,
  45686. + 0x29024E08,
  45687. + 0x80DC1CD1,
  45688. + 0xC4C6628B,
  45689. + 0x2168C234,
  45690. + 0xC90FDAA2,
  45691. + 0xFFFFFFFF,
  45692. + 0xFFFFFFFF,
  45693. +};
  45694. +
  45695. +static __u32 dh_a[] = {
  45696. + 8,
  45697. + 0xdf367516,
  45698. + 0x86459caa,
  45699. + 0xe2d459a4,
  45700. + 0xd910dae0,
  45701. + 0x8a8b5e37,
  45702. + 0x67ab31c6,
  45703. + 0xf0b55ea9,
  45704. + 0x440051d6,
  45705. +};
  45706. +
  45707. +static __u32 dh_b[] = {
  45708. + 8,
  45709. + 0xded92656,
  45710. + 0xe07a048a,
  45711. + 0x6fa452cd,
  45712. + 0x2df89d30,
  45713. + 0xc75f1b0f,
  45714. + 0x8ce3578f,
  45715. + 0x7980a324,
  45716. + 0x5daec786,
  45717. +};
  45718. +
  45719. +static __u32 dh_g[] = {
  45720. + 1,
  45721. + 2,
  45722. +};
  45723. +
  45724. +int main(void)
  45725. +{
  45726. + int i;
  45727. + __u32 *k;
  45728. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  45729. +
  45730. + printf("\n\n");
  45731. + for (i=0; i<k[0]; i++) {
  45732. + __u32 word32 = k[k[0] - i];
  45733. + __u16 l = word32 & 0xffff;
  45734. + __u16 m = (word32 & 0xffff0000) >> 16;
  45735. + printf("%04x %04x ", m, l);
  45736. + if (!((i + 1)%13)) printf("\n");
  45737. + }
  45738. + printf("\n\n");
  45739. +
  45740. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  45741. + printf("PASS\n\n");
  45742. + }
  45743. + else {
  45744. + printf("FAIL\n\n");
  45745. + }
  45746. +
  45747. +}
  45748. +
  45749. +#endif /* UNITTEST */
  45750. +
  45751. +#endif /* CONFIG_MACH_IPMATE */
  45752. +
  45753. +#endif /*DWC_CRYPTOLIB */
  45754. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_modpow.h
  45755. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  45756. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-02-07 19:57:30.000000000 +0100
  45757. @@ -0,0 +1,34 @@
  45758. +/*
  45759. + * dwc_modpow.h
  45760. + * See dwc_modpow.c for license and changes
  45761. + */
  45762. +#ifndef _DWC_MODPOW_H
  45763. +#define _DWC_MODPOW_H
  45764. +
  45765. +#ifdef __cplusplus
  45766. +extern "C" {
  45767. +#endif
  45768. +
  45769. +#include "dwc_os.h"
  45770. +
  45771. +/** @file
  45772. + *
  45773. + * This file defines the module exponentiation function which is only used
  45774. + * internally by the DWC UWB modules for calculation of PKs during numeric
  45775. + * association. The routine is taken from the PUTTY, an open source terminal
  45776. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  45777. + *
  45778. + */
  45779. +
  45780. +typedef uint32_t BignumInt;
  45781. +typedef uint64_t BignumDblInt;
  45782. +typedef BignumInt *Bignum;
  45783. +
  45784. +/* Compute modular exponentiaion */
  45785. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  45786. +
  45787. +#ifdef __cplusplus
  45788. +}
  45789. +#endif
  45790. +
  45791. +#endif /* _LINUX_BIGNUM_H */
  45792. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_notifier.c
  45793. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  45794. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-02-07 19:57:30.000000000 +0100
  45795. @@ -0,0 +1,319 @@
  45796. +#ifdef DWC_NOTIFYLIB
  45797. +
  45798. +#include "dwc_notifier.h"
  45799. +#include "dwc_list.h"
  45800. +
  45801. +typedef struct dwc_observer {
  45802. + void *observer;
  45803. + dwc_notifier_callback_t callback;
  45804. + void *data;
  45805. + char *notification;
  45806. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  45807. +} observer_t;
  45808. +
  45809. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  45810. +
  45811. +typedef struct dwc_notifier {
  45812. + void *mem_ctx;
  45813. + void *object;
  45814. + struct observer_queue observers;
  45815. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  45816. +} notifier_t;
  45817. +
  45818. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  45819. +
  45820. +typedef struct manager {
  45821. + void *mem_ctx;
  45822. + void *wkq_ctx;
  45823. + dwc_workq_t *wq;
  45824. +// dwc_mutex_t *mutex;
  45825. + struct notifier_queue notifiers;
  45826. +} manager_t;
  45827. +
  45828. +static manager_t *manager = NULL;
  45829. +
  45830. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  45831. +{
  45832. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  45833. + if (!manager) {
  45834. + return -DWC_E_NO_MEMORY;
  45835. + }
  45836. +
  45837. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  45838. +
  45839. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  45840. + if (!manager->wq) {
  45841. + return -DWC_E_NO_MEMORY;
  45842. + }
  45843. +
  45844. + return 0;
  45845. +}
  45846. +
  45847. +static void free_manager(void)
  45848. +{
  45849. + dwc_workq_free(manager->wq);
  45850. +
  45851. + /* All notifiers must have unregistered themselves before this module
  45852. + * can be removed. Hitting this assertion indicates a programmer
  45853. + * error. */
  45854. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  45855. + "Notification manager being freed before all notifiers have been removed");
  45856. + dwc_free(manager->mem_ctx, manager);
  45857. +}
  45858. +
  45859. +#ifdef DEBUG
  45860. +static void dump_manager(void)
  45861. +{
  45862. + notifier_t *n;
  45863. + observer_t *o;
  45864. +
  45865. + DWC_ASSERT(manager, "Notification manager not found");
  45866. +
  45867. + DWC_DEBUG("List of all notifiers and observers:\n");
  45868. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  45869. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  45870. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  45871. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  45872. + }
  45873. + }
  45874. +}
  45875. +#else
  45876. +#define dump_manager(...)
  45877. +#endif
  45878. +
  45879. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  45880. + dwc_notifier_callback_t callback, void *data)
  45881. +{
  45882. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  45883. +
  45884. + if (!new_observer) {
  45885. + return NULL;
  45886. + }
  45887. +
  45888. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  45889. + new_observer->observer = observer;
  45890. + new_observer->notification = notification;
  45891. + new_observer->callback = callback;
  45892. + new_observer->data = data;
  45893. + return new_observer;
  45894. +}
  45895. +
  45896. +static void free_observer(void *mem_ctx, observer_t *observer)
  45897. +{
  45898. + dwc_free(mem_ctx, observer);
  45899. +}
  45900. +
  45901. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  45902. +{
  45903. + notifier_t *notifier;
  45904. +
  45905. + if (!object) {
  45906. + return NULL;
  45907. + }
  45908. +
  45909. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  45910. + if (!notifier) {
  45911. + return NULL;
  45912. + }
  45913. +
  45914. + DWC_CIRCLEQ_INIT(&notifier->observers);
  45915. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  45916. +
  45917. + notifier->mem_ctx = mem_ctx;
  45918. + notifier->object = object;
  45919. + return notifier;
  45920. +}
  45921. +
  45922. +static void free_notifier(notifier_t *notifier)
  45923. +{
  45924. + observer_t *observer;
  45925. +
  45926. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  45927. + free_observer(notifier->mem_ctx, observer);
  45928. + }
  45929. +
  45930. + dwc_free(notifier->mem_ctx, notifier);
  45931. +}
  45932. +
  45933. +static notifier_t *find_notifier(void *object)
  45934. +{
  45935. + notifier_t *notifier;
  45936. +
  45937. + DWC_ASSERT(manager, "Notification manager not found");
  45938. +
  45939. + if (!object) {
  45940. + return NULL;
  45941. + }
  45942. +
  45943. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  45944. + if (notifier->object == object) {
  45945. + return notifier;
  45946. + }
  45947. + }
  45948. +
  45949. + return NULL;
  45950. +}
  45951. +
  45952. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  45953. +{
  45954. + return create_manager(mem_ctx, wkq_ctx);
  45955. +}
  45956. +
  45957. +void dwc_free_notification_manager(void)
  45958. +{
  45959. + free_manager();
  45960. +}
  45961. +
  45962. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  45963. +{
  45964. + notifier_t *notifier;
  45965. +
  45966. + DWC_ASSERT(manager, "Notification manager not found");
  45967. +
  45968. + notifier = find_notifier(object);
  45969. + if (notifier) {
  45970. + DWC_ERROR("Notifier %p is already registered\n", object);
  45971. + return NULL;
  45972. + }
  45973. +
  45974. + notifier = alloc_notifier(mem_ctx, object);
  45975. + if (!notifier) {
  45976. + return NULL;
  45977. + }
  45978. +
  45979. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  45980. +
  45981. + DWC_INFO("Notifier %p registered", object);
  45982. + dump_manager();
  45983. +
  45984. + return notifier;
  45985. +}
  45986. +
  45987. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  45988. +{
  45989. + DWC_ASSERT(manager, "Notification manager not found");
  45990. +
  45991. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  45992. + observer_t *o;
  45993. +
  45994. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  45995. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  45996. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  45997. + }
  45998. +
  45999. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  46000. + "Notifier %p has active observers when removing", notifier);
  46001. + }
  46002. +
  46003. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  46004. + free_notifier(notifier);
  46005. +
  46006. + DWC_INFO("Notifier unregistered");
  46007. + dump_manager();
  46008. +}
  46009. +
  46010. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  46011. +int dwc_add_observer(void *observer, void *object, char *notification,
  46012. + dwc_notifier_callback_t callback, void *data)
  46013. +{
  46014. + notifier_t *notifier = find_notifier(object);
  46015. + observer_t *new_observer;
  46016. +
  46017. + if (!notifier) {
  46018. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  46019. + return -DWC_E_INVALID;
  46020. + }
  46021. +
  46022. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  46023. + if (!new_observer) {
  46024. + return -DWC_E_NO_MEMORY;
  46025. + }
  46026. +
  46027. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  46028. +
  46029. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  46030. + observer, object, notification, callback, data);
  46031. +
  46032. + dump_manager();
  46033. + return 0;
  46034. +}
  46035. +
  46036. +int dwc_remove_observer(void *observer)
  46037. +{
  46038. + notifier_t *n;
  46039. +
  46040. + DWC_ASSERT(manager, "Notification manager not found");
  46041. +
  46042. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46043. + observer_t *o;
  46044. + observer_t *o2;
  46045. +
  46046. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  46047. + if (o->observer == observer) {
  46048. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  46049. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  46050. + o->observer, n->object, o->notification);
  46051. + free_observer(n->mem_ctx, o);
  46052. + }
  46053. + }
  46054. + }
  46055. +
  46056. + dump_manager();
  46057. + return 0;
  46058. +}
  46059. +
  46060. +typedef struct callback_data {
  46061. + void *mem_ctx;
  46062. + dwc_notifier_callback_t cb;
  46063. + void *observer;
  46064. + void *data;
  46065. + void *object;
  46066. + char *notification;
  46067. + void *notification_data;
  46068. +} cb_data_t;
  46069. +
  46070. +static void cb_task(void *data)
  46071. +{
  46072. + cb_data_t *cb = (cb_data_t *)data;
  46073. +
  46074. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  46075. + dwc_free(cb->mem_ctx, cb);
  46076. +}
  46077. +
  46078. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  46079. +{
  46080. + observer_t *o;
  46081. +
  46082. + DWC_ASSERT(manager, "Notification manager not found");
  46083. +
  46084. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46085. + int len = DWC_STRLEN(notification);
  46086. +
  46087. + if (DWC_STRLEN(o->notification) != len) {
  46088. + continue;
  46089. + }
  46090. +
  46091. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  46092. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  46093. +
  46094. + if (!cb_data) {
  46095. + DWC_ERROR("Failed to allocate callback data\n");
  46096. + return;
  46097. + }
  46098. +
  46099. + cb_data->mem_ctx = notifier->mem_ctx;
  46100. + cb_data->cb = o->callback;
  46101. + cb_data->observer = o->observer;
  46102. + cb_data->data = o->data;
  46103. + cb_data->object = notifier->object;
  46104. + cb_data->notification = notification;
  46105. + cb_data->notification_data = notification_data;
  46106. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  46107. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  46108. + "Notify callback from %p for Notification %s, to observer %p",
  46109. + cb_data->object, notification, cb_data->observer);
  46110. + }
  46111. + }
  46112. +}
  46113. +
  46114. +#endif /* DWC_NOTIFYLIB */
  46115. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_notifier.h
  46116. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  46117. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-02-07 19:57:30.000000000 +0100
  46118. @@ -0,0 +1,122 @@
  46119. +
  46120. +#ifndef __DWC_NOTIFIER_H__
  46121. +#define __DWC_NOTIFIER_H__
  46122. +
  46123. +#ifdef __cplusplus
  46124. +extern "C" {
  46125. +#endif
  46126. +
  46127. +#include "dwc_os.h"
  46128. +
  46129. +/** @file
  46130. + *
  46131. + * A simple implementation of the Observer pattern. Any "module" can
  46132. + * register as an observer or notifier. The notion of "module" is abstract and
  46133. + * can mean anything used to identify either an observer or notifier. Usually
  46134. + * it will be a pointer to a data structure which contains some state, ie an
  46135. + * object.
  46136. + *
  46137. + * Before any notifiers can be added, the global notification manager must be
  46138. + * brought up with dwc_alloc_notification_manager().
  46139. + * dwc_free_notification_manager() will bring it down and free all resources.
  46140. + * These would typically be called upon module load and unload. The
  46141. + * notification manager is a single global instance that handles all registered
  46142. + * observable modules and observers so this should be done only once.
  46143. + *
  46144. + * A module can be observable by using Notifications to publicize some general
  46145. + * information about it's state or operation. It does not care who listens, or
  46146. + * even if anyone listens, or what they do with the information. The observable
  46147. + * modules do not need to know any information about it's observers or their
  46148. + * interface, or their state or data.
  46149. + *
  46150. + * Any module can register to emit Notifications. It should publish a list of
  46151. + * notifications that it can emit and their behavior, such as when they will get
  46152. + * triggered, and what information will be provided to the observer. Then it
  46153. + * should register itself as an observable module. See dwc_register_notifier().
  46154. + *
  46155. + * Any module can observe any observable, registered module, provided it has a
  46156. + * handle to the other module and knows what notifications to observe. See
  46157. + * dwc_add_observer().
  46158. + *
  46159. + * A function of type dwc_notifier_callback_t is called whenever a notification
  46160. + * is triggered with one or more observers observing it. This function is
  46161. + * called in it's own process so it may sleep or block if needed. It is
  46162. + * guaranteed to be called sometime after the notification has occurred and will
  46163. + * be called once per each time the notification is triggered. It will NOT be
  46164. + * called in the same process context used to trigger the notification.
  46165. + *
  46166. + * @section Limitiations
  46167. + *
  46168. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  46169. + * schedule too many processes too handle. Be aware of this limitation when
  46170. + * designing to use notifications, and only add notifications for appropriate
  46171. + * observable information.
  46172. + *
  46173. + * Also Notification callbacks are not synchronous. If you need to synchronize
  46174. + * the behavior between module/observer you must use other means. And perhaps
  46175. + * that will mean Notifications are not the proper solution.
  46176. + */
  46177. +
  46178. +struct dwc_notifier;
  46179. +typedef struct dwc_notifier dwc_notifier_t;
  46180. +
  46181. +/** The callback function must be of this type.
  46182. + *
  46183. + * @param object This is the object that is being observed.
  46184. + * @param notification This is the notification that was triggered.
  46185. + * @param observer This is the observer
  46186. + * @param notification_data This is notification-specific data that the notifier
  46187. + * has included in this notification. The value of this should be published in
  46188. + * the documentation of the observable module with the notifications.
  46189. + * @param user_data This is any custom data that the observer provided when
  46190. + * adding itself as an observer to the notification. */
  46191. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  46192. + void *notification_data, void *user_data);
  46193. +
  46194. +/** Brings up the notification manager. */
  46195. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  46196. +/** Brings down the notification manager. */
  46197. +extern void dwc_free_notification_manager(void);
  46198. +
  46199. +/** This function registers an observable module. A dwc_notifier_t object is
  46200. + * returned to the observable module. This is an opaque object that is used by
  46201. + * the observable module to trigger notifications. This object should only be
  46202. + * accessible to functions that are authorized to trigger notifications for this
  46203. + * module. Observers do not need this object. */
  46204. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  46205. +
  46206. +/** This function unregisters an observable module. All observers have to be
  46207. + * removed prior to unregistration. */
  46208. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  46209. +
  46210. +/** Add a module as an observer to the observable module. The observable module
  46211. + * needs to have previously registered with the notification manager.
  46212. + *
  46213. + * @param observer The observer module
  46214. + * @param object The module to observe
  46215. + * @param notification The notification to observe
  46216. + * @param callback The callback function to call
  46217. + * @param user_data Any additional user data to pass into the callback function */
  46218. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  46219. + dwc_notifier_callback_t callback, void *user_data);
  46220. +
  46221. +/** Removes the specified observer from all notifications that it is currently
  46222. + * observing. */
  46223. +extern int dwc_remove_observer(void *observer);
  46224. +
  46225. +/** This function triggers a Notification. It should be called by the
  46226. + * observable module, or any module or library which the observable module
  46227. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  46228. + *
  46229. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  46230. + * their own process context for each trigger. Callbacks can be blocking.
  46231. + * dwc_notify can be called from interrupt context if needed.
  46232. + *
  46233. + */
  46234. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  46235. +
  46236. +#ifdef __cplusplus
  46237. +}
  46238. +#endif
  46239. +
  46240. +#endif /* __DWC_NOTIFIER_H__ */
  46241. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_os.h linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_os.h
  46242. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  46243. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/dwc_os.h 2014-02-07 19:57:30.000000000 +0100
  46244. @@ -0,0 +1,1262 @@
  46245. +/* =========================================================================
  46246. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  46247. + * $Revision: #14 $
  46248. + * $Date: 2010/11/04 $
  46249. + * $Change: 1621695 $
  46250. + *
  46251. + * Synopsys Portability Library Software and documentation
  46252. + * (hereinafter, "Software") is an Unsupported proprietary work of
  46253. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  46254. + * between Synopsys and you.
  46255. + *
  46256. + * The Software IS NOT an item of Licensed Software or Licensed Product
  46257. + * under any End User Software License Agreement or Agreement for
  46258. + * Licensed Product with Synopsys or any supplement thereto. You are
  46259. + * permitted to use and redistribute this Software in source and binary
  46260. + * forms, with or without modification, provided that redistributions
  46261. + * of source code must retain this notice. You may not view, use,
  46262. + * disclose, copy or distribute this file or any information contained
  46263. + * herein except pursuant to this license grant from Synopsys. If you
  46264. + * do not agree with this notice, including the disclaimer below, then
  46265. + * you are not authorized to use the Software.
  46266. + *
  46267. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  46268. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46269. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  46270. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  46271. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46272. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46273. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46274. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  46275. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  46276. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  46277. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  46278. + * DAMAGE.
  46279. + * ========================================================================= */
  46280. +#ifndef _DWC_OS_H_
  46281. +#define _DWC_OS_H_
  46282. +
  46283. +#ifdef __cplusplus
  46284. +extern "C" {
  46285. +#endif
  46286. +
  46287. +/** @file
  46288. + *
  46289. + * DWC portability library, low level os-wrapper functions
  46290. + *
  46291. + */
  46292. +
  46293. +/* These basic types need to be defined by some OS header file or custom header
  46294. + * file for your specific target architecture.
  46295. + *
  46296. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  46297. + *
  46298. + * Any custom or alternate header file must be added and enabled here.
  46299. + */
  46300. +
  46301. +#ifdef DWC_LINUX
  46302. +# include <linux/types.h>
  46303. +# ifdef CONFIG_DEBUG_MUTEXES
  46304. +# include <linux/mutex.h>
  46305. +# endif
  46306. +# include <linux/errno.h>
  46307. +# include <stdarg.h>
  46308. +#endif
  46309. +
  46310. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46311. +# include <os_dep.h>
  46312. +#endif
  46313. +
  46314. +
  46315. +/** @name Primitive Types and Values */
  46316. +
  46317. +/** We define a boolean type for consistency. Can be either YES or NO */
  46318. +typedef uint8_t dwc_bool_t;
  46319. +#define YES 1
  46320. +#define NO 0
  46321. +
  46322. +#ifdef DWC_LINUX
  46323. +
  46324. +/** @name Error Codes */
  46325. +#define DWC_E_INVALID EINVAL
  46326. +#define DWC_E_NO_MEMORY ENOMEM
  46327. +#define DWC_E_NO_DEVICE ENODEV
  46328. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  46329. +#define DWC_E_TIMEOUT ETIMEDOUT
  46330. +#define DWC_E_BUSY EBUSY
  46331. +#define DWC_E_AGAIN EAGAIN
  46332. +#define DWC_E_RESTART ERESTART
  46333. +#define DWC_E_ABORT ECONNABORTED
  46334. +#define DWC_E_SHUTDOWN ESHUTDOWN
  46335. +#define DWC_E_NO_DATA ENODATA
  46336. +#define DWC_E_DISCONNECT ECONNRESET
  46337. +#define DWC_E_UNKNOWN EINVAL
  46338. +#define DWC_E_NO_STREAM_RES ENOSR
  46339. +#define DWC_E_COMMUNICATION ECOMM
  46340. +#define DWC_E_OVERFLOW EOVERFLOW
  46341. +#define DWC_E_PROTOCOL EPROTO
  46342. +#define DWC_E_IN_PROGRESS EINPROGRESS
  46343. +#define DWC_E_PIPE EPIPE
  46344. +#define DWC_E_IO EIO
  46345. +#define DWC_E_NO_SPACE ENOSPC
  46346. +
  46347. +#else
  46348. +
  46349. +/** @name Error Codes */
  46350. +#define DWC_E_INVALID 1001
  46351. +#define DWC_E_NO_MEMORY 1002
  46352. +#define DWC_E_NO_DEVICE 1003
  46353. +#define DWC_E_NOT_SUPPORTED 1004
  46354. +#define DWC_E_TIMEOUT 1005
  46355. +#define DWC_E_BUSY 1006
  46356. +#define DWC_E_AGAIN 1007
  46357. +#define DWC_E_RESTART 1008
  46358. +#define DWC_E_ABORT 1009
  46359. +#define DWC_E_SHUTDOWN 1010
  46360. +#define DWC_E_NO_DATA 1011
  46361. +#define DWC_E_DISCONNECT 2000
  46362. +#define DWC_E_UNKNOWN 3000
  46363. +#define DWC_E_NO_STREAM_RES 4001
  46364. +#define DWC_E_COMMUNICATION 4002
  46365. +#define DWC_E_OVERFLOW 4003
  46366. +#define DWC_E_PROTOCOL 4004
  46367. +#define DWC_E_IN_PROGRESS 4005
  46368. +#define DWC_E_PIPE 4006
  46369. +#define DWC_E_IO 4007
  46370. +#define DWC_E_NO_SPACE 4008
  46371. +
  46372. +#endif
  46373. +
  46374. +
  46375. +/** @name Tracing/Logging Functions
  46376. + *
  46377. + * These function provide the capability to add tracing, debugging, and error
  46378. + * messages, as well exceptions as assertions. The WUDEV uses these
  46379. + * extensively. These could be logged to the main console, the serial port, an
  46380. + * internal buffer, etc. These functions could also be no-op if they are too
  46381. + * expensive on your system. By default undefining the DEBUG macro already
  46382. + * no-ops some of these functions. */
  46383. +
  46384. +/** Returns non-zero if in interrupt context. */
  46385. +extern dwc_bool_t DWC_IN_IRQ(void);
  46386. +#define dwc_in_irq DWC_IN_IRQ
  46387. +
  46388. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  46389. +static inline char *dwc_irq(void) {
  46390. + return DWC_IN_IRQ() ? "IRQ" : "";
  46391. +}
  46392. +
  46393. +/** Returns non-zero if in bottom-half context. */
  46394. +extern dwc_bool_t DWC_IN_BH(void);
  46395. +#define dwc_in_bh DWC_IN_BH
  46396. +
  46397. +/** Returns "BH" if DWC_IN_BH is true. */
  46398. +static inline char *dwc_bh(void) {
  46399. + return DWC_IN_BH() ? "BH" : "";
  46400. +}
  46401. +
  46402. +/**
  46403. + * A vprintf() clone. Just call vprintf if you've got it.
  46404. + */
  46405. +extern void DWC_VPRINTF(char *format, va_list args);
  46406. +#define dwc_vprintf DWC_VPRINTF
  46407. +
  46408. +/**
  46409. + * A vsnprintf() clone. Just call vprintf if you've got it.
  46410. + */
  46411. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  46412. +#define dwc_vsnprintf DWC_VSNPRINTF
  46413. +
  46414. +/**
  46415. + * printf() clone. Just call printf if you've go it.
  46416. + */
  46417. +extern void DWC_PRINTF(char *format, ...)
  46418. +/* This provides compiler level static checking of the parameters if you're
  46419. + * using GCC. */
  46420. +#ifdef __GNUC__
  46421. + __attribute__ ((format(printf, 1, 2)));
  46422. +#else
  46423. + ;
  46424. +#endif
  46425. +#define dwc_printf DWC_PRINTF
  46426. +
  46427. +/**
  46428. + * sprintf() clone. Just call sprintf if you've got it.
  46429. + */
  46430. +extern int DWC_SPRINTF(char *string, char *format, ...)
  46431. +#ifdef __GNUC__
  46432. + __attribute__ ((format(printf, 2, 3)));
  46433. +#else
  46434. + ;
  46435. +#endif
  46436. +#define dwc_sprintf DWC_SPRINTF
  46437. +
  46438. +/**
  46439. + * snprintf() clone. Just call snprintf if you've got it.
  46440. + */
  46441. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  46442. +#ifdef __GNUC__
  46443. + __attribute__ ((format(printf, 3, 4)));
  46444. +#else
  46445. + ;
  46446. +#endif
  46447. +#define dwc_snprintf DWC_SNPRINTF
  46448. +
  46449. +/**
  46450. + * Prints a WARNING message. On systems that don't differentiate between
  46451. + * warnings and regular log messages, just print it. Indicates that something
  46452. + * may be wrong with the driver. Works like printf().
  46453. + *
  46454. + * Use the DWC_WARN macro to call this function.
  46455. + */
  46456. +extern void __DWC_WARN(char *format, ...)
  46457. +#ifdef __GNUC__
  46458. + __attribute__ ((format(printf, 1, 2)));
  46459. +#else
  46460. + ;
  46461. +#endif
  46462. +
  46463. +/**
  46464. + * Prints an error message. On systems that don't differentiate between errors
  46465. + * and regular log messages, just print it. Indicates that something went wrong
  46466. + * with the driver. Works like printf().
  46467. + *
  46468. + * Use the DWC_ERROR macro to call this function.
  46469. + */
  46470. +extern void __DWC_ERROR(char *format, ...)
  46471. +#ifdef __GNUC__
  46472. + __attribute__ ((format(printf, 1, 2)));
  46473. +#else
  46474. + ;
  46475. +#endif
  46476. +
  46477. +/**
  46478. + * Prints an exception error message and takes some user-defined action such as
  46479. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  46480. + * abnormally wrong with the driver such as programmer error, or other
  46481. + * exceptional condition. It should not be ignored so even on systems without
  46482. + * printing capability, some action should be taken to notify the developer of
  46483. + * it. Works like printf().
  46484. + */
  46485. +extern void DWC_EXCEPTION(char *format, ...)
  46486. +#ifdef __GNUC__
  46487. + __attribute__ ((format(printf, 1, 2)));
  46488. +#else
  46489. + ;
  46490. +#endif
  46491. +#define dwc_exception DWC_EXCEPTION
  46492. +
  46493. +#ifndef DWC_OTG_DEBUG_LEV
  46494. +#define DWC_OTG_DEBUG_LEV 0
  46495. +#endif
  46496. +
  46497. +#ifdef DEBUG
  46498. +/**
  46499. + * Prints out a debug message. Used for logging/trace messages.
  46500. + *
  46501. + * Use the DWC_DEBUG macro to call this function
  46502. + */
  46503. +extern void __DWC_DEBUG(char *format, ...)
  46504. +#ifdef __GNUC__
  46505. + __attribute__ ((format(printf, 1, 2)));
  46506. +#else
  46507. + ;
  46508. +#endif
  46509. +#else
  46510. +#define __DWC_DEBUG printk
  46511. +#endif
  46512. +
  46513. +/**
  46514. + * Prints out a Debug message.
  46515. + */
  46516. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  46517. + __func__, dwc_irq(), ## _args)
  46518. +#define dwc_debug DWC_DEBUG
  46519. +/**
  46520. + * Prints out a Debug message if enabled at compile time.
  46521. + */
  46522. +#if DWC_OTG_DEBUG_LEV > 0
  46523. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  46524. +#else
  46525. +#define DWC_DEBUGC(_format, _args...)
  46526. +#endif
  46527. +#define dwc_debugc DWC_DEBUGC
  46528. +/**
  46529. + * Prints out an informative message.
  46530. + */
  46531. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  46532. + dwc_irq(), ## _args)
  46533. +#define dwc_info DWC_INFO
  46534. +/**
  46535. + * Prints out an informative message if enabled at compile time.
  46536. + */
  46537. +#if DWC_OTG_DEBUG_LEV > 1
  46538. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  46539. +#else
  46540. +#define DWC_INFOC(_format, _args...)
  46541. +#endif
  46542. +#define dwc_infoc DWC_INFOC
  46543. +/**
  46544. + * Prints out a warning message.
  46545. + */
  46546. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  46547. + dwc_irq(), __func__, __LINE__, ## _args)
  46548. +#define dwc_warn DWC_WARN
  46549. +/**
  46550. + * Prints out an error message.
  46551. + */
  46552. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  46553. + dwc_irq(), __func__, __LINE__, ## _args)
  46554. +#define dwc_error DWC_ERROR
  46555. +
  46556. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  46557. + dwc_irq(), __func__, __LINE__, ## _args)
  46558. +#define dwc_proto_error DWC_PROTO_ERROR
  46559. +
  46560. +#ifdef DEBUG
  46561. +/** Prints out a exception error message if the _expr expression fails. Disabled
  46562. + * if DEBUG is not enabled. */
  46563. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  46564. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  46565. + __FILE__, __LINE__, ## _args); } \
  46566. + } while (0)
  46567. +#else
  46568. +#define DWC_ASSERT(_x...)
  46569. +#endif
  46570. +#define dwc_assert DWC_ASSERT
  46571. +
  46572. +
  46573. +/** @name Byte Ordering
  46574. + * The following functions are for conversions between processor's byte ordering
  46575. + * and specific ordering you want.
  46576. + */
  46577. +
  46578. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  46579. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  46580. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  46581. +
  46582. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  46583. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  46584. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  46585. +
  46586. +/** Converts 32 bit little endian data to CPU byte ordering. */
  46587. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  46588. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  46589. +
  46590. +/** Converts 32 bit big endian data to CPU byte ordering. */
  46591. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  46592. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  46593. +
  46594. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  46595. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  46596. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  46597. +
  46598. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  46599. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  46600. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  46601. +
  46602. +/** Converts 16 bit little endian data to CPU byte ordering. */
  46603. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  46604. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  46605. +
  46606. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  46607. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  46608. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  46609. +
  46610. +
  46611. +/** @name Register Read/Write
  46612. + *
  46613. + * The following six functions should be implemented to read/write registers of
  46614. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  46615. + * The reg value is a pointer to the register calculated from the void *base
  46616. + * variable passed into the driver when it is started. */
  46617. +
  46618. +#ifdef DWC_LINUX
  46619. +/* Linux doesn't need any extra parameters for register read/write, so we
  46620. + * just throw away the IO context parameter.
  46621. + */
  46622. +/** Reads the content of a 32-bit register. */
  46623. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  46624. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  46625. +
  46626. +/** Reads the content of a 64-bit register. */
  46627. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  46628. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  46629. +
  46630. +/** Writes to a 32-bit register. */
  46631. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  46632. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  46633. +
  46634. +/** Writes to a 64-bit register. */
  46635. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  46636. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  46637. +
  46638. +/**
  46639. + * Modify bit values in a register. Using the
  46640. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46641. + */
  46642. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46643. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  46644. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46645. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  46646. +
  46647. +#endif /* DWC_LINUX */
  46648. +
  46649. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46650. +typedef struct dwc_ioctx {
  46651. + struct device *dev;
  46652. + bus_space_tag_t iot;
  46653. + bus_space_handle_t ioh;
  46654. +} dwc_ioctx_t;
  46655. +
  46656. +/** BSD needs two extra parameters for register read/write, so we pass
  46657. + * them in using the IO context parameter.
  46658. + */
  46659. +/** Reads the content of a 32-bit register. */
  46660. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  46661. +#define dwc_read_reg32 DWC_READ_REG32
  46662. +
  46663. +/** Reads the content of a 64-bit register. */
  46664. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  46665. +#define dwc_read_reg64 DWC_READ_REG64
  46666. +
  46667. +/** Writes to a 32-bit register. */
  46668. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  46669. +#define dwc_write_reg32 DWC_WRITE_REG32
  46670. +
  46671. +/** Writes to a 64-bit register. */
  46672. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  46673. +#define dwc_write_reg64 DWC_WRITE_REG64
  46674. +
  46675. +/**
  46676. + * Modify bit values in a register. Using the
  46677. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46678. + */
  46679. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46680. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  46681. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46682. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  46683. +
  46684. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46685. +
  46686. +/** @cond */
  46687. +
  46688. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  46689. + * register writes. */
  46690. +
  46691. +#ifdef DWC_LINUX
  46692. +
  46693. +# ifdef DWC_DEBUG_REGS
  46694. +
  46695. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46696. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46697. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46698. +} \
  46699. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46700. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46701. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46702. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46703. +}
  46704. +
  46705. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46706. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46707. + return DWC_READ_REG32(&container->regs->_reg); \
  46708. +} \
  46709. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46710. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46711. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46712. +}
  46713. +
  46714. +# else /* DWC_DEBUG_REGS */
  46715. +
  46716. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46717. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46718. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46719. +} \
  46720. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46721. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46722. +}
  46723. +
  46724. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46725. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46726. + return DWC_READ_REG32(&container->regs->_reg); \
  46727. +} \
  46728. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46729. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46730. +}
  46731. +
  46732. +# endif /* DWC_DEBUG_REGS */
  46733. +
  46734. +#endif /* DWC_LINUX */
  46735. +
  46736. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46737. +
  46738. +# ifdef DWC_DEBUG_REGS
  46739. +
  46740. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46741. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46742. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46743. +} \
  46744. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46745. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46746. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46747. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46748. +}
  46749. +
  46750. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46751. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46752. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46753. +} \
  46754. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46755. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46756. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46757. +}
  46758. +
  46759. +# else /* DWC_DEBUG_REGS */
  46760. +
  46761. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46762. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46763. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46764. +} \
  46765. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46766. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46767. +}
  46768. +
  46769. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46770. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46771. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46772. +} \
  46773. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46774. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46775. +}
  46776. +
  46777. +# endif /* DWC_DEBUG_REGS */
  46778. +
  46779. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46780. +
  46781. +/** @endcond */
  46782. +
  46783. +
  46784. +#ifdef DWC_CRYPTOLIB
  46785. +/** @name Crypto Functions
  46786. + *
  46787. + * These are the low-level cryptographic functions used by the driver. */
  46788. +
  46789. +/** Perform AES CBC */
  46790. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  46791. +#define dwc_aes_cbc DWC_AES_CBC
  46792. +
  46793. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  46794. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  46795. +#define dwc_random_bytes DWC_RANDOM_BYTES
  46796. +
  46797. +/** Perform the SHA-256 hash function */
  46798. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  46799. +#define dwc_sha256 DWC_SHA256
  46800. +
  46801. +/** Calculated the HMAC-SHA256 */
  46802. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  46803. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  46804. +
  46805. +#endif /* DWC_CRYPTOLIB */
  46806. +
  46807. +
  46808. +/** @name Memory Allocation
  46809. + *
  46810. + * These function provide access to memory allocation. There are only 2 DMA
  46811. + * functions and 3 Regular memory functions that need to be implemented. None
  46812. + * of the memory debugging routines need to be implemented. The allocation
  46813. + * routines all ZERO the contents of the memory.
  46814. + *
  46815. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  46816. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  46817. + * keeps track of how much memory the driver is using at any given time. */
  46818. +
  46819. +#define DWC_PAGE_SIZE 4096
  46820. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  46821. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  46822. +
  46823. +#define DWC_INVALID_DMA_ADDR 0x0
  46824. +
  46825. +#ifdef DWC_LINUX
  46826. +/** Type for a DMA address */
  46827. +typedef dma_addr_t dwc_dma_t;
  46828. +#endif
  46829. +
  46830. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46831. +typedef bus_addr_t dwc_dma_t;
  46832. +#endif
  46833. +
  46834. +#ifdef DWC_FREEBSD
  46835. +typedef struct dwc_dmactx {
  46836. + struct device *dev;
  46837. + bus_dma_tag_t dma_tag;
  46838. + bus_dmamap_t dma_map;
  46839. + bus_addr_t dma_paddr;
  46840. + void *dma_vaddr;
  46841. +} dwc_dmactx_t;
  46842. +#endif
  46843. +
  46844. +#ifdef DWC_NETBSD
  46845. +typedef struct dwc_dmactx {
  46846. + struct device *dev;
  46847. + bus_dma_tag_t dma_tag;
  46848. + bus_dmamap_t dma_map;
  46849. + bus_dma_segment_t segs[1];
  46850. + int nsegs;
  46851. + bus_addr_t dma_paddr;
  46852. + void *dma_vaddr;
  46853. +} dwc_dmactx_t;
  46854. +#endif
  46855. +
  46856. +/* @todo these functions will be added in the future */
  46857. +#if 0
  46858. +/**
  46859. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  46860. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  46861. + * boundary requirements specified.
  46862. + *
  46863. + * @param[in] size Specifies the size of the buffers that will be allocated from
  46864. + * this pool.
  46865. + * @param[in] align Specifies the byte alignment requirements of the buffers
  46866. + * allocated from this pool. Must be a power of 2.
  46867. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  46868. + * this pool must not cross.
  46869. + *
  46870. + * @returns A pointer to an internal opaque structure which is not to be
  46871. + * accessed outside of these library functions. Use this handle to specify
  46872. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  46873. + * when you are done with it.
  46874. + */
  46875. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  46876. +
  46877. +/**
  46878. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  46879. + */
  46880. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  46881. +
  46882. +/**
  46883. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  46884. + */
  46885. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  46886. +
  46887. +/**
  46888. + * Free a previously allocated buffer from the DMA pool.
  46889. + */
  46890. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  46891. +#endif
  46892. +
  46893. +/** Allocates a DMA capable buffer and zeroes its contents. */
  46894. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46895. +
  46896. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  46897. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46898. +
  46899. +/** Frees a previously allocated buffer. */
  46900. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  46901. +
  46902. +/** Allocates a block of memory and zeroes its contents. */
  46903. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  46904. +
  46905. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  46906. + * which can be used inside interrupt context. The size should be sufficiently
  46907. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  46908. + * __DWC_ALLOC if it is atomic. */
  46909. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  46910. +
  46911. +/** Frees a previously allocated buffer. */
  46912. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  46913. +
  46914. +#ifndef DWC_DEBUG_MEMORY
  46915. +
  46916. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  46917. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  46918. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  46919. +
  46920. +# ifdef DWC_LINUX
  46921. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  46922. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  46923. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  46924. +# endif
  46925. +
  46926. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46927. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  46928. +#define DWC_DMA_FREE __DWC_DMA_FREE
  46929. +# endif
  46930. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  46931. +
  46932. +#else /* DWC_DEBUG_MEMORY */
  46933. +
  46934. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46935. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46936. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  46937. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46938. + char const *func, int line);
  46939. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46940. + char const *func, int line);
  46941. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46942. + dwc_dma_t dma_addr, char const *func, int line);
  46943. +
  46944. +extern int dwc_memory_debug_start(void *mem_ctx);
  46945. +extern void dwc_memory_debug_stop(void);
  46946. +extern void dwc_memory_debug_report(void);
  46947. +
  46948. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  46949. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  46950. + __func__, __LINE__)
  46951. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  46952. +
  46953. +# ifdef DWC_LINUX
  46954. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  46955. + _dma_, __func__, __LINE__)
  46956. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  46957. + _dma_, __func__, __LINE__)
  46958. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  46959. + _virt_, _dma_, __func__, __LINE__)
  46960. +# endif
  46961. +
  46962. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46963. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  46964. + _dma_, __func__, __LINE__)
  46965. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  46966. + _virt_, _dma_, __func__, __LINE__)
  46967. +# endif
  46968. +
  46969. +#endif /* DWC_DEBUG_MEMORY */
  46970. +
  46971. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  46972. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  46973. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  46974. +
  46975. +#ifdef DWC_LINUX
  46976. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  46977. + * just throw away the DMA context parameter.
  46978. + */
  46979. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  46980. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  46981. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  46982. +#endif
  46983. +
  46984. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46985. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  46986. + * them in using the DMA context parameter.
  46987. + */
  46988. +#define dwc_dma_alloc DWC_DMA_ALLOC
  46989. +#define dwc_dma_free DWC_DMA_FREE
  46990. +#endif
  46991. +
  46992. +
  46993. +/** @name Memory and String Processing */
  46994. +
  46995. +/** memset() clone */
  46996. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  46997. +#define dwc_memset DWC_MEMSET
  46998. +
  46999. +/** memcpy() clone */
  47000. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  47001. +#define dwc_memcpy DWC_MEMCPY
  47002. +
  47003. +/** memmove() clone */
  47004. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  47005. +#define dwc_memmove DWC_MEMMOVE
  47006. +
  47007. +/** memcmp() clone */
  47008. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  47009. +#define dwc_memcmp DWC_MEMCMP
  47010. +
  47011. +/** strcmp() clone */
  47012. +extern int DWC_STRCMP(void *s1, void *s2);
  47013. +#define dwc_strcmp DWC_STRCMP
  47014. +
  47015. +/** strncmp() clone */
  47016. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  47017. +#define dwc_strncmp DWC_STRNCMP
  47018. +
  47019. +/** strlen() clone, for NULL terminated ASCII strings */
  47020. +extern int DWC_STRLEN(char const *str);
  47021. +#define dwc_strlen DWC_STRLEN
  47022. +
  47023. +/** strcpy() clone, for NULL terminated ASCII strings */
  47024. +extern char *DWC_STRCPY(char *to, const char *from);
  47025. +#define dwc_strcpy DWC_STRCPY
  47026. +
  47027. +/** strdup() clone. If you wish to use memory allocation debugging, this
  47028. + * implementation of strdup should use the DWC_* memory routines instead of
  47029. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  47030. + * will not be seen by the debugging routines. */
  47031. +extern char *DWC_STRDUP(char const *str);
  47032. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  47033. +
  47034. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  47035. + * converted from the string str in base 10 unless the string begins with a "0x"
  47036. + * in which case it is base 16. String must be a NULL terminated sequence of
  47037. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  47038. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  47039. + * the number and end with a NULL character. If any invalid characters are
  47040. + * encountered or it returns with a negative error code and the results of the
  47041. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  47042. + * undefined. An example implementation using atoi() can be referenced from the
  47043. + * Linux implementation. */
  47044. +extern int DWC_ATOI(const char *str, int32_t *value);
  47045. +#define dwc_atoi DWC_ATOI
  47046. +
  47047. +/** Same as above but for unsigned. */
  47048. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  47049. +#define dwc_atoui DWC_ATOUI
  47050. +
  47051. +#ifdef DWC_UTFLIB
  47052. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  47053. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  47054. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  47055. +#endif
  47056. +
  47057. +
  47058. +/** @name Wait queues
  47059. + *
  47060. + * Wait queues provide a means of synchronizing between threads or processes. A
  47061. + * process can block on a waitq if some condition is not true, waiting for it to
  47062. + * become true. When the waitq is triggered all waiting process will get
  47063. + * unblocked and the condition will be check again. Waitqs should be triggered
  47064. + * every time a condition can potentially change.*/
  47065. +struct dwc_waitq;
  47066. +
  47067. +/** Type for a waitq */
  47068. +typedef struct dwc_waitq dwc_waitq_t;
  47069. +
  47070. +/** The type of waitq condition callback function. This is called every time
  47071. + * condition is evaluated. */
  47072. +typedef int (*dwc_waitq_condition_t)(void *data);
  47073. +
  47074. +/** Allocate a waitq */
  47075. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  47076. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  47077. +
  47078. +/** Free a waitq */
  47079. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  47080. +#define dwc_waitq_free DWC_WAITQ_FREE
  47081. +
  47082. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  47083. + * condition again. The function returns when the condition becomes true. The return value
  47084. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  47085. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  47086. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  47087. +
  47088. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  47089. + * check the condition again. The function returns when the condition become
  47090. + * true or the timeout has passed. The return value is 0 on condition true or
  47091. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  47092. + * error. */
  47093. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  47094. + void *data, int32_t msecs);
  47095. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  47096. +
  47097. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  47098. + * has potentially changed. */
  47099. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  47100. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  47101. +
  47102. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  47103. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  47104. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  47105. +
  47106. +
  47107. +/** @name Threads
  47108. + *
  47109. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  47110. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  47111. + * returns the value from the thread.
  47112. + */
  47113. +
  47114. +struct dwc_thread;
  47115. +
  47116. +/** Type for a thread */
  47117. +typedef struct dwc_thread dwc_thread_t;
  47118. +
  47119. +/** The thread function */
  47120. +typedef int (*dwc_thread_function_t)(void *data);
  47121. +
  47122. +/** Create a thread and start it running the thread_function. Returns a handle
  47123. + * to the thread */
  47124. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  47125. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  47126. +
  47127. +/** Stops a thread. Return the value returned by the thread. Or will return
  47128. + * DWC_ABORT if the thread never started. */
  47129. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  47130. +#define dwc_thread_stop DWC_THREAD_STOP
  47131. +
  47132. +/** Signifies to the thread that it must stop. */
  47133. +#ifdef DWC_LINUX
  47134. +/* Linux doesn't need any parameters for kthread_should_stop() */
  47135. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  47136. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  47137. +
  47138. +/* No thread_exit function in Linux */
  47139. +#define dwc_thread_exit(_thrd_)
  47140. +#endif
  47141. +
  47142. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47143. +/** BSD needs the thread pointer for kthread_suspend_check() */
  47144. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  47145. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  47146. +
  47147. +/** The thread must call this to exit. */
  47148. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  47149. +#define dwc_thread_exit DWC_THREAD_EXIT
  47150. +#endif
  47151. +
  47152. +
  47153. +/** @name Work queues
  47154. + *
  47155. + * Workqs are used to queue a callback function to be called at some later time,
  47156. + * in another thread. */
  47157. +struct dwc_workq;
  47158. +
  47159. +/** Type for a workq */
  47160. +typedef struct dwc_workq dwc_workq_t;
  47161. +
  47162. +/** The type of the callback function to be called. */
  47163. +typedef void (*dwc_work_callback_t)(void *data);
  47164. +
  47165. +/** Allocate a workq */
  47166. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  47167. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  47168. +
  47169. +/** Free a workq. All work must be completed before being freed. */
  47170. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  47171. +#define dwc_workq_free DWC_WORKQ_FREE
  47172. +
  47173. +/** Schedule a callback on the workq, passing in data. The function will be
  47174. + * scheduled at some later time. */
  47175. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  47176. + void *data, char *format, ...)
  47177. +#ifdef __GNUC__
  47178. + __attribute__ ((format(printf, 4, 5)));
  47179. +#else
  47180. + ;
  47181. +#endif
  47182. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  47183. +
  47184. +/** Schedule a callback on the workq, that will be called until at least
  47185. + * given number miliseconds have passed. */
  47186. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  47187. + void *data, uint32_t time, char *format, ...)
  47188. +#ifdef __GNUC__
  47189. + __attribute__ ((format(printf, 5, 6)));
  47190. +#else
  47191. + ;
  47192. +#endif
  47193. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  47194. +
  47195. +/** The number of processes in the workq */
  47196. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  47197. +#define dwc_workq_pending DWC_WORKQ_PENDING
  47198. +
  47199. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  47200. + * 0 on timeout. */
  47201. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  47202. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  47203. +
  47204. +
  47205. +/** @name Tasklets
  47206. + *
  47207. + */
  47208. +struct dwc_tasklet;
  47209. +
  47210. +/** Type for a tasklet */
  47211. +typedef struct dwc_tasklet dwc_tasklet_t;
  47212. +
  47213. +/** The type of the callback function to be called */
  47214. +typedef void (*dwc_tasklet_callback_t)(void *data);
  47215. +
  47216. +/** Allocates a tasklet */
  47217. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  47218. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  47219. +
  47220. +/** Frees a tasklet */
  47221. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  47222. +#define dwc_task_free DWC_TASK_FREE
  47223. +
  47224. +/** Schedules a tasklet to run */
  47225. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  47226. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  47227. +
  47228. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  47229. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  47230. +
  47231. +/** @name Timer
  47232. + *
  47233. + * Callbacks must be small and atomic.
  47234. + */
  47235. +struct dwc_timer;
  47236. +
  47237. +/** Type for a timer */
  47238. +typedef struct dwc_timer dwc_timer_t;
  47239. +
  47240. +/** The type of the callback function to be called */
  47241. +typedef void (*dwc_timer_callback_t)(void *data);
  47242. +
  47243. +/** Allocates a timer */
  47244. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  47245. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  47246. +
  47247. +/** Frees a timer */
  47248. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  47249. +#define dwc_timer_free DWC_TIMER_FREE
  47250. +
  47251. +/** Schedules the timer to run at time ms from now. And will repeat at every
  47252. + * repeat_interval msec therafter
  47253. + *
  47254. + * Modifies a timer that is still awaiting execution to a new expiration time.
  47255. + * The mod_time is added to the old time. */
  47256. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  47257. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  47258. +
  47259. +/** Disables the timer from execution. */
  47260. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  47261. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  47262. +
  47263. +
  47264. +/** @name Spinlocks
  47265. + *
  47266. + * These locks are used when the work between the lock/unlock is atomic and
  47267. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  47268. + * suitable to lock between interrupt/non-interrupt context. They also lock
  47269. + * between processes if you have multiple CPUs or Preemption. If you don't have
  47270. + * multiple CPUS or Preemption, then the you can simply implement the
  47271. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  47272. + * the work between the lock/unlock is atomic, the process context will never
  47273. + * change, and so you never have to lock between processes. */
  47274. +
  47275. +struct dwc_spinlock;
  47276. +
  47277. +/** Type for a spinlock */
  47278. +typedef struct dwc_spinlock dwc_spinlock_t;
  47279. +
  47280. +/** Type for the 'flags' argument to spinlock funtions */
  47281. +typedef unsigned long dwc_irqflags_t;
  47282. +
  47283. +/** Returns an initialized lock variable. This function should allocate and
  47284. + * initialize the OS-specific data structure used for locking. This data
  47285. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  47286. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  47287. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  47288. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  47289. +
  47290. +/** Frees an initialized lock variable. */
  47291. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  47292. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  47293. +
  47294. +/** Disables interrupts and blocks until it acquires the lock.
  47295. + *
  47296. + * @param lock Pointer to the spinlock.
  47297. + * @param flags Unsigned long for irq flags storage.
  47298. + */
  47299. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  47300. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  47301. +
  47302. +/** Re-enables the interrupt and releases the lock.
  47303. + *
  47304. + * @param lock Pointer to the spinlock.
  47305. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  47306. + * passed into DWC_LOCK.
  47307. + */
  47308. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  47309. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  47310. +
  47311. +/** Blocks until it acquires the lock.
  47312. + *
  47313. + * @param lock Pointer to the spinlock.
  47314. + */
  47315. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  47316. +#define dwc_spinlock DWC_SPINLOCK
  47317. +
  47318. +/** Releases the lock.
  47319. + *
  47320. + * @param lock Pointer to the spinlock.
  47321. + */
  47322. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  47323. +#define dwc_spinunlock DWC_SPINUNLOCK
  47324. +
  47325. +
  47326. +/** @name Mutexes
  47327. + *
  47328. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  47329. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  47330. + */
  47331. +
  47332. +struct dwc_mutex;
  47333. +
  47334. +/** Type for a mutex */
  47335. +typedef struct dwc_mutex dwc_mutex_t;
  47336. +
  47337. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  47338. + * the symbol to determine recursive locking. This makes it falsely think
  47339. + * recursive locking occurs. */
  47340. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47341. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  47342. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  47343. + mutex_init((struct mutex *)__mutexp); \
  47344. +})
  47345. +#endif
  47346. +
  47347. +/** Allocate a mutex */
  47348. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  47349. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  47350. +
  47351. +/* For memory leak debugging when using Linux Mutex Debugging */
  47352. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47353. +#define DWC_MUTEX_FREE(__mutexp) do { \
  47354. + mutex_destroy((struct mutex *)__mutexp); \
  47355. + DWC_FREE(__mutexp); \
  47356. +} while(0)
  47357. +#else
  47358. +/** Free a mutex */
  47359. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  47360. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  47361. +#endif
  47362. +
  47363. +/** Lock a mutex */
  47364. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  47365. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  47366. +
  47367. +/** Non-blocking lock returns 1 on successful lock. */
  47368. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  47369. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  47370. +
  47371. +/** Unlock a mutex */
  47372. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  47373. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  47374. +
  47375. +
  47376. +/** @name Time */
  47377. +
  47378. +/** Microsecond delay.
  47379. + *
  47380. + * @param usecs Microseconds to delay.
  47381. + */
  47382. +extern void DWC_UDELAY(uint32_t usecs);
  47383. +#define dwc_udelay DWC_UDELAY
  47384. +
  47385. +/** Millisecond delay.
  47386. + *
  47387. + * @param msecs Milliseconds to delay.
  47388. + */
  47389. +extern void DWC_MDELAY(uint32_t msecs);
  47390. +#define dwc_mdelay DWC_MDELAY
  47391. +
  47392. +/** Non-busy waiting.
  47393. + * Sleeps for specified number of milliseconds.
  47394. + *
  47395. + * @param msecs Milliseconds to sleep.
  47396. + */
  47397. +extern void DWC_MSLEEP(uint32_t msecs);
  47398. +#define dwc_msleep DWC_MSLEEP
  47399. +
  47400. +/**
  47401. + * Returns number of milliseconds since boot.
  47402. + */
  47403. +extern uint32_t DWC_TIME(void);
  47404. +#define dwc_time DWC_TIME
  47405. +
  47406. +
  47407. +
  47408. +
  47409. +/* @mainpage DWC Portability and Common Library
  47410. + *
  47411. + * This is the documentation for the DWC Portability and Common Library.
  47412. + *
  47413. + * @section intro Introduction
  47414. + *
  47415. + * The DWC Portability library consists of wrapper calls and data structures to
  47416. + * all low-level functions which are typically provided by the OS. The WUDEV
  47417. + * driver uses only these functions. In order to port the WUDEV driver, only
  47418. + * the functions in this library need to be re-implemented, with the same
  47419. + * behavior as documented here.
  47420. + *
  47421. + * The Common library consists of higher level functions, which rely only on
  47422. + * calling the functions from the DWC Portability library. These common
  47423. + * routines are shared across modules. Some of the common libraries need to be
  47424. + * used directly by the driver programmer when porting WUDEV. Such as the
  47425. + * parameter and notification libraries.
  47426. + *
  47427. + * @section low Portability Library OS Wrapper Functions
  47428. + *
  47429. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  47430. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  47431. + * these functions are included in the dwc_os.h file.
  47432. + *
  47433. + * There are many functions here covering a wide array of OS services. Please
  47434. + * see dwc_os.h for details, and implementation notes for each function.
  47435. + *
  47436. + * @section common Common Library Functions
  47437. + *
  47438. + * Any function starting with dwc and in all lowercase is a common library
  47439. + * routine. These functions have a portable implementation and do not need to
  47440. + * be reimplemented when porting. The common routines can be used by any
  47441. + * driver, and some must be used by the end user to control the drivers. For
  47442. + * example, you must use the Parameter common library in order to set the
  47443. + * parameters in the WUDEV module.
  47444. + *
  47445. + * The common libraries consist of the following:
  47446. + *
  47447. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  47448. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  47449. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  47450. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  47451. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  47452. + * - Modpow - Used internally only. See dwc_modpow.h
  47453. + * - DH - Used internally only. See dwc_dh.h
  47454. + * - Crypto - Used internally only. See dwc_crypto.h
  47455. + *
  47456. + *
  47457. + * @section prereq Prerequistes For dwc_os.h
  47458. + * @subsection types Data Types
  47459. + *
  47460. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  47461. + * compilation environment. These data types are:
  47462. + *
  47463. + * - uint8_t - unsigned 8-bit data type
  47464. + * - int8_t - signed 8-bit data type
  47465. + * - uint16_t - unsigned 16-bit data type
  47466. + * - int16_t - signed 16-bit data type
  47467. + * - uint32_t - unsigned 32-bit data type
  47468. + * - int32_t - signed 32-bit data type
  47469. + * - uint64_t - unsigned 64-bit data type
  47470. + * - int64_t - signed 64-bit data type
  47471. + *
  47472. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  47473. + * that is to modify the top of the file to include the appropriate header.
  47474. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  47475. + * defined, the correct header will be added. A standard header <stdint.h> is
  47476. + * also used for environments where standard C headers are available.
  47477. + *
  47478. + * @subsection stdarg Variable Arguments
  47479. + *
  47480. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  47481. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  47482. + * provided in your enviornment in order to use dwc_os.h with the debug and
  47483. + * tracing message functionality.
  47484. + *
  47485. + * @subsection thread Threading
  47486. + *
  47487. + * WUDEV Core must be run on an operating system that provides for multiple
  47488. + * threads/processes. Threading can be implemented in many ways, even in
  47489. + * embedded systems without an operating system. At the bare minimum, the
  47490. + * system should be able to start any number of processes at any time to handle
  47491. + * special work. It need not be a pre-emptive system. Process context can
  47492. + * change upon a call to a blocking function. The hardware interrupt context
  47493. + * that calls the module's ISR() function must be differentiable from process
  47494. + * context, even if your processes are impemented via a hardware interrupt.
  47495. + * Further locking mechanism between process must exist (or be implemented), and
  47496. + * process context must have a way to disable interrupts for a period of time to
  47497. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  47498. + * threading should be able to be implemented with the defined behavior.
  47499. + *
  47500. + */
  47501. +
  47502. +#ifdef __cplusplus
  47503. +}
  47504. +#endif
  47505. +
  47506. +#endif /* _DWC_OS_H_ */
  47507. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile
  47508. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  47509. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile 2014-02-07 19:57:30.000000000 +0100
  47510. @@ -0,0 +1,58 @@
  47511. +#
  47512. +# Makefile for DWC_common library
  47513. +#
  47514. +
  47515. +ifneq ($(KERNELRELEASE),)
  47516. +
  47517. +EXTRA_CFLAGS += -DDWC_LINUX
  47518. +#EXTRA_CFLAGS += -DDEBUG
  47519. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  47520. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  47521. +
  47522. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  47523. +EXTRA_CFLAGS += -DDWC_CCLIB
  47524. +#EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  47525. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  47526. +EXTRA_CFLAGS += -DDWC_UTFLIB
  47527. +
  47528. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  47529. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47530. + dwc_crypto.o dwc_notifier.o \
  47531. + dwc_common_linux.o dwc_mem.o
  47532. +
  47533. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  47534. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  47535. +
  47536. +ifneq ($(kernrel3),2.6.20)
  47537. +# grayg - I only know that we use EXTRA_CFLAGS in 2.6.31 actually
  47538. +EXTRA_CFLAGS += $(CPPFLAGS)
  47539. +endif
  47540. +
  47541. +else
  47542. +
  47543. +#ifeq ($(KDIR),)
  47544. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47545. +#endif
  47546. +
  47547. +ifeq ($(ARCH),)
  47548. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47549. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47550. +endif
  47551. +
  47552. +ifeq ($(DOXYGEN),)
  47553. +DOXYGEN := doxygen
  47554. +endif
  47555. +
  47556. +default:
  47557. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47558. +
  47559. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47560. + $(DOXYGEN) doc/doxygen.cfg
  47561. +
  47562. +tags: $(wildcard *.[hc])
  47563. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47564. +
  47565. +endif
  47566. +
  47567. +clean:
  47568. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47569. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile.fbsd
  47570. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  47571. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-02-07 19:57:30.000000000 +0100
  47572. @@ -0,0 +1,17 @@
  47573. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  47574. +CFLAGS += -DDWC_FREEBSD
  47575. +CFLAGS += -DDEBUG
  47576. +#CFLAGS += -DDWC_DEBUG_REGS
  47577. +#CFLAGS += -DDWC_DEBUG_MEMORY
  47578. +
  47579. +#CFLAGS += -DDWC_LIBMODULE
  47580. +#CFLAGS += -DDWC_CCLIB
  47581. +#CFLAGS += -DDWC_CRYPTOLIB
  47582. +#CFLAGS += -DDWC_NOTIFYLIB
  47583. +#CFLAGS += -DDWC_UTFLIB
  47584. +
  47585. +KMOD = dwc_common_port_lib
  47586. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  47587. + dwc_common_fbsd.c dwc_mem.c
  47588. +
  47589. +.include <bsd.kmod.mk>
  47590. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile.linux linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile.linux
  47591. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  47592. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/Makefile.linux 2014-02-07 19:57:30.000000000 +0100
  47593. @@ -0,0 +1,49 @@
  47594. +#
  47595. +# Makefile for DWC_common library
  47596. +#
  47597. +ifneq ($(KERNELRELEASE),)
  47598. +
  47599. +EXTRA_CFLAGS += -DDWC_LINUX
  47600. +#EXTRA_CFLAGS += -DDEBUG
  47601. +#EXTRA_CFLAGS += -DDWC_DEBUG_REGS
  47602. +#EXTRA_CFLAGS += -DDWC_DEBUG_MEMORY
  47603. +
  47604. +EXTRA_CFLAGS += -DDWC_LIBMODULE
  47605. +EXTRA_CFLAGS += -DDWC_CCLIB
  47606. +EXTRA_CFLAGS += -DDWC_CRYPTOLIB
  47607. +EXTRA_CFLAGS += -DDWC_NOTIFYLIB
  47608. +EXTRA_CFLAGS += -DDWC_UTFLIB
  47609. +
  47610. +obj-m := dwc_common_port_lib.o
  47611. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47612. + dwc_crypto.o dwc_notifier.o \
  47613. + dwc_common_linux.o dwc_mem.o
  47614. +
  47615. +else
  47616. +
  47617. +ifeq ($(KDIR),)
  47618. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47619. +endif
  47620. +
  47621. +ifeq ($(ARCH),)
  47622. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47623. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47624. +endif
  47625. +
  47626. +ifeq ($(DOXYGEN),)
  47627. +DOXYGEN := doxygen
  47628. +endif
  47629. +
  47630. +default:
  47631. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47632. +
  47633. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47634. + $(DOXYGEN) doc/doxygen.cfg
  47635. +
  47636. +tags: $(wildcard *.[hc])
  47637. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47638. +
  47639. +endif
  47640. +
  47641. +clean:
  47642. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47643. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_common_port/usb.h linux-3.11.10/drivers/usb/host/dwc_common_port/usb.h
  47644. --- linux-3.11.10.orig/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  47645. +++ linux-3.11.10/drivers/usb/host/dwc_common_port/usb.h 2014-02-07 19:57:30.000000000 +0100
  47646. @@ -0,0 +1,946 @@
  47647. +/*
  47648. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  47649. + * All rights reserved.
  47650. + *
  47651. + * This code is derived from software contributed to The NetBSD Foundation
  47652. + * by Lennart Augustsson (lennart@augustsson.net) at
  47653. + * Carlstedt Research & Technology.
  47654. + *
  47655. + * Redistribution and use in source and binary forms, with or without
  47656. + * modification, are permitted provided that the following conditions
  47657. + * are met:
  47658. + * 1. Redistributions of source code must retain the above copyright
  47659. + * notice, this list of conditions and the following disclaimer.
  47660. + * 2. Redistributions in binary form must reproduce the above copyright
  47661. + * notice, this list of conditions and the following disclaimer in the
  47662. + * documentation and/or other materials provided with the distribution.
  47663. + * 3. All advertising materials mentioning features or use of this software
  47664. + * must display the following acknowledgement:
  47665. + * This product includes software developed by the NetBSD
  47666. + * Foundation, Inc. and its contributors.
  47667. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  47668. + * contributors may be used to endorse or promote products derived
  47669. + * from this software without specific prior written permission.
  47670. + *
  47671. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  47672. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  47673. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47674. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  47675. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  47676. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47677. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47678. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  47679. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47680. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  47681. + * POSSIBILITY OF SUCH DAMAGE.
  47682. + */
  47683. +
  47684. +/* Modified by Synopsys, Inc, 12/12/2007 */
  47685. +
  47686. +
  47687. +#ifndef _USB_H_
  47688. +#define _USB_H_
  47689. +
  47690. +#ifdef __cplusplus
  47691. +extern "C" {
  47692. +#endif
  47693. +
  47694. +/*
  47695. + * The USB records contain some unaligned little-endian word
  47696. + * components. The U[SG]ETW macros take care of both the alignment
  47697. + * and endian problem and should always be used to access non-byte
  47698. + * values.
  47699. + */
  47700. +typedef u_int8_t uByte;
  47701. +typedef u_int8_t uWord[2];
  47702. +typedef u_int8_t uDWord[4];
  47703. +
  47704. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  47705. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  47706. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  47707. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  47708. +
  47709. +#if 1
  47710. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  47711. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  47712. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  47713. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  47714. + (w)[1] = (u_int8_t)((v) >> 8), \
  47715. + (w)[2] = (u_int8_t)((v) >> 16), \
  47716. + (w)[3] = (u_int8_t)((v) >> 24))
  47717. +#else
  47718. +/*
  47719. + * On little-endian machines that can handle unanliged accesses
  47720. + * (e.g. i386) these macros can be replaced by the following.
  47721. + */
  47722. +#define UGETW(w) (*(u_int16_t *)(w))
  47723. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  47724. +#define UGETDW(w) (*(u_int32_t *)(w))
  47725. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  47726. +#endif
  47727. +
  47728. +/*
  47729. + * Macros for accessing UAS IU fields, which are big-endian
  47730. + */
  47731. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  47732. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  47733. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  47734. + ((x) >> 8) & 0xff, (x) & 0xff }
  47735. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  47736. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  47737. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  47738. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  47739. + (w)[1] = (u_int8_t)((v) >> 16), \
  47740. + (w)[2] = (u_int8_t)((v) >> 8), \
  47741. + (w)[3] = (u_int8_t)(v))
  47742. +
  47743. +#define UPACKED __attribute__((__packed__))
  47744. +
  47745. +typedef struct {
  47746. + uByte bmRequestType;
  47747. + uByte bRequest;
  47748. + uWord wValue;
  47749. + uWord wIndex;
  47750. + uWord wLength;
  47751. +} UPACKED usb_device_request_t;
  47752. +
  47753. +#define UT_GET_DIR(a) ((a) & 0x80)
  47754. +#define UT_WRITE 0x00
  47755. +#define UT_READ 0x80
  47756. +
  47757. +#define UT_GET_TYPE(a) ((a) & 0x60)
  47758. +#define UT_STANDARD 0x00
  47759. +#define UT_CLASS 0x20
  47760. +#define UT_VENDOR 0x40
  47761. +
  47762. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  47763. +#define UT_DEVICE 0x00
  47764. +#define UT_INTERFACE 0x01
  47765. +#define UT_ENDPOINT 0x02
  47766. +#define UT_OTHER 0x03
  47767. +
  47768. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  47769. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  47770. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  47771. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  47772. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  47773. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  47774. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  47775. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  47776. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  47777. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  47778. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  47779. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  47780. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  47781. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  47782. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  47783. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  47784. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  47785. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  47786. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  47787. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  47788. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  47789. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  47790. +
  47791. +/* Requests */
  47792. +#define UR_GET_STATUS 0x00
  47793. +#define USTAT_STANDARD_STATUS 0x00
  47794. +#define WUSTAT_WUSB_FEATURE 0x01
  47795. +#define WUSTAT_CHANNEL_INFO 0x02
  47796. +#define WUSTAT_RECEIVED_DATA 0x03
  47797. +#define WUSTAT_MAS_AVAILABILITY 0x04
  47798. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  47799. +#define UR_CLEAR_FEATURE 0x01
  47800. +#define UR_SET_FEATURE 0x03
  47801. +#define UR_SET_AND_TEST_FEATURE 0x0c
  47802. +#define UR_SET_ADDRESS 0x05
  47803. +#define UR_GET_DESCRIPTOR 0x06
  47804. +#define UDESC_DEVICE 0x01
  47805. +#define UDESC_CONFIG 0x02
  47806. +#define UDESC_STRING 0x03
  47807. +#define UDESC_INTERFACE 0x04
  47808. +#define UDESC_ENDPOINT 0x05
  47809. +#define UDESC_SS_USB_COMPANION 0x30
  47810. +#define UDESC_DEVICE_QUALIFIER 0x06
  47811. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  47812. +#define UDESC_INTERFACE_POWER 0x08
  47813. +#define UDESC_OTG 0x09
  47814. +#define WUDESC_SECURITY 0x0c
  47815. +#define WUDESC_KEY 0x0d
  47816. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  47817. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  47818. +#define WUD_KEY_TYPE_ASSOC 0x01
  47819. +#define WUD_KEY_TYPE_GTK 0x02
  47820. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  47821. +#define WUD_KEY_ORIGIN_HOST 0x00
  47822. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  47823. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  47824. +#define WUDESC_BOS 0x0f
  47825. +#define WUDESC_DEVICE_CAPABILITY 0x10
  47826. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  47827. +#define UDESC_BOS 0x0f
  47828. +#define UDESC_DEVICE_CAPABILITY 0x10
  47829. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  47830. +#define UDESC_CS_CONFIG 0x22
  47831. +#define UDESC_CS_STRING 0x23
  47832. +#define UDESC_CS_INTERFACE 0x24
  47833. +#define UDESC_CS_ENDPOINT 0x25
  47834. +#define UDESC_HUB 0x29
  47835. +#define UR_SET_DESCRIPTOR 0x07
  47836. +#define UR_GET_CONFIG 0x08
  47837. +#define UR_SET_CONFIG 0x09
  47838. +#define UR_GET_INTERFACE 0x0a
  47839. +#define UR_SET_INTERFACE 0x0b
  47840. +#define UR_SYNCH_FRAME 0x0c
  47841. +#define WUR_SET_ENCRYPTION 0x0d
  47842. +#define WUR_GET_ENCRYPTION 0x0e
  47843. +#define WUR_SET_HANDSHAKE 0x0f
  47844. +#define WUR_GET_HANDSHAKE 0x10
  47845. +#define WUR_SET_CONNECTION 0x11
  47846. +#define WUR_SET_SECURITY_DATA 0x12
  47847. +#define WUR_GET_SECURITY_DATA 0x13
  47848. +#define WUR_SET_WUSB_DATA 0x14
  47849. +#define WUDATA_DRPIE_INFO 0x01
  47850. +#define WUDATA_TRANSMIT_DATA 0x02
  47851. +#define WUDATA_TRANSMIT_PARAMS 0x03
  47852. +#define WUDATA_RECEIVE_PARAMS 0x04
  47853. +#define WUDATA_TRANSMIT_POWER 0x05
  47854. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  47855. +#define WUR_LOOPBACK_DATA_READ 0x16
  47856. +#define WUR_SET_INTERFACE_DS 0x17
  47857. +
  47858. +/* Feature numbers */
  47859. +#define UF_ENDPOINT_HALT 0
  47860. +#define UF_DEVICE_REMOTE_WAKEUP 1
  47861. +#define UF_TEST_MODE 2
  47862. +#define UF_DEVICE_B_HNP_ENABLE 3
  47863. +#define UF_DEVICE_A_HNP_SUPPORT 4
  47864. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  47865. +#define WUF_WUSB 3
  47866. +#define WUF_TX_DRPIE 0x0
  47867. +#define WUF_DEV_XMIT_PACKET 0x1
  47868. +#define WUF_COUNT_PACKETS 0x2
  47869. +#define WUF_CAPTURE_PACKETS 0x3
  47870. +#define UF_FUNCTION_SUSPEND 0
  47871. +#define UF_U1_ENABLE 48
  47872. +#define UF_U2_ENABLE 49
  47873. +#define UF_LTM_ENABLE 50
  47874. +
  47875. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  47876. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  47877. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  47878. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  47879. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  47880. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  47881. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  47882. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  47883. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  47884. +
  47885. +#ifdef _MSC_VER
  47886. +#include <pshpack1.h>
  47887. +#endif
  47888. +
  47889. +typedef struct {
  47890. + uByte bLength;
  47891. + uByte bDescriptorType;
  47892. + uByte bDescriptorSubtype;
  47893. +} UPACKED usb_descriptor_t;
  47894. +
  47895. +typedef struct {
  47896. + uByte bLength;
  47897. + uByte bDescriptorType;
  47898. +} UPACKED usb_descriptor_header_t;
  47899. +
  47900. +typedef struct {
  47901. + uByte bLength;
  47902. + uByte bDescriptorType;
  47903. + uWord bcdUSB;
  47904. +#define UD_USB_2_0 0x0200
  47905. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  47906. + uByte bDeviceClass;
  47907. + uByte bDeviceSubClass;
  47908. + uByte bDeviceProtocol;
  47909. + uByte bMaxPacketSize;
  47910. + /* The fields below are not part of the initial descriptor. */
  47911. + uWord idVendor;
  47912. + uWord idProduct;
  47913. + uWord bcdDevice;
  47914. + uByte iManufacturer;
  47915. + uByte iProduct;
  47916. + uByte iSerialNumber;
  47917. + uByte bNumConfigurations;
  47918. +} UPACKED usb_device_descriptor_t;
  47919. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  47920. +
  47921. +typedef struct {
  47922. + uByte bLength;
  47923. + uByte bDescriptorType;
  47924. + uWord wTotalLength;
  47925. + uByte bNumInterface;
  47926. + uByte bConfigurationValue;
  47927. + uByte iConfiguration;
  47928. +#define UC_ATT_ONE (1 << 7) /* must be set */
  47929. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  47930. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  47931. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  47932. + uByte bmAttributes;
  47933. +#define UC_BUS_POWERED 0x80
  47934. +#define UC_SELF_POWERED 0x40
  47935. +#define UC_REMOTE_WAKEUP 0x20
  47936. + uByte bMaxPower; /* max current in 2 mA units */
  47937. +#define UC_POWER_FACTOR 2
  47938. +} UPACKED usb_config_descriptor_t;
  47939. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  47940. +
  47941. +typedef struct {
  47942. + uByte bLength;
  47943. + uByte bDescriptorType;
  47944. + uByte bInterfaceNumber;
  47945. + uByte bAlternateSetting;
  47946. + uByte bNumEndpoints;
  47947. + uByte bInterfaceClass;
  47948. + uByte bInterfaceSubClass;
  47949. + uByte bInterfaceProtocol;
  47950. + uByte iInterface;
  47951. +} UPACKED usb_interface_descriptor_t;
  47952. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  47953. +
  47954. +typedef struct {
  47955. + uByte bLength;
  47956. + uByte bDescriptorType;
  47957. + uByte bEndpointAddress;
  47958. +#define UE_GET_DIR(a) ((a) & 0x80)
  47959. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  47960. +#define UE_DIR_IN 0x80
  47961. +#define UE_DIR_OUT 0x00
  47962. +#define UE_ADDR 0x0f
  47963. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  47964. + uByte bmAttributes;
  47965. +#define UE_XFERTYPE 0x03
  47966. +#define UE_CONTROL 0x00
  47967. +#define UE_ISOCHRONOUS 0x01
  47968. +#define UE_BULK 0x02
  47969. +#define UE_INTERRUPT 0x03
  47970. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  47971. +#define UE_ISO_TYPE 0x0c
  47972. +#define UE_ISO_ASYNC 0x04
  47973. +#define UE_ISO_ADAPT 0x08
  47974. +#define UE_ISO_SYNC 0x0c
  47975. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  47976. + uWord wMaxPacketSize;
  47977. + uByte bInterval;
  47978. +} UPACKED usb_endpoint_descriptor_t;
  47979. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  47980. +
  47981. +typedef struct ss_endpoint_companion_descriptor {
  47982. + uByte bLength;
  47983. + uByte bDescriptorType;
  47984. + uByte bMaxBurst;
  47985. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  47986. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  47987. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  47988. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  47989. + uByte bmAttributes;
  47990. + uWord wBytesPerInterval;
  47991. +} UPACKED ss_endpoint_companion_descriptor_t;
  47992. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  47993. +
  47994. +typedef struct {
  47995. + uByte bLength;
  47996. + uByte bDescriptorType;
  47997. + uWord bString[127];
  47998. +} UPACKED usb_string_descriptor_t;
  47999. +#define USB_MAX_STRING_LEN 128
  48000. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  48001. +
  48002. +/* Hub specific request */
  48003. +#define UR_GET_BUS_STATE 0x02
  48004. +#define UR_CLEAR_TT_BUFFER 0x08
  48005. +#define UR_RESET_TT 0x09
  48006. +#define UR_GET_TT_STATE 0x0a
  48007. +#define UR_STOP_TT 0x0b
  48008. +
  48009. +/* Hub features */
  48010. +#define UHF_C_HUB_LOCAL_POWER 0
  48011. +#define UHF_C_HUB_OVER_CURRENT 1
  48012. +#define UHF_PORT_CONNECTION 0
  48013. +#define UHF_PORT_ENABLE 1
  48014. +#define UHF_PORT_SUSPEND 2
  48015. +#define UHF_PORT_OVER_CURRENT 3
  48016. +#define UHF_PORT_RESET 4
  48017. +#define UHF_PORT_L1 5
  48018. +#define UHF_PORT_POWER 8
  48019. +#define UHF_PORT_LOW_SPEED 9
  48020. +#define UHF_PORT_HIGH_SPEED 10
  48021. +#define UHF_C_PORT_CONNECTION 16
  48022. +#define UHF_C_PORT_ENABLE 17
  48023. +#define UHF_C_PORT_SUSPEND 18
  48024. +#define UHF_C_PORT_OVER_CURRENT 19
  48025. +#define UHF_C_PORT_RESET 20
  48026. +#define UHF_C_PORT_L1 23
  48027. +#define UHF_PORT_TEST 21
  48028. +#define UHF_PORT_INDICATOR 22
  48029. +
  48030. +typedef struct {
  48031. + uByte bDescLength;
  48032. + uByte bDescriptorType;
  48033. + uByte bNbrPorts;
  48034. + uWord wHubCharacteristics;
  48035. +#define UHD_PWR 0x0003
  48036. +#define UHD_PWR_GANGED 0x0000
  48037. +#define UHD_PWR_INDIVIDUAL 0x0001
  48038. +#define UHD_PWR_NO_SWITCH 0x0002
  48039. +#define UHD_COMPOUND 0x0004
  48040. +#define UHD_OC 0x0018
  48041. +#define UHD_OC_GLOBAL 0x0000
  48042. +#define UHD_OC_INDIVIDUAL 0x0008
  48043. +#define UHD_OC_NONE 0x0010
  48044. +#define UHD_TT_THINK 0x0060
  48045. +#define UHD_TT_THINK_8 0x0000
  48046. +#define UHD_TT_THINK_16 0x0020
  48047. +#define UHD_TT_THINK_24 0x0040
  48048. +#define UHD_TT_THINK_32 0x0060
  48049. +#define UHD_PORT_IND 0x0080
  48050. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  48051. +#define UHD_PWRON_FACTOR 2
  48052. + uByte bHubContrCurrent;
  48053. + uByte DeviceRemovable[32]; /* max 255 ports */
  48054. +#define UHD_NOT_REMOV(desc, i) \
  48055. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  48056. + /* deprecated */ uByte PortPowerCtrlMask[1];
  48057. +} UPACKED usb_hub_descriptor_t;
  48058. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  48059. +
  48060. +typedef struct {
  48061. + uByte bLength;
  48062. + uByte bDescriptorType;
  48063. + uWord bcdUSB;
  48064. + uByte bDeviceClass;
  48065. + uByte bDeviceSubClass;
  48066. + uByte bDeviceProtocol;
  48067. + uByte bMaxPacketSize0;
  48068. + uByte bNumConfigurations;
  48069. + uByte bReserved;
  48070. +} UPACKED usb_device_qualifier_t;
  48071. +#define USB_DEVICE_QUALIFIER_SIZE 10
  48072. +
  48073. +typedef struct {
  48074. + uByte bLength;
  48075. + uByte bDescriptorType;
  48076. + uByte bmAttributes;
  48077. +#define UOTG_SRP 0x01
  48078. +#define UOTG_HNP 0x02
  48079. +} UPACKED usb_otg_descriptor_t;
  48080. +
  48081. +/* OTG feature selectors */
  48082. +#define UOTG_B_HNP_ENABLE 3
  48083. +#define UOTG_A_HNP_SUPPORT 4
  48084. +#define UOTG_A_ALT_HNP_SUPPORT 5
  48085. +
  48086. +typedef struct {
  48087. + uWord wStatus;
  48088. +/* Device status flags */
  48089. +#define UDS_SELF_POWERED 0x0001
  48090. +#define UDS_REMOTE_WAKEUP 0x0002
  48091. +/* Endpoint status flags */
  48092. +#define UES_HALT 0x0001
  48093. +} UPACKED usb_status_t;
  48094. +
  48095. +typedef struct {
  48096. + uWord wHubStatus;
  48097. +#define UHS_LOCAL_POWER 0x0001
  48098. +#define UHS_OVER_CURRENT 0x0002
  48099. + uWord wHubChange;
  48100. +} UPACKED usb_hub_status_t;
  48101. +
  48102. +typedef struct {
  48103. + uWord wPortStatus;
  48104. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  48105. +#define UPS_PORT_ENABLED 0x0002
  48106. +#define UPS_SUSPEND 0x0004
  48107. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  48108. +#define UPS_RESET 0x0010
  48109. +#define UPS_PORT_POWER 0x0100
  48110. +#define UPS_LOW_SPEED 0x0200
  48111. +#define UPS_HIGH_SPEED 0x0400
  48112. +#define UPS_PORT_TEST 0x0800
  48113. +#define UPS_PORT_INDICATOR 0x1000
  48114. + uWord wPortChange;
  48115. +#define UPS_C_CONNECT_STATUS 0x0001
  48116. +#define UPS_C_PORT_ENABLED 0x0002
  48117. +#define UPS_C_SUSPEND 0x0004
  48118. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  48119. +#define UPS_C_PORT_RESET 0x0010
  48120. +} UPACKED usb_port_status_t;
  48121. +
  48122. +#ifdef _MSC_VER
  48123. +#include <poppack.h>
  48124. +#endif
  48125. +
  48126. +/* Device class codes */
  48127. +#define UDCLASS_IN_INTERFACE 0x00
  48128. +#define UDCLASS_COMM 0x02
  48129. +#define UDCLASS_HUB 0x09
  48130. +#define UDSUBCLASS_HUB 0x00
  48131. +#define UDPROTO_FSHUB 0x00
  48132. +#define UDPROTO_HSHUBSTT 0x01
  48133. +#define UDPROTO_HSHUBMTT 0x02
  48134. +#define UDCLASS_DIAGNOSTIC 0xdc
  48135. +#define UDCLASS_WIRELESS 0xe0
  48136. +#define UDSUBCLASS_RF 0x01
  48137. +#define UDPROTO_BLUETOOTH 0x01
  48138. +#define UDCLASS_VENDOR 0xff
  48139. +
  48140. +/* Interface class codes */
  48141. +#define UICLASS_UNSPEC 0x00
  48142. +
  48143. +#define UICLASS_AUDIO 0x01
  48144. +#define UISUBCLASS_AUDIOCONTROL 1
  48145. +#define UISUBCLASS_AUDIOSTREAM 2
  48146. +#define UISUBCLASS_MIDISTREAM 3
  48147. +
  48148. +#define UICLASS_CDC 0x02 /* communication */
  48149. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  48150. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  48151. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  48152. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  48153. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  48154. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  48155. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  48156. +#define UIPROTO_CDC_AT 1
  48157. +
  48158. +#define UICLASS_HID 0x03
  48159. +#define UISUBCLASS_BOOT 1
  48160. +#define UIPROTO_BOOT_KEYBOARD 1
  48161. +
  48162. +#define UICLASS_PHYSICAL 0x05
  48163. +
  48164. +#define UICLASS_IMAGE 0x06
  48165. +
  48166. +#define UICLASS_PRINTER 0x07
  48167. +#define UISUBCLASS_PRINTER 1
  48168. +#define UIPROTO_PRINTER_UNI 1
  48169. +#define UIPROTO_PRINTER_BI 2
  48170. +#define UIPROTO_PRINTER_1284 3
  48171. +
  48172. +#define UICLASS_MASS 0x08
  48173. +#define UISUBCLASS_RBC 1
  48174. +#define UISUBCLASS_SFF8020I 2
  48175. +#define UISUBCLASS_QIC157 3
  48176. +#define UISUBCLASS_UFI 4
  48177. +#define UISUBCLASS_SFF8070I 5
  48178. +#define UISUBCLASS_SCSI 6
  48179. +#define UIPROTO_MASS_CBI_I 0
  48180. +#define UIPROTO_MASS_CBI 1
  48181. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  48182. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  48183. +
  48184. +#define UICLASS_HUB 0x09
  48185. +#define UISUBCLASS_HUB 0
  48186. +#define UIPROTO_FSHUB 0
  48187. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  48188. +#define UIPROTO_HSHUBMTT 1
  48189. +
  48190. +#define UICLASS_CDC_DATA 0x0a
  48191. +#define UISUBCLASS_DATA 0
  48192. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  48193. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  48194. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  48195. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  48196. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  48197. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  48198. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  48199. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  48200. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  48201. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  48202. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  48203. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  48204. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  48205. +
  48206. +#define UICLASS_SMARTCARD 0x0b
  48207. +
  48208. +/*#define UICLASS_FIRM_UPD 0x0c*/
  48209. +
  48210. +#define UICLASS_SECURITY 0x0d
  48211. +
  48212. +#define UICLASS_DIAGNOSTIC 0xdc
  48213. +
  48214. +#define UICLASS_WIRELESS 0xe0
  48215. +#define UISUBCLASS_RF 0x01
  48216. +#define UIPROTO_BLUETOOTH 0x01
  48217. +
  48218. +#define UICLASS_APPL_SPEC 0xfe
  48219. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  48220. +#define UISUBCLASS_IRDA 2
  48221. +#define UIPROTO_IRDA 0
  48222. +
  48223. +#define UICLASS_VENDOR 0xff
  48224. +
  48225. +#define USB_HUB_MAX_DEPTH 5
  48226. +
  48227. +/*
  48228. + * Minimum time a device needs to be powered down to go through
  48229. + * a power cycle. XXX Are these time in the spec?
  48230. + */
  48231. +#define USB_POWER_DOWN_TIME 200 /* ms */
  48232. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  48233. +
  48234. +#if 0
  48235. +/* These are the values from the spec. */
  48236. +#define USB_PORT_RESET_DELAY 10 /* ms */
  48237. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  48238. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  48239. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  48240. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  48241. +#define USB_RESUME_DELAY (20*5) /* ms */
  48242. +#define USB_RESUME_WAIT 10 /* ms */
  48243. +#define USB_RESUME_RECOVERY 10 /* ms */
  48244. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  48245. +#else
  48246. +/* Allow for marginal (i.e. non-conforming) devices. */
  48247. +#define USB_PORT_RESET_DELAY 50 /* ms */
  48248. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  48249. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  48250. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  48251. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  48252. +#define USB_RESUME_DELAY (50*5) /* ms */
  48253. +#define USB_RESUME_WAIT 50 /* ms */
  48254. +#define USB_RESUME_RECOVERY 50 /* ms */
  48255. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  48256. +#endif
  48257. +
  48258. +#define USB_MIN_POWER 100 /* mA */
  48259. +#define USB_MAX_POWER 500 /* mA */
  48260. +
  48261. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  48262. +
  48263. +#define USB_UNCONFIG_NO 0
  48264. +#define USB_UNCONFIG_INDEX (-1)
  48265. +
  48266. +/*** ioctl() related stuff ***/
  48267. +
  48268. +struct usb_ctl_request {
  48269. + int ucr_addr;
  48270. + usb_device_request_t ucr_request;
  48271. + void *ucr_data;
  48272. + int ucr_flags;
  48273. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  48274. + int ucr_actlen; /* actual length transferred */
  48275. +};
  48276. +
  48277. +struct usb_alt_interface {
  48278. + int uai_config_index;
  48279. + int uai_interface_index;
  48280. + int uai_alt_no;
  48281. +};
  48282. +
  48283. +#define USB_CURRENT_CONFIG_INDEX (-1)
  48284. +#define USB_CURRENT_ALT_INDEX (-1)
  48285. +
  48286. +struct usb_config_desc {
  48287. + int ucd_config_index;
  48288. + usb_config_descriptor_t ucd_desc;
  48289. +};
  48290. +
  48291. +struct usb_interface_desc {
  48292. + int uid_config_index;
  48293. + int uid_interface_index;
  48294. + int uid_alt_index;
  48295. + usb_interface_descriptor_t uid_desc;
  48296. +};
  48297. +
  48298. +struct usb_endpoint_desc {
  48299. + int ued_config_index;
  48300. + int ued_interface_index;
  48301. + int ued_alt_index;
  48302. + int ued_endpoint_index;
  48303. + usb_endpoint_descriptor_t ued_desc;
  48304. +};
  48305. +
  48306. +struct usb_full_desc {
  48307. + int ufd_config_index;
  48308. + u_int ufd_size;
  48309. + u_char *ufd_data;
  48310. +};
  48311. +
  48312. +struct usb_string_desc {
  48313. + int usd_string_index;
  48314. + int usd_language_id;
  48315. + usb_string_descriptor_t usd_desc;
  48316. +};
  48317. +
  48318. +struct usb_ctl_report_desc {
  48319. + int ucrd_size;
  48320. + u_char ucrd_data[1024]; /* filled data size will vary */
  48321. +};
  48322. +
  48323. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  48324. +
  48325. +#define USB_MAX_DEVNAMES 4
  48326. +#define USB_MAX_DEVNAMELEN 16
  48327. +struct usb_device_info {
  48328. + u_int8_t udi_bus;
  48329. + u_int8_t udi_addr; /* device address */
  48330. + usb_event_cookie_t udi_cookie;
  48331. + char udi_product[USB_MAX_STRING_LEN];
  48332. + char udi_vendor[USB_MAX_STRING_LEN];
  48333. + char udi_release[8];
  48334. + u_int16_t udi_productNo;
  48335. + u_int16_t udi_vendorNo;
  48336. + u_int16_t udi_releaseNo;
  48337. + u_int8_t udi_class;
  48338. + u_int8_t udi_subclass;
  48339. + u_int8_t udi_protocol;
  48340. + u_int8_t udi_config;
  48341. + u_int8_t udi_speed;
  48342. +#define USB_SPEED_UNKNOWN 0
  48343. +#define USB_SPEED_LOW 1
  48344. +#define USB_SPEED_FULL 2
  48345. +#define USB_SPEED_HIGH 3
  48346. +#define USB_SPEED_VARIABLE 4
  48347. +#define USB_SPEED_SUPER 5
  48348. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  48349. + int udi_nports;
  48350. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  48351. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  48352. +#define USB_PORT_ENABLED 0xff
  48353. +#define USB_PORT_SUSPENDED 0xfe
  48354. +#define USB_PORT_POWERED 0xfd
  48355. +#define USB_PORT_DISABLED 0xfc
  48356. +};
  48357. +
  48358. +struct usb_ctl_report {
  48359. + int ucr_report;
  48360. + u_char ucr_data[1024]; /* filled data size will vary */
  48361. +};
  48362. +
  48363. +struct usb_device_stats {
  48364. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  48365. +};
  48366. +
  48367. +#define WUSB_MIN_IE 0x80
  48368. +#define WUSB_WCTA_IE 0x80
  48369. +#define WUSB_WCONNECTACK_IE 0x81
  48370. +#define WUSB_WHOSTINFO_IE 0x82
  48371. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  48372. +#define WUHI_CA_RECONN 0x00
  48373. +#define WUHI_CA_LIMITED 0x01
  48374. +#define WUHI_CA_ALL 0x03
  48375. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  48376. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  48377. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  48378. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  48379. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  48380. +#define WUSB_WWORK_IE 0x87
  48381. +#define WUSB_WCHANNEL_STOP_IE 0x88
  48382. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  48383. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  48384. +#define WUSB_WRESETDEVICE_IE 0x8B
  48385. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  48386. +#define WUSB_MAX_IE 0x8C
  48387. +
  48388. +/* Device Notification Types */
  48389. +
  48390. +#define WUSB_DN_MIN 0x01
  48391. +#define WUSB_DN_CONNECT 0x01
  48392. +# define WUSB_DA_OLDCONN 0x00
  48393. +# define WUSB_DA_NEWCONN 0x01
  48394. +# define WUSB_DA_SELF_BEACON 0x02
  48395. +# define WUSB_DA_DIR_BEACON 0x04
  48396. +# define WUSB_DA_NO_BEACON 0x06
  48397. +#define WUSB_DN_DISCONNECT 0x02
  48398. +#define WUSB_DN_EPRDY 0x03
  48399. +#define WUSB_DN_MASAVAILCHANGED 0x04
  48400. +#define WUSB_DN_REMOTEWAKEUP 0x05
  48401. +#define WUSB_DN_SLEEP 0x06
  48402. +#define WUSB_DN_ALIVE 0x07
  48403. +#define WUSB_DN_MAX 0x07
  48404. +
  48405. +#ifdef _MSC_VER
  48406. +#include <pshpack1.h>
  48407. +#endif
  48408. +
  48409. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  48410. +typedef struct wusb_hndshk_data {
  48411. + uByte bMessageNumber;
  48412. + uByte bStatus;
  48413. + uByte tTKID[3];
  48414. + uByte bReserved;
  48415. + uByte CDID[16];
  48416. + uByte Nonce[16];
  48417. + uByte MIC[8];
  48418. +} UPACKED wusb_hndshk_data_t;
  48419. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  48420. +
  48421. +/* WUSB Connection Context */
  48422. +typedef struct wusb_conn_context {
  48423. + uByte CHID [16];
  48424. + uByte CDID [16];
  48425. + uByte CK [16];
  48426. +} UPACKED wusb_conn_context_t;
  48427. +
  48428. +/* WUSB Security Descriptor */
  48429. +typedef struct wusb_security_desc {
  48430. + uByte bLength;
  48431. + uByte bDescriptorType;
  48432. + uWord wTotalLength;
  48433. + uByte bNumEncryptionTypes;
  48434. +} UPACKED wusb_security_desc_t;
  48435. +
  48436. +/* WUSB Encryption Type Descriptor */
  48437. +typedef struct wusb_encrypt_type_desc {
  48438. + uByte bLength;
  48439. + uByte bDescriptorType;
  48440. +
  48441. + uByte bEncryptionType;
  48442. +#define WUETD_UNSECURE 0
  48443. +#define WUETD_WIRED 1
  48444. +#define WUETD_CCM_1 2
  48445. +#define WUETD_RSA_1 3
  48446. +
  48447. + uByte bEncryptionValue;
  48448. + uByte bAuthKeyIndex;
  48449. +} UPACKED wusb_encrypt_type_desc_t;
  48450. +
  48451. +/* WUSB Key Descriptor */
  48452. +typedef struct wusb_key_desc {
  48453. + uByte bLength;
  48454. + uByte bDescriptorType;
  48455. + uByte tTKID[3];
  48456. + uByte bReserved;
  48457. + uByte KeyData[1]; /* variable length */
  48458. +} UPACKED wusb_key_desc_t;
  48459. +
  48460. +/* WUSB BOS Descriptor (Binary device Object Store) */
  48461. +typedef struct wusb_bos_desc {
  48462. + uByte bLength;
  48463. + uByte bDescriptorType;
  48464. + uWord wTotalLength;
  48465. + uByte bNumDeviceCaps;
  48466. +} UPACKED wusb_bos_desc_t;
  48467. +
  48468. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  48469. +typedef struct usb_dev_cap_20_ext_desc {
  48470. + uByte bLength;
  48471. + uByte bDescriptorType;
  48472. + uByte bDevCapabilityType;
  48473. +#define USB_20_EXT_LPM 0x02
  48474. + uDWord bmAttributes;
  48475. +} UPACKED usb_dev_cap_20_ext_desc_t;
  48476. +
  48477. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  48478. +typedef struct usb_dev_cap_ss_usb {
  48479. + uByte bLength;
  48480. + uByte bDescriptorType;
  48481. + uByte bDevCapabilityType;
  48482. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  48483. + uByte bmAttributes;
  48484. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  48485. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  48486. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  48487. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  48488. + uWord wSpeedsSupported;
  48489. + uByte bFunctionalitySupport;
  48490. + uByte bU1DevExitLat;
  48491. + uWord wU2DevExitLat;
  48492. +} UPACKED usb_dev_cap_ss_usb_t;
  48493. +
  48494. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  48495. +typedef struct usb_dev_cap_container_id {
  48496. + uByte bLength;
  48497. + uByte bDescriptorType;
  48498. + uByte bDevCapabilityType;
  48499. + uByte bReserved;
  48500. + uByte containerID[16];
  48501. +} UPACKED usb_dev_cap_container_id_t;
  48502. +
  48503. +/* Device Capability Type Codes */
  48504. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  48505. +
  48506. +/* Device Capability Descriptor */
  48507. +typedef struct wusb_dev_cap_desc {
  48508. + uByte bLength;
  48509. + uByte bDescriptorType;
  48510. + uByte bDevCapabilityType;
  48511. + uByte caps[1]; /* Variable length */
  48512. +} UPACKED wusb_dev_cap_desc_t;
  48513. +
  48514. +/* Device Capability Descriptor */
  48515. +typedef struct wusb_dev_cap_uwb_desc {
  48516. + uByte bLength;
  48517. + uByte bDescriptorType;
  48518. + uByte bDevCapabilityType;
  48519. + uByte bmAttributes;
  48520. + uWord wPHYRates; /* Bitmap */
  48521. + uByte bmTFITXPowerInfo;
  48522. + uByte bmFFITXPowerInfo;
  48523. + uWord bmBandGroup;
  48524. + uByte bReserved;
  48525. +} UPACKED wusb_dev_cap_uwb_desc_t;
  48526. +
  48527. +/* Wireless USB Endpoint Companion Descriptor */
  48528. +typedef struct wusb_endpoint_companion_desc {
  48529. + uByte bLength;
  48530. + uByte bDescriptorType;
  48531. + uByte bMaxBurst;
  48532. + uByte bMaxSequence;
  48533. + uWord wMaxStreamDelay;
  48534. + uWord wOverTheAirPacketSize;
  48535. + uByte bOverTheAirInterval;
  48536. + uByte bmCompAttributes;
  48537. +} UPACKED wusb_endpoint_companion_desc_t;
  48538. +
  48539. +/* Wireless USB Numeric Association M1 Data Structure */
  48540. +typedef struct wusb_m1_data {
  48541. + uByte version;
  48542. + uWord langId;
  48543. + uByte deviceFriendlyNameLength;
  48544. + uByte sha_256_m3[32];
  48545. + uByte deviceFriendlyName[256];
  48546. +} UPACKED wusb_m1_data_t;
  48547. +
  48548. +typedef struct wusb_m2_data {
  48549. + uByte version;
  48550. + uWord langId;
  48551. + uByte hostFriendlyNameLength;
  48552. + uByte pkh[384];
  48553. + uByte hostFriendlyName[256];
  48554. +} UPACKED wusb_m2_data_t;
  48555. +
  48556. +typedef struct wusb_m3_data {
  48557. + uByte pkd[384];
  48558. + uByte nd;
  48559. +} UPACKED wusb_m3_data_t;
  48560. +
  48561. +typedef struct wusb_m4_data {
  48562. + uDWord _attributeTypeIdAndLength_1;
  48563. + uWord associationTypeId;
  48564. +
  48565. + uDWord _attributeTypeIdAndLength_2;
  48566. + uWord associationSubTypeId;
  48567. +
  48568. + uDWord _attributeTypeIdAndLength_3;
  48569. + uDWord length;
  48570. +
  48571. + uDWord _attributeTypeIdAndLength_4;
  48572. + uDWord associationStatus;
  48573. +
  48574. + uDWord _attributeTypeIdAndLength_5;
  48575. + uByte chid[16];
  48576. +
  48577. + uDWord _attributeTypeIdAndLength_6;
  48578. + uByte cdid[16];
  48579. +
  48580. + uDWord _attributeTypeIdAndLength_7;
  48581. + uByte bandGroups[2];
  48582. +} UPACKED wusb_m4_data_t;
  48583. +
  48584. +#ifdef _MSC_VER
  48585. +#include <poppack.h>
  48586. +#endif
  48587. +
  48588. +#ifdef __cplusplus
  48589. +}
  48590. +#endif
  48591. +
  48592. +#endif /* _USB_H_ */
  48593. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-3.11.10/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  48594. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  48595. +++ linux-3.11.10/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-02-07 19:57:30.000000000 +0100
  48596. @@ -0,0 +1,224 @@
  48597. +# Doxyfile 1.3.9.1
  48598. +
  48599. +#---------------------------------------------------------------------------
  48600. +# Project related configuration options
  48601. +#---------------------------------------------------------------------------
  48602. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  48603. +PROJECT_NUMBER = v3.00a
  48604. +OUTPUT_DIRECTORY = ./doc/
  48605. +CREATE_SUBDIRS = NO
  48606. +OUTPUT_LANGUAGE = English
  48607. +BRIEF_MEMBER_DESC = YES
  48608. +REPEAT_BRIEF = YES
  48609. +ABBREVIATE_BRIEF = "The $name class" \
  48610. + "The $name widget" \
  48611. + "The $name file" \
  48612. + is \
  48613. + provides \
  48614. + specifies \
  48615. + contains \
  48616. + represents \
  48617. + a \
  48618. + an \
  48619. + the
  48620. +ALWAYS_DETAILED_SEC = NO
  48621. +INLINE_INHERITED_MEMB = NO
  48622. +FULL_PATH_NAMES = NO
  48623. +STRIP_FROM_PATH =
  48624. +STRIP_FROM_INC_PATH =
  48625. +SHORT_NAMES = NO
  48626. +JAVADOC_AUTOBRIEF = YES
  48627. +MULTILINE_CPP_IS_BRIEF = NO
  48628. +INHERIT_DOCS = YES
  48629. +DISTRIBUTE_GROUP_DOC = NO
  48630. +TAB_SIZE = 8
  48631. +ALIASES =
  48632. +OPTIMIZE_OUTPUT_FOR_C = YES
  48633. +OPTIMIZE_OUTPUT_JAVA = NO
  48634. +SUBGROUPING = YES
  48635. +#---------------------------------------------------------------------------
  48636. +# Build related configuration options
  48637. +#---------------------------------------------------------------------------
  48638. +EXTRACT_ALL = NO
  48639. +EXTRACT_PRIVATE = YES
  48640. +EXTRACT_STATIC = YES
  48641. +EXTRACT_LOCAL_CLASSES = YES
  48642. +EXTRACT_LOCAL_METHODS = NO
  48643. +HIDE_UNDOC_MEMBERS = NO
  48644. +HIDE_UNDOC_CLASSES = NO
  48645. +HIDE_FRIEND_COMPOUNDS = NO
  48646. +HIDE_IN_BODY_DOCS = NO
  48647. +INTERNAL_DOCS = NO
  48648. +CASE_SENSE_NAMES = NO
  48649. +HIDE_SCOPE_NAMES = NO
  48650. +SHOW_INCLUDE_FILES = YES
  48651. +INLINE_INFO = YES
  48652. +SORT_MEMBER_DOCS = NO
  48653. +SORT_BRIEF_DOCS = NO
  48654. +SORT_BY_SCOPE_NAME = NO
  48655. +GENERATE_TODOLIST = YES
  48656. +GENERATE_TESTLIST = YES
  48657. +GENERATE_BUGLIST = YES
  48658. +GENERATE_DEPRECATEDLIST= YES
  48659. +ENABLED_SECTIONS =
  48660. +MAX_INITIALIZER_LINES = 30
  48661. +SHOW_USED_FILES = YES
  48662. +SHOW_DIRECTORIES = YES
  48663. +#---------------------------------------------------------------------------
  48664. +# configuration options related to warning and progress messages
  48665. +#---------------------------------------------------------------------------
  48666. +QUIET = YES
  48667. +WARNINGS = YES
  48668. +WARN_IF_UNDOCUMENTED = NO
  48669. +WARN_IF_DOC_ERROR = YES
  48670. +WARN_FORMAT = "$file:$line: $text"
  48671. +WARN_LOGFILE =
  48672. +#---------------------------------------------------------------------------
  48673. +# configuration options related to the input files
  48674. +#---------------------------------------------------------------------------
  48675. +INPUT = .
  48676. +FILE_PATTERNS = *.c \
  48677. + *.h \
  48678. + ./linux/*.c \
  48679. + ./linux/*.h
  48680. +RECURSIVE = NO
  48681. +EXCLUDE = ./test/ \
  48682. + ./dwc_otg/.AppleDouble/
  48683. +EXCLUDE_SYMLINKS = YES
  48684. +EXCLUDE_PATTERNS = *.mod.*
  48685. +EXAMPLE_PATH =
  48686. +EXAMPLE_PATTERNS = *
  48687. +EXAMPLE_RECURSIVE = NO
  48688. +IMAGE_PATH =
  48689. +INPUT_FILTER =
  48690. +FILTER_PATTERNS =
  48691. +FILTER_SOURCE_FILES = NO
  48692. +#---------------------------------------------------------------------------
  48693. +# configuration options related to source browsing
  48694. +#---------------------------------------------------------------------------
  48695. +SOURCE_BROWSER = YES
  48696. +INLINE_SOURCES = NO
  48697. +STRIP_CODE_COMMENTS = YES
  48698. +REFERENCED_BY_RELATION = NO
  48699. +REFERENCES_RELATION = NO
  48700. +VERBATIM_HEADERS = NO
  48701. +#---------------------------------------------------------------------------
  48702. +# configuration options related to the alphabetical class index
  48703. +#---------------------------------------------------------------------------
  48704. +ALPHABETICAL_INDEX = NO
  48705. +COLS_IN_ALPHA_INDEX = 5
  48706. +IGNORE_PREFIX =
  48707. +#---------------------------------------------------------------------------
  48708. +# configuration options related to the HTML output
  48709. +#---------------------------------------------------------------------------
  48710. +GENERATE_HTML = YES
  48711. +HTML_OUTPUT = html
  48712. +HTML_FILE_EXTENSION = .html
  48713. +HTML_HEADER =
  48714. +HTML_FOOTER =
  48715. +HTML_STYLESHEET =
  48716. +HTML_ALIGN_MEMBERS = YES
  48717. +GENERATE_HTMLHELP = NO
  48718. +CHM_FILE =
  48719. +HHC_LOCATION =
  48720. +GENERATE_CHI = NO
  48721. +BINARY_TOC = NO
  48722. +TOC_EXPAND = NO
  48723. +DISABLE_INDEX = NO
  48724. +ENUM_VALUES_PER_LINE = 4
  48725. +GENERATE_TREEVIEW = YES
  48726. +TREEVIEW_WIDTH = 250
  48727. +#---------------------------------------------------------------------------
  48728. +# configuration options related to the LaTeX output
  48729. +#---------------------------------------------------------------------------
  48730. +GENERATE_LATEX = NO
  48731. +LATEX_OUTPUT = latex
  48732. +LATEX_CMD_NAME = latex
  48733. +MAKEINDEX_CMD_NAME = makeindex
  48734. +COMPACT_LATEX = NO
  48735. +PAPER_TYPE = a4wide
  48736. +EXTRA_PACKAGES =
  48737. +LATEX_HEADER =
  48738. +PDF_HYPERLINKS = NO
  48739. +USE_PDFLATEX = NO
  48740. +LATEX_BATCHMODE = NO
  48741. +LATEX_HIDE_INDICES = NO
  48742. +#---------------------------------------------------------------------------
  48743. +# configuration options related to the RTF output
  48744. +#---------------------------------------------------------------------------
  48745. +GENERATE_RTF = NO
  48746. +RTF_OUTPUT = rtf
  48747. +COMPACT_RTF = NO
  48748. +RTF_HYPERLINKS = NO
  48749. +RTF_STYLESHEET_FILE =
  48750. +RTF_EXTENSIONS_FILE =
  48751. +#---------------------------------------------------------------------------
  48752. +# configuration options related to the man page output
  48753. +#---------------------------------------------------------------------------
  48754. +GENERATE_MAN = NO
  48755. +MAN_OUTPUT = man
  48756. +MAN_EXTENSION = .3
  48757. +MAN_LINKS = NO
  48758. +#---------------------------------------------------------------------------
  48759. +# configuration options related to the XML output
  48760. +#---------------------------------------------------------------------------
  48761. +GENERATE_XML = NO
  48762. +XML_OUTPUT = xml
  48763. +XML_SCHEMA =
  48764. +XML_DTD =
  48765. +XML_PROGRAMLISTING = YES
  48766. +#---------------------------------------------------------------------------
  48767. +# configuration options for the AutoGen Definitions output
  48768. +#---------------------------------------------------------------------------
  48769. +GENERATE_AUTOGEN_DEF = NO
  48770. +#---------------------------------------------------------------------------
  48771. +# configuration options related to the Perl module output
  48772. +#---------------------------------------------------------------------------
  48773. +GENERATE_PERLMOD = NO
  48774. +PERLMOD_LATEX = NO
  48775. +PERLMOD_PRETTY = YES
  48776. +PERLMOD_MAKEVAR_PREFIX =
  48777. +#---------------------------------------------------------------------------
  48778. +# Configuration options related to the preprocessor
  48779. +#---------------------------------------------------------------------------
  48780. +ENABLE_PREPROCESSING = YES
  48781. +MACRO_EXPANSION = YES
  48782. +EXPAND_ONLY_PREDEF = YES
  48783. +SEARCH_INCLUDES = YES
  48784. +INCLUDE_PATH =
  48785. +INCLUDE_FILE_PATTERNS =
  48786. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  48787. +EXPAND_AS_DEFINED = DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW DWC_OTG_DEVICE_ATTR_BITFIELD_STORE DWC_OTG_DEVICE_ATTR_BITFIELD_RW DWC_OTG_DEVICE_ATTR_BITFIELD_RO DWC_OTG_DEVICE_ATTR_REG_SHOW DWC_OTG_DEVICE_ATTR_REG_STORE DWC_OTG_DEVICE_ATTR_REG32_RW DWC_OTG_DEVICE_ATTR_REG32_RO DWC_EN_ISOC
  48788. +SKIP_FUNCTION_MACROS = NO
  48789. +#---------------------------------------------------------------------------
  48790. +# Configuration::additions related to external references
  48791. +#---------------------------------------------------------------------------
  48792. +TAGFILES =
  48793. +GENERATE_TAGFILE =
  48794. +ALLEXTERNALS = NO
  48795. +EXTERNAL_GROUPS = YES
  48796. +PERL_PATH = /usr/bin/perl
  48797. +#---------------------------------------------------------------------------
  48798. +# Configuration options related to the dot tool
  48799. +#---------------------------------------------------------------------------
  48800. +CLASS_DIAGRAMS = YES
  48801. +HIDE_UNDOC_RELATIONS = YES
  48802. +HAVE_DOT = NO
  48803. +CLASS_GRAPH = YES
  48804. +COLLABORATION_GRAPH = YES
  48805. +UML_LOOK = NO
  48806. +TEMPLATE_RELATIONS = NO
  48807. +INCLUDE_GRAPH = YES
  48808. +INCLUDED_BY_GRAPH = YES
  48809. +CALL_GRAPH = NO
  48810. +GRAPHICAL_HIERARCHY = YES
  48811. +DOT_IMAGE_FORMAT = png
  48812. +DOT_PATH =
  48813. +DOTFILE_DIRS =
  48814. +MAX_DOT_GRAPH_DEPTH = 1000
  48815. +GENERATE_LEGEND = YES
  48816. +DOT_CLEANUP = YES
  48817. +#---------------------------------------------------------------------------
  48818. +# Configuration::additions related to the search engine
  48819. +#---------------------------------------------------------------------------
  48820. +SEARCHENGINE = NO
  48821. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dummy_audio.c linux-3.11.10/drivers/usb/host/dwc_otg/dummy_audio.c
  48822. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  48823. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dummy_audio.c 2014-02-07 19:57:30.000000000 +0100
  48824. @@ -0,0 +1,1575 @@
  48825. +/*
  48826. + * zero.c -- Gadget Zero, for USB development
  48827. + *
  48828. + * Copyright (C) 2003-2004 David Brownell
  48829. + * All rights reserved.
  48830. + *
  48831. + * Redistribution and use in source and binary forms, with or without
  48832. + * modification, are permitted provided that the following conditions
  48833. + * are met:
  48834. + * 1. Redistributions of source code must retain the above copyright
  48835. + * notice, this list of conditions, and the following disclaimer,
  48836. + * without modification.
  48837. + * 2. Redistributions in binary form must reproduce the above copyright
  48838. + * notice, this list of conditions and the following disclaimer in the
  48839. + * documentation and/or other materials provided with the distribution.
  48840. + * 3. The names of the above-listed copyright holders may not be used
  48841. + * to endorse or promote products derived from this software without
  48842. + * specific prior written permission.
  48843. + *
  48844. + * ALTERNATIVELY, this software may be distributed under the terms of the
  48845. + * GNU General Public License ("GPL") as published by the Free Software
  48846. + * Foundation, either version 2 of that License or (at your option) any
  48847. + * later version.
  48848. + *
  48849. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  48850. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  48851. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48852. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  48853. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48854. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  48855. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  48856. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  48857. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  48858. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48859. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48860. + */
  48861. +
  48862. +
  48863. +/*
  48864. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  48865. + * can write a hardware-agnostic gadget driver running inside a USB device.
  48866. + *
  48867. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  48868. + * affect most of the driver.
  48869. + *
  48870. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  48871. + * functional test of your device-side usb stack, or with "usb-skeleton".
  48872. + *
  48873. + * It supports two similar configurations. One sinks whatever the usb host
  48874. + * writes, and in return sources zeroes. The other loops whatever the host
  48875. + * writes back, so the host can read it. Module options include:
  48876. + *
  48877. + * buflen=N default N=4096, buffer size used
  48878. + * qlen=N default N=32, how many buffers in the loopback queue
  48879. + * loopdefault default false, list loopback config first
  48880. + *
  48881. + * Many drivers will only have one configuration, letting them be much
  48882. + * simpler if they also don't support high speed operation (like this
  48883. + * driver does).
  48884. + */
  48885. +
  48886. +#include <linux/config.h>
  48887. +#include <linux/module.h>
  48888. +#include <linux/kernel.h>
  48889. +#include <linux/delay.h>
  48890. +#include <linux/ioport.h>
  48891. +#include <linux/sched.h>
  48892. +#include <linux/slab.h>
  48893. +#include <linux/smp_lock.h>
  48894. +#include <linux/errno.h>
  48895. +#include <linux/init.h>
  48896. +#include <linux/timer.h>
  48897. +#include <linux/list.h>
  48898. +#include <linux/interrupt.h>
  48899. +#include <linux/uts.h>
  48900. +#include <linux/version.h>
  48901. +#include <linux/device.h>
  48902. +#include <linux/moduleparam.h>
  48903. +#include <linux/proc_fs.h>
  48904. +
  48905. +#include <asm/byteorder.h>
  48906. +#include <asm/io.h>
  48907. +#include <asm/irq.h>
  48908. +#include <asm/system.h>
  48909. +#include <asm/unaligned.h>
  48910. +
  48911. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  48912. +# include <linux/usb/ch9.h>
  48913. +#else
  48914. +# include <linux/usb_ch9.h>
  48915. +#endif
  48916. +
  48917. +#include <linux/usb_gadget.h>
  48918. +
  48919. +
  48920. +/*-------------------------------------------------------------------------*/
  48921. +/*-------------------------------------------------------------------------*/
  48922. +
  48923. +
  48924. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  48925. +{
  48926. + int count = 0;
  48927. + u8 c;
  48928. + u16 uchar;
  48929. +
  48930. + /* this insists on correct encodings, though not minimal ones.
  48931. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  48932. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  48933. + */
  48934. + while (len != 0 && (c = (u8) *s++) != 0) {
  48935. + if (unlikely(c & 0x80)) {
  48936. + // 2-byte sequence:
  48937. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  48938. + if ((c & 0xe0) == 0xc0) {
  48939. + uchar = (c & 0x1f) << 6;
  48940. +
  48941. + c = (u8) *s++;
  48942. + if ((c & 0xc0) != 0xc0)
  48943. + goto fail;
  48944. + c &= 0x3f;
  48945. + uchar |= c;
  48946. +
  48947. + // 3-byte sequence (most CJKV characters):
  48948. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  48949. + } else if ((c & 0xf0) == 0xe0) {
  48950. + uchar = (c & 0x0f) << 12;
  48951. +
  48952. + c = (u8) *s++;
  48953. + if ((c & 0xc0) != 0xc0)
  48954. + goto fail;
  48955. + c &= 0x3f;
  48956. + uchar |= c << 6;
  48957. +
  48958. + c = (u8) *s++;
  48959. + if ((c & 0xc0) != 0xc0)
  48960. + goto fail;
  48961. + c &= 0x3f;
  48962. + uchar |= c;
  48963. +
  48964. + /* no bogus surrogates */
  48965. + if (0xd800 <= uchar && uchar <= 0xdfff)
  48966. + goto fail;
  48967. +
  48968. + // 4-byte sequence (surrogate pairs, currently rare):
  48969. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  48970. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  48971. + // (uuuuu = wwww + 1)
  48972. + // FIXME accept the surrogate code points (only)
  48973. +
  48974. + } else
  48975. + goto fail;
  48976. + } else
  48977. + uchar = c;
  48978. + put_unaligned (cpu_to_le16 (uchar), cp++);
  48979. + count++;
  48980. + len--;
  48981. + }
  48982. + return count;
  48983. +fail:
  48984. + return -1;
  48985. +}
  48986. +
  48987. +
  48988. +/**
  48989. + * usb_gadget_get_string - fill out a string descriptor
  48990. + * @table: of c strings encoded using UTF-8
  48991. + * @id: string id, from low byte of wValue in get string descriptor
  48992. + * @buf: at least 256 bytes
  48993. + *
  48994. + * Finds the UTF-8 string matching the ID, and converts it into a
  48995. + * string descriptor in utf16-le.
  48996. + * Returns length of descriptor (always even) or negative errno
  48997. + *
  48998. + * If your driver needs stings in multiple languages, you'll probably
  48999. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  49000. + * using this routine after choosing which set of UTF-8 strings to use.
  49001. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  49002. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  49003. + * characters (which are also widely used in C strings).
  49004. + */
  49005. +int
  49006. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  49007. +{
  49008. + struct usb_string *s;
  49009. + int len;
  49010. +
  49011. + /* descriptor 0 has the language id */
  49012. + if (id == 0) {
  49013. + buf [0] = 4;
  49014. + buf [1] = USB_DT_STRING;
  49015. + buf [2] = (u8) table->language;
  49016. + buf [3] = (u8) (table->language >> 8);
  49017. + return 4;
  49018. + }
  49019. + for (s = table->strings; s && s->s; s++)
  49020. + if (s->id == id)
  49021. + break;
  49022. +
  49023. + /* unrecognized: stall. */
  49024. + if (!s || !s->s)
  49025. + return -EINVAL;
  49026. +
  49027. + /* string descriptors have length, tag, then UTF16-LE text */
  49028. + len = min ((size_t) 126, strlen (s->s));
  49029. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  49030. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  49031. + if (len < 0)
  49032. + return -EINVAL;
  49033. + buf [0] = (len + 1) * 2;
  49034. + buf [1] = USB_DT_STRING;
  49035. + return buf [0];
  49036. +}
  49037. +
  49038. +
  49039. +/*-------------------------------------------------------------------------*/
  49040. +/*-------------------------------------------------------------------------*/
  49041. +
  49042. +
  49043. +/**
  49044. + * usb_descriptor_fillbuf - fill buffer with descriptors
  49045. + * @buf: Buffer to be filled
  49046. + * @buflen: Size of buf
  49047. + * @src: Array of descriptor pointers, terminated by null pointer.
  49048. + *
  49049. + * Copies descriptors into the buffer, returning the length or a
  49050. + * negative error code if they can't all be copied. Useful when
  49051. + * assembling descriptors for an associated set of interfaces used
  49052. + * as part of configuring a composite device; or in other cases where
  49053. + * sets of descriptors need to be marshaled.
  49054. + */
  49055. +int
  49056. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  49057. + const struct usb_descriptor_header **src)
  49058. +{
  49059. + u8 *dest = buf;
  49060. +
  49061. + if (!src)
  49062. + return -EINVAL;
  49063. +
  49064. + /* fill buffer from src[] until null descriptor ptr */
  49065. + for (; 0 != *src; src++) {
  49066. + unsigned len = (*src)->bLength;
  49067. +
  49068. + if (len > buflen)
  49069. + return -EINVAL;
  49070. + memcpy(dest, *src, len);
  49071. + buflen -= len;
  49072. + dest += len;
  49073. + }
  49074. + return dest - (u8 *)buf;
  49075. +}
  49076. +
  49077. +
  49078. +/**
  49079. + * usb_gadget_config_buf - builts a complete configuration descriptor
  49080. + * @config: Header for the descriptor, including characteristics such
  49081. + * as power requirements and number of interfaces.
  49082. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  49083. + * endpoint, etc) defining all functions in this device configuration.
  49084. + * @buf: Buffer for the resulting configuration descriptor.
  49085. + * @length: Length of buffer. If this is not big enough to hold the
  49086. + * entire configuration descriptor, an error code will be returned.
  49087. + *
  49088. + * This copies descriptors into the response buffer, building a descriptor
  49089. + * for that configuration. It returns the buffer length or a negative
  49090. + * status code. The config.wTotalLength field is set to match the length
  49091. + * of the result, but other descriptor fields (including power usage and
  49092. + * interface count) must be set by the caller.
  49093. + *
  49094. + * Gadget drivers could use this when constructing a config descriptor
  49095. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  49096. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  49097. + */
  49098. +int usb_gadget_config_buf(
  49099. + const struct usb_config_descriptor *config,
  49100. + void *buf,
  49101. + unsigned length,
  49102. + const struct usb_descriptor_header **desc
  49103. +)
  49104. +{
  49105. + struct usb_config_descriptor *cp = buf;
  49106. + int len;
  49107. +
  49108. + /* config descriptor first */
  49109. + if (length < USB_DT_CONFIG_SIZE || !desc)
  49110. + return -EINVAL;
  49111. + *cp = *config;
  49112. +
  49113. + /* then interface/endpoint/class/vendor/... */
  49114. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  49115. + length - USB_DT_CONFIG_SIZE, desc);
  49116. + if (len < 0)
  49117. + return len;
  49118. + len += USB_DT_CONFIG_SIZE;
  49119. + if (len > 0xffff)
  49120. + return -EINVAL;
  49121. +
  49122. + /* patch up the config descriptor */
  49123. + cp->bLength = USB_DT_CONFIG_SIZE;
  49124. + cp->bDescriptorType = USB_DT_CONFIG;
  49125. + cp->wTotalLength = cpu_to_le16(len);
  49126. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  49127. + return len;
  49128. +}
  49129. +
  49130. +/*-------------------------------------------------------------------------*/
  49131. +/*-------------------------------------------------------------------------*/
  49132. +
  49133. +
  49134. +#define RBUF_LEN (1024*1024)
  49135. +static int rbuf_start;
  49136. +static int rbuf_len;
  49137. +static __u8 rbuf[RBUF_LEN];
  49138. +
  49139. +/*-------------------------------------------------------------------------*/
  49140. +
  49141. +#define DRIVER_VERSION "St Patrick's Day 2004"
  49142. +
  49143. +static const char shortname [] = "zero";
  49144. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  49145. +
  49146. +static const char source_sink [] = "source and sink data";
  49147. +static const char loopback [] = "loop input to output";
  49148. +
  49149. +/*-------------------------------------------------------------------------*/
  49150. +
  49151. +/*
  49152. + * driver assumes self-powered hardware, and
  49153. + * has no way for users to trigger remote wakeup.
  49154. + *
  49155. + * this version autoconfigures as much as possible,
  49156. + * which is reasonable for most "bulk-only" drivers.
  49157. + */
  49158. +static const char *EP_IN_NAME; /* source */
  49159. +static const char *EP_OUT_NAME; /* sink */
  49160. +
  49161. +/*-------------------------------------------------------------------------*/
  49162. +
  49163. +/* big enough to hold our biggest descriptor */
  49164. +#define USB_BUFSIZ 512
  49165. +
  49166. +struct zero_dev {
  49167. + spinlock_t lock;
  49168. + struct usb_gadget *gadget;
  49169. + struct usb_request *req; /* for control responses */
  49170. +
  49171. + /* when configured, we have one of two configs:
  49172. + * - source data (in to host) and sink it (out from host)
  49173. + * - or loop it back (out from host back in to host)
  49174. + */
  49175. + u8 config;
  49176. + struct usb_ep *in_ep, *out_ep;
  49177. +
  49178. + /* autoresume timer */
  49179. + struct timer_list resume;
  49180. +};
  49181. +
  49182. +#define xprintk(d,level,fmt,args...) \
  49183. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  49184. +
  49185. +#ifdef DEBUG
  49186. +#define DBG(dev,fmt,args...) \
  49187. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  49188. +#else
  49189. +#define DBG(dev,fmt,args...) \
  49190. + do { } while (0)
  49191. +#endif /* DEBUG */
  49192. +
  49193. +#ifdef VERBOSE
  49194. +#define VDBG DBG
  49195. +#else
  49196. +#define VDBG(dev,fmt,args...) \
  49197. + do { } while (0)
  49198. +#endif /* VERBOSE */
  49199. +
  49200. +#define ERROR(dev,fmt,args...) \
  49201. + xprintk(dev , KERN_ERR , fmt , ## args)
  49202. +#define WARN(dev,fmt,args...) \
  49203. + xprintk(dev , KERN_WARNING , fmt , ## args)
  49204. +#define INFO(dev,fmt,args...) \
  49205. + xprintk(dev , KERN_INFO , fmt , ## args)
  49206. +
  49207. +/*-------------------------------------------------------------------------*/
  49208. +
  49209. +static unsigned buflen = 4096;
  49210. +static unsigned qlen = 32;
  49211. +static unsigned pattern = 0;
  49212. +
  49213. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  49214. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  49215. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  49216. +
  49217. +/*
  49218. + * if it's nonzero, autoresume says how many seconds to wait
  49219. + * before trying to wake up the host after suspend.
  49220. + */
  49221. +static unsigned autoresume = 0;
  49222. +module_param (autoresume, uint, 0);
  49223. +
  49224. +/*
  49225. + * Normally the "loopback" configuration is second (index 1) so
  49226. + * it's not the default. Here's where to change that order, to
  49227. + * work better with hosts where config changes are problematic.
  49228. + * Or controllers (like superh) that only support one config.
  49229. + */
  49230. +static int loopdefault = 0;
  49231. +
  49232. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  49233. +
  49234. +/*-------------------------------------------------------------------------*/
  49235. +
  49236. +/* Thanks to NetChip Technologies for donating this product ID.
  49237. + *
  49238. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  49239. + * Instead: allocate your own, using normal USB-IF procedures.
  49240. + */
  49241. +#ifndef CONFIG_USB_ZERO_HNPTEST
  49242. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  49243. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  49244. +#else
  49245. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  49246. +#define DRIVER_PRODUCT_NUM 0xbadd
  49247. +#endif
  49248. +
  49249. +/*-------------------------------------------------------------------------*/
  49250. +
  49251. +/*
  49252. + * DESCRIPTORS ... most are static, but strings and (full)
  49253. + * configuration descriptors are built on demand.
  49254. + */
  49255. +
  49256. +/*
  49257. +#define STRING_MANUFACTURER 25
  49258. +#define STRING_PRODUCT 42
  49259. +#define STRING_SERIAL 101
  49260. +*/
  49261. +#define STRING_MANUFACTURER 1
  49262. +#define STRING_PRODUCT 2
  49263. +#define STRING_SERIAL 3
  49264. +
  49265. +#define STRING_SOURCE_SINK 250
  49266. +#define STRING_LOOPBACK 251
  49267. +
  49268. +/*
  49269. + * This device advertises two configurations; these numbers work
  49270. + * on a pxa250 as well as more flexible hardware.
  49271. + */
  49272. +#define CONFIG_SOURCE_SINK 3
  49273. +#define CONFIG_LOOPBACK 2
  49274. +
  49275. +/*
  49276. +static struct usb_device_descriptor
  49277. +device_desc = {
  49278. + .bLength = sizeof device_desc,
  49279. + .bDescriptorType = USB_DT_DEVICE,
  49280. +
  49281. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49282. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49283. +
  49284. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  49285. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  49286. + .iManufacturer = STRING_MANUFACTURER,
  49287. + .iProduct = STRING_PRODUCT,
  49288. + .iSerialNumber = STRING_SERIAL,
  49289. + .bNumConfigurations = 2,
  49290. +};
  49291. +*/
  49292. +static struct usb_device_descriptor
  49293. +device_desc = {
  49294. + .bLength = sizeof device_desc,
  49295. + .bDescriptorType = USB_DT_DEVICE,
  49296. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  49297. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  49298. + .bDeviceSubClass = 0,
  49299. + .bDeviceProtocol = 0,
  49300. + .bMaxPacketSize0 = 64,
  49301. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  49302. + .idVendor = __constant_cpu_to_le16 (0x0499),
  49303. + .idProduct = __constant_cpu_to_le16 (0x3002),
  49304. + .iManufacturer = STRING_MANUFACTURER,
  49305. + .iProduct = STRING_PRODUCT,
  49306. + .iSerialNumber = STRING_SERIAL,
  49307. + .bNumConfigurations = 1,
  49308. +};
  49309. +
  49310. +static struct usb_config_descriptor
  49311. +z_config = {
  49312. + .bLength = sizeof z_config,
  49313. + .bDescriptorType = USB_DT_CONFIG,
  49314. +
  49315. + /* compute wTotalLength on the fly */
  49316. + .bNumInterfaces = 2,
  49317. + .bConfigurationValue = 1,
  49318. + .iConfiguration = 0,
  49319. + .bmAttributes = 0x40,
  49320. + .bMaxPower = 0, /* self-powered */
  49321. +};
  49322. +
  49323. +
  49324. +static struct usb_otg_descriptor
  49325. +otg_descriptor = {
  49326. + .bLength = sizeof otg_descriptor,
  49327. + .bDescriptorType = USB_DT_OTG,
  49328. +
  49329. + .bmAttributes = USB_OTG_SRP,
  49330. +};
  49331. +
  49332. +/* one interface in each configuration */
  49333. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49334. +
  49335. +/*
  49336. + * usb 2.0 devices need to expose both high speed and full speed
  49337. + * descriptors, unless they only run at full speed.
  49338. + *
  49339. + * that means alternate endpoint descriptors (bigger packets)
  49340. + * and a "device qualifier" ... plus more construction options
  49341. + * for the config descriptor.
  49342. + */
  49343. +
  49344. +static struct usb_qualifier_descriptor
  49345. +dev_qualifier = {
  49346. + .bLength = sizeof dev_qualifier,
  49347. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  49348. +
  49349. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49350. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49351. +
  49352. + .bNumConfigurations = 2,
  49353. +};
  49354. +
  49355. +
  49356. +struct usb_cs_as_general_descriptor {
  49357. + __u8 bLength;
  49358. + __u8 bDescriptorType;
  49359. +
  49360. + __u8 bDescriptorSubType;
  49361. + __u8 bTerminalLink;
  49362. + __u8 bDelay;
  49363. + __u16 wFormatTag;
  49364. +} __attribute__ ((packed));
  49365. +
  49366. +struct usb_cs_as_format_descriptor {
  49367. + __u8 bLength;
  49368. + __u8 bDescriptorType;
  49369. +
  49370. + __u8 bDescriptorSubType;
  49371. + __u8 bFormatType;
  49372. + __u8 bNrChannels;
  49373. + __u8 bSubframeSize;
  49374. + __u8 bBitResolution;
  49375. + __u8 bSamfreqType;
  49376. + __u8 tLowerSamFreq[3];
  49377. + __u8 tUpperSamFreq[3];
  49378. +} __attribute__ ((packed));
  49379. +
  49380. +static const struct usb_interface_descriptor
  49381. +z_audio_control_if_desc = {
  49382. + .bLength = sizeof z_audio_control_if_desc,
  49383. + .bDescriptorType = USB_DT_INTERFACE,
  49384. + .bInterfaceNumber = 0,
  49385. + .bAlternateSetting = 0,
  49386. + .bNumEndpoints = 0,
  49387. + .bInterfaceClass = USB_CLASS_AUDIO,
  49388. + .bInterfaceSubClass = 0x1,
  49389. + .bInterfaceProtocol = 0,
  49390. + .iInterface = 0,
  49391. +};
  49392. +
  49393. +static const struct usb_interface_descriptor
  49394. +z_audio_if_desc = {
  49395. + .bLength = sizeof z_audio_if_desc,
  49396. + .bDescriptorType = USB_DT_INTERFACE,
  49397. + .bInterfaceNumber = 1,
  49398. + .bAlternateSetting = 0,
  49399. + .bNumEndpoints = 0,
  49400. + .bInterfaceClass = USB_CLASS_AUDIO,
  49401. + .bInterfaceSubClass = 0x2,
  49402. + .bInterfaceProtocol = 0,
  49403. + .iInterface = 0,
  49404. +};
  49405. +
  49406. +static const struct usb_interface_descriptor
  49407. +z_audio_if_desc2 = {
  49408. + .bLength = sizeof z_audio_if_desc,
  49409. + .bDescriptorType = USB_DT_INTERFACE,
  49410. + .bInterfaceNumber = 1,
  49411. + .bAlternateSetting = 1,
  49412. + .bNumEndpoints = 1,
  49413. + .bInterfaceClass = USB_CLASS_AUDIO,
  49414. + .bInterfaceSubClass = 0x2,
  49415. + .bInterfaceProtocol = 0,
  49416. + .iInterface = 0,
  49417. +};
  49418. +
  49419. +static const struct usb_cs_as_general_descriptor
  49420. +z_audio_cs_as_if_desc = {
  49421. + .bLength = 7,
  49422. + .bDescriptorType = 0x24,
  49423. +
  49424. + .bDescriptorSubType = 0x01,
  49425. + .bTerminalLink = 0x01,
  49426. + .bDelay = 0x0,
  49427. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  49428. +};
  49429. +
  49430. +
  49431. +static const struct usb_cs_as_format_descriptor
  49432. +z_audio_cs_as_format_desc = {
  49433. + .bLength = 0xe,
  49434. + .bDescriptorType = 0x24,
  49435. +
  49436. + .bDescriptorSubType = 2,
  49437. + .bFormatType = 1,
  49438. + .bNrChannels = 1,
  49439. + .bSubframeSize = 1,
  49440. + .bBitResolution = 8,
  49441. + .bSamfreqType = 0,
  49442. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  49443. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  49444. +};
  49445. +
  49446. +static const struct usb_endpoint_descriptor
  49447. +z_iso_ep = {
  49448. + .bLength = 0x09,
  49449. + .bDescriptorType = 0x05,
  49450. + .bEndpointAddress = 0x04,
  49451. + .bmAttributes = 0x09,
  49452. + .wMaxPacketSize = 0x0038,
  49453. + .bInterval = 0x01,
  49454. + .bRefresh = 0x00,
  49455. + .bSynchAddress = 0x00,
  49456. +};
  49457. +
  49458. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49459. +
  49460. +// 9 bytes
  49461. +static char z_ac_interface_header_desc[] =
  49462. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  49463. +
  49464. +// 12 bytes
  49465. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  49466. + 0x03, 0x00, 0x00, 0x00};
  49467. +// 13 bytes
  49468. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  49469. + 0x02, 0x00, 0x02, 0x00, 0x00};
  49470. +// 9 bytes
  49471. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  49472. + 0x00};
  49473. +
  49474. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  49475. + 0x00};
  49476. +
  49477. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49478. +
  49479. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  49480. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49481. +
  49482. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49483. + 0x00};
  49484. +
  49485. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49486. +
  49487. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  49488. + 0x00};
  49489. +
  49490. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49491. +
  49492. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  49493. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49494. +
  49495. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49496. + 0x00};
  49497. +
  49498. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49499. +
  49500. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  49501. + 0x00};
  49502. +
  49503. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49504. +
  49505. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  49506. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49507. +
  49508. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  49509. + 0x00};
  49510. +
  49511. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49512. +
  49513. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  49514. + 0x00};
  49515. +
  49516. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49517. +
  49518. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  49519. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49520. +
  49521. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  49522. + 0x00};
  49523. +
  49524. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49525. +
  49526. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  49527. + 0x00};
  49528. +
  49529. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49530. +
  49531. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  49532. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49533. +
  49534. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  49535. + 0x00};
  49536. +
  49537. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49538. +
  49539. +
  49540. +
  49541. +static const struct usb_descriptor_header *z_function [] = {
  49542. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  49543. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  49544. + (struct usb_descriptor_header *) &z_0,
  49545. + (struct usb_descriptor_header *) &z_1,
  49546. + (struct usb_descriptor_header *) &z_2,
  49547. + (struct usb_descriptor_header *) &z_audio_if_desc,
  49548. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  49549. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  49550. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  49551. + (struct usb_descriptor_header *) &z_iso_ep,
  49552. + (struct usb_descriptor_header *) &z_iso_ep2,
  49553. + (struct usb_descriptor_header *) &za_0,
  49554. + (struct usb_descriptor_header *) &za_1,
  49555. + (struct usb_descriptor_header *) &za_2,
  49556. + (struct usb_descriptor_header *) &za_3,
  49557. + (struct usb_descriptor_header *) &za_4,
  49558. + (struct usb_descriptor_header *) &za_5,
  49559. + (struct usb_descriptor_header *) &za_6,
  49560. + (struct usb_descriptor_header *) &za_7,
  49561. + (struct usb_descriptor_header *) &za_8,
  49562. + (struct usb_descriptor_header *) &za_9,
  49563. + (struct usb_descriptor_header *) &za_10,
  49564. + (struct usb_descriptor_header *) &za_11,
  49565. + (struct usb_descriptor_header *) &za_12,
  49566. + (struct usb_descriptor_header *) &za_13,
  49567. + (struct usb_descriptor_header *) &za_14,
  49568. + (struct usb_descriptor_header *) &za_15,
  49569. + (struct usb_descriptor_header *) &za_16,
  49570. + (struct usb_descriptor_header *) &za_17,
  49571. + (struct usb_descriptor_header *) &za_18,
  49572. + (struct usb_descriptor_header *) &za_19,
  49573. + (struct usb_descriptor_header *) &za_20,
  49574. + (struct usb_descriptor_header *) &za_21,
  49575. + (struct usb_descriptor_header *) &za_22,
  49576. + (struct usb_descriptor_header *) &za_23,
  49577. + (struct usb_descriptor_header *) &za_24,
  49578. + NULL,
  49579. +};
  49580. +
  49581. +/* maxpacket and other transfer characteristics vary by speed. */
  49582. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  49583. +
  49584. +#else
  49585. +
  49586. +/* if there's no high speed support, maxpacket doesn't change. */
  49587. +#define ep_desc(g,hs,fs) fs
  49588. +
  49589. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  49590. +
  49591. +static char manufacturer [40];
  49592. +//static char serial [40];
  49593. +static char serial [] = "Ser 00 em";
  49594. +
  49595. +/* static strings, in UTF-8 */
  49596. +static struct usb_string strings [] = {
  49597. + { STRING_MANUFACTURER, manufacturer, },
  49598. + { STRING_PRODUCT, longname, },
  49599. + { STRING_SERIAL, serial, },
  49600. + { STRING_LOOPBACK, loopback, },
  49601. + { STRING_SOURCE_SINK, source_sink, },
  49602. + { } /* end of list */
  49603. +};
  49604. +
  49605. +static struct usb_gadget_strings stringtab = {
  49606. + .language = 0x0409, /* en-us */
  49607. + .strings = strings,
  49608. +};
  49609. +
  49610. +/*
  49611. + * config descriptors are also handcrafted. these must agree with code
  49612. + * that sets configurations, and with code managing interfaces and their
  49613. + * altsettings. other complexity may come from:
  49614. + *
  49615. + * - high speed support, including "other speed config" rules
  49616. + * - multiple configurations
  49617. + * - interfaces with alternate settings
  49618. + * - embedded class or vendor-specific descriptors
  49619. + *
  49620. + * this handles high speed, and has a second config that could as easily
  49621. + * have been an alternate interface setting (on most hardware).
  49622. + *
  49623. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  49624. + * should include an altsetting to test interrupt transfers, including
  49625. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  49626. + * device?)
  49627. + */
  49628. +static int
  49629. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  49630. +{
  49631. + int len;
  49632. + const struct usb_descriptor_header **function;
  49633. +
  49634. + function = z_function;
  49635. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  49636. + if (len < 0)
  49637. + return len;
  49638. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  49639. + return len;
  49640. +}
  49641. +
  49642. +/*-------------------------------------------------------------------------*/
  49643. +
  49644. +static struct usb_request *
  49645. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  49646. +{
  49647. + struct usb_request *req;
  49648. +
  49649. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  49650. + if (req) {
  49651. + req->length = length;
  49652. + req->buf = usb_ep_alloc_buffer (ep, length,
  49653. + &req->dma, GFP_ATOMIC);
  49654. + if (!req->buf) {
  49655. + usb_ep_free_request (ep, req);
  49656. + req = NULL;
  49657. + }
  49658. + }
  49659. + return req;
  49660. +}
  49661. +
  49662. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  49663. +{
  49664. + if (req->buf)
  49665. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  49666. + usb_ep_free_request (ep, req);
  49667. +}
  49668. +
  49669. +/*-------------------------------------------------------------------------*/
  49670. +
  49671. +/* optionally require specific source/sink data patterns */
  49672. +
  49673. +static int
  49674. +check_read_data (
  49675. + struct zero_dev *dev,
  49676. + struct usb_ep *ep,
  49677. + struct usb_request *req
  49678. +)
  49679. +{
  49680. + unsigned i;
  49681. + u8 *buf = req->buf;
  49682. +
  49683. + for (i = 0; i < req->actual; i++, buf++) {
  49684. + switch (pattern) {
  49685. + /* all-zeroes has no synchronization issues */
  49686. + case 0:
  49687. + if (*buf == 0)
  49688. + continue;
  49689. + break;
  49690. + /* mod63 stays in sync with short-terminated transfers,
  49691. + * or otherwise when host and gadget agree on how large
  49692. + * each usb transfer request should be. resync is done
  49693. + * with set_interface or set_config.
  49694. + */
  49695. + case 1:
  49696. + if (*buf == (u8)(i % 63))
  49697. + continue;
  49698. + break;
  49699. + }
  49700. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  49701. + usb_ep_set_halt (ep);
  49702. + return -EINVAL;
  49703. + }
  49704. + return 0;
  49705. +}
  49706. +
  49707. +/*-------------------------------------------------------------------------*/
  49708. +
  49709. +static void zero_reset_config (struct zero_dev *dev)
  49710. +{
  49711. + if (dev->config == 0)
  49712. + return;
  49713. +
  49714. + DBG (dev, "reset config\n");
  49715. +
  49716. + /* just disable endpoints, forcing completion of pending i/o.
  49717. + * all our completion handlers free their requests in this case.
  49718. + */
  49719. + if (dev->in_ep) {
  49720. + usb_ep_disable (dev->in_ep);
  49721. + dev->in_ep = NULL;
  49722. + }
  49723. + if (dev->out_ep) {
  49724. + usb_ep_disable (dev->out_ep);
  49725. + dev->out_ep = NULL;
  49726. + }
  49727. + dev->config = 0;
  49728. + del_timer (&dev->resume);
  49729. +}
  49730. +
  49731. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  49732. +
  49733. +static void
  49734. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  49735. +{
  49736. + struct zero_dev *dev = ep->driver_data;
  49737. + int status = req->status;
  49738. + int i, j;
  49739. +
  49740. + switch (status) {
  49741. +
  49742. + case 0: /* normal completion? */
  49743. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  49744. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  49745. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  49746. + rbuf[j] = ((__u8*)req->buf)[i];
  49747. + j++;
  49748. + if (j >= RBUF_LEN) j=0;
  49749. + }
  49750. + rbuf_start = j;
  49751. + //printk ("\n\n");
  49752. +
  49753. + if (rbuf_len < RBUF_LEN) {
  49754. + rbuf_len += req->actual;
  49755. + if (rbuf_len > RBUF_LEN) {
  49756. + rbuf_len = RBUF_LEN;
  49757. + }
  49758. + }
  49759. +
  49760. + break;
  49761. +
  49762. + /* this endpoint is normally active while we're configured */
  49763. + case -ECONNABORTED: /* hardware forced ep reset */
  49764. + case -ECONNRESET: /* request dequeued */
  49765. + case -ESHUTDOWN: /* disconnect from host */
  49766. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  49767. + req->actual, req->length);
  49768. + if (ep == dev->out_ep)
  49769. + check_read_data (dev, ep, req);
  49770. + free_ep_req (ep, req);
  49771. + return;
  49772. +
  49773. + case -EOVERFLOW: /* buffer overrun on read means that
  49774. + * we didn't provide a big enough
  49775. + * buffer.
  49776. + */
  49777. + default:
  49778. +#if 1
  49779. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  49780. + status, req->actual, req->length);
  49781. +#endif
  49782. + case -EREMOTEIO: /* short read */
  49783. + break;
  49784. + }
  49785. +
  49786. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  49787. + if (status) {
  49788. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  49789. + ep->name, req->length, status);
  49790. + usb_ep_set_halt (ep);
  49791. + /* FIXME recover later ... somehow */
  49792. + }
  49793. +}
  49794. +
  49795. +static struct usb_request *
  49796. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  49797. +{
  49798. + struct usb_request *req;
  49799. + int status;
  49800. +
  49801. + req = alloc_ep_req (ep, 512);
  49802. + if (!req)
  49803. + return NULL;
  49804. +
  49805. + req->complete = zero_isoc_complete;
  49806. +
  49807. + status = usb_ep_queue (ep, req, gfp_flags);
  49808. + if (status) {
  49809. + struct zero_dev *dev = ep->driver_data;
  49810. +
  49811. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  49812. + free_ep_req (ep, req);
  49813. + req = NULL;
  49814. + }
  49815. +
  49816. + return req;
  49817. +}
  49818. +
  49819. +/* change our operational config. this code must agree with the code
  49820. + * that returns config descriptors, and altsetting code.
  49821. + *
  49822. + * it's also responsible for power management interactions. some
  49823. + * configurations might not work with our current power sources.
  49824. + *
  49825. + * note that some device controller hardware will constrain what this
  49826. + * code can do, perhaps by disallowing more than one configuration or
  49827. + * by limiting configuration choices (like the pxa2xx).
  49828. + */
  49829. +static int
  49830. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  49831. +{
  49832. + int result = 0;
  49833. + struct usb_gadget *gadget = dev->gadget;
  49834. + const struct usb_endpoint_descriptor *d;
  49835. + struct usb_ep *ep;
  49836. +
  49837. + if (number == dev->config)
  49838. + return 0;
  49839. +
  49840. + zero_reset_config (dev);
  49841. +
  49842. + gadget_for_each_ep (ep, gadget) {
  49843. +
  49844. + if (strcmp (ep->name, "ep4") == 0) {
  49845. +
  49846. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  49847. + result = usb_ep_enable (ep, d);
  49848. +
  49849. + if (result == 0) {
  49850. + ep->driver_data = dev;
  49851. + dev->in_ep = ep;
  49852. +
  49853. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  49854. +
  49855. + dev->in_ep = ep;
  49856. + continue;
  49857. + }
  49858. +
  49859. + usb_ep_disable (ep);
  49860. + result = -EIO;
  49861. + }
  49862. + }
  49863. +
  49864. + }
  49865. +
  49866. + dev->config = number;
  49867. + return result;
  49868. +}
  49869. +
  49870. +/*-------------------------------------------------------------------------*/
  49871. +
  49872. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  49873. +{
  49874. + if (req->status || req->actual != req->length)
  49875. + DBG ((struct zero_dev *) ep->driver_data,
  49876. + "setup complete --> %d, %d/%d\n",
  49877. + req->status, req->actual, req->length);
  49878. +}
  49879. +
  49880. +/*
  49881. + * The setup() callback implements all the ep0 functionality that's
  49882. + * not handled lower down, in hardware or the hardware driver (like
  49883. + * device and endpoint feature flags, and their status). It's all
  49884. + * housekeeping for the gadget function we're implementing. Most of
  49885. + * the work is in config-specific setup.
  49886. + */
  49887. +static int
  49888. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  49889. +{
  49890. + struct zero_dev *dev = get_gadget_data (gadget);
  49891. + struct usb_request *req = dev->req;
  49892. + int value = -EOPNOTSUPP;
  49893. +
  49894. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  49895. + * but config change events will reconfigure hardware.
  49896. + */
  49897. + req->zero = 0;
  49898. + switch (ctrl->bRequest) {
  49899. +
  49900. + case USB_REQ_GET_DESCRIPTOR:
  49901. +
  49902. + switch (ctrl->wValue >> 8) {
  49903. +
  49904. + case USB_DT_DEVICE:
  49905. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  49906. + memcpy (req->buf, &device_desc, value);
  49907. + break;
  49908. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49909. + case USB_DT_DEVICE_QUALIFIER:
  49910. + if (!gadget->is_dualspeed)
  49911. + break;
  49912. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  49913. + memcpy (req->buf, &dev_qualifier, value);
  49914. + break;
  49915. +
  49916. + case USB_DT_OTHER_SPEED_CONFIG:
  49917. + if (!gadget->is_dualspeed)
  49918. + break;
  49919. + // FALLTHROUGH
  49920. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  49921. + case USB_DT_CONFIG:
  49922. + value = config_buf (gadget, req->buf,
  49923. + ctrl->wValue >> 8,
  49924. + ctrl->wValue & 0xff);
  49925. + if (value >= 0)
  49926. + value = min (ctrl->wLength, (u16) value);
  49927. + break;
  49928. +
  49929. + case USB_DT_STRING:
  49930. + /* wIndex == language code.
  49931. + * this driver only handles one language, you can
  49932. + * add string tables for other languages, using
  49933. + * any UTF-8 characters
  49934. + */
  49935. + value = usb_gadget_get_string (&stringtab,
  49936. + ctrl->wValue & 0xff, req->buf);
  49937. + if (value >= 0) {
  49938. + value = min (ctrl->wLength, (u16) value);
  49939. + }
  49940. + break;
  49941. + }
  49942. + break;
  49943. +
  49944. + /* currently two configs, two speeds */
  49945. + case USB_REQ_SET_CONFIGURATION:
  49946. + if (ctrl->bRequestType != 0)
  49947. + goto unknown;
  49948. +
  49949. + spin_lock (&dev->lock);
  49950. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  49951. + spin_unlock (&dev->lock);
  49952. + break;
  49953. + case USB_REQ_GET_CONFIGURATION:
  49954. + if (ctrl->bRequestType != USB_DIR_IN)
  49955. + goto unknown;
  49956. + *(u8 *)req->buf = dev->config;
  49957. + value = min (ctrl->wLength, (u16) 1);
  49958. + break;
  49959. +
  49960. + /* until we add altsetting support, or other interfaces,
  49961. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  49962. + * and already killed pending endpoint I/O.
  49963. + */
  49964. + case USB_REQ_SET_INTERFACE:
  49965. +
  49966. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  49967. + goto unknown;
  49968. + spin_lock (&dev->lock);
  49969. + if (dev->config) {
  49970. + u8 config = dev->config;
  49971. +
  49972. + /* resets interface configuration, forgets about
  49973. + * previous transaction state (queued bufs, etc)
  49974. + * and re-inits endpoint state (toggle etc)
  49975. + * no response queued, just zero status == success.
  49976. + * if we had more than one interface we couldn't
  49977. + * use this "reset the config" shortcut.
  49978. + */
  49979. + zero_reset_config (dev);
  49980. + zero_set_config (dev, config, GFP_ATOMIC);
  49981. + value = 0;
  49982. + }
  49983. + spin_unlock (&dev->lock);
  49984. + break;
  49985. + case USB_REQ_GET_INTERFACE:
  49986. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  49987. + value = ctrl->wLength;
  49988. + break;
  49989. + }
  49990. + else {
  49991. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  49992. + goto unknown;
  49993. + if (!dev->config)
  49994. + break;
  49995. + if (ctrl->wIndex != 0) {
  49996. + value = -EDOM;
  49997. + break;
  49998. + }
  49999. + *(u8 *)req->buf = 0;
  50000. + value = min (ctrl->wLength, (u16) 1);
  50001. + }
  50002. + break;
  50003. +
  50004. + /*
  50005. + * These are the same vendor-specific requests supported by
  50006. + * Intel's USB 2.0 compliance test devices. We exceed that
  50007. + * device spec by allowing multiple-packet requests.
  50008. + */
  50009. + case 0x5b: /* control WRITE test -- fill the buffer */
  50010. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  50011. + goto unknown;
  50012. + if (ctrl->wValue || ctrl->wIndex)
  50013. + break;
  50014. + /* just read that many bytes into the buffer */
  50015. + if (ctrl->wLength > USB_BUFSIZ)
  50016. + break;
  50017. + value = ctrl->wLength;
  50018. + break;
  50019. + case 0x5c: /* control READ test -- return the buffer */
  50020. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  50021. + goto unknown;
  50022. + if (ctrl->wValue || ctrl->wIndex)
  50023. + break;
  50024. + /* expect those bytes are still in the buffer; send back */
  50025. + if (ctrl->wLength > USB_BUFSIZ
  50026. + || ctrl->wLength != req->length)
  50027. + break;
  50028. + value = ctrl->wLength;
  50029. + break;
  50030. +
  50031. + case 0x01: // SET_CUR
  50032. + case 0x02:
  50033. + case 0x03:
  50034. + case 0x04:
  50035. + case 0x05:
  50036. + value = ctrl->wLength;
  50037. + break;
  50038. + case 0x81:
  50039. + switch (ctrl->wValue) {
  50040. + case 0x0201:
  50041. + case 0x0202:
  50042. + ((u8*)req->buf)[0] = 0x00;
  50043. + ((u8*)req->buf)[1] = 0xe3;
  50044. + break;
  50045. + case 0x0300:
  50046. + case 0x0500:
  50047. + ((u8*)req->buf)[0] = 0x00;
  50048. + break;
  50049. + }
  50050. + //((u8*)req->buf)[0] = 0x81;
  50051. + //((u8*)req->buf)[1] = 0x81;
  50052. + value = ctrl->wLength;
  50053. + break;
  50054. + case 0x82:
  50055. + switch (ctrl->wValue) {
  50056. + case 0x0201:
  50057. + case 0x0202:
  50058. + ((u8*)req->buf)[0] = 0x00;
  50059. + ((u8*)req->buf)[1] = 0xc3;
  50060. + break;
  50061. + case 0x0300:
  50062. + case 0x0500:
  50063. + ((u8*)req->buf)[0] = 0x00;
  50064. + break;
  50065. + }
  50066. + //((u8*)req->buf)[0] = 0x82;
  50067. + //((u8*)req->buf)[1] = 0x82;
  50068. + value = ctrl->wLength;
  50069. + break;
  50070. + case 0x83:
  50071. + switch (ctrl->wValue) {
  50072. + case 0x0201:
  50073. + case 0x0202:
  50074. + ((u8*)req->buf)[0] = 0x00;
  50075. + ((u8*)req->buf)[1] = 0x00;
  50076. + break;
  50077. + case 0x0300:
  50078. + ((u8*)req->buf)[0] = 0x60;
  50079. + break;
  50080. + case 0x0500:
  50081. + ((u8*)req->buf)[0] = 0x18;
  50082. + break;
  50083. + }
  50084. + //((u8*)req->buf)[0] = 0x83;
  50085. + //((u8*)req->buf)[1] = 0x83;
  50086. + value = ctrl->wLength;
  50087. + break;
  50088. + case 0x84:
  50089. + switch (ctrl->wValue) {
  50090. + case 0x0201:
  50091. + case 0x0202:
  50092. + ((u8*)req->buf)[0] = 0x00;
  50093. + ((u8*)req->buf)[1] = 0x01;
  50094. + break;
  50095. + case 0x0300:
  50096. + case 0x0500:
  50097. + ((u8*)req->buf)[0] = 0x08;
  50098. + break;
  50099. + }
  50100. + //((u8*)req->buf)[0] = 0x84;
  50101. + //((u8*)req->buf)[1] = 0x84;
  50102. + value = ctrl->wLength;
  50103. + break;
  50104. + case 0x85:
  50105. + ((u8*)req->buf)[0] = 0x85;
  50106. + ((u8*)req->buf)[1] = 0x85;
  50107. + value = ctrl->wLength;
  50108. + break;
  50109. +
  50110. +
  50111. + default:
  50112. +unknown:
  50113. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  50114. + ctrl->bRequestType, ctrl->bRequest,
  50115. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  50116. + }
  50117. +
  50118. + /* respond with data transfer before status phase? */
  50119. + if (value >= 0) {
  50120. + req->length = value;
  50121. + req->zero = value < ctrl->wLength
  50122. + && (value % gadget->ep0->maxpacket) == 0;
  50123. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  50124. + if (value < 0) {
  50125. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  50126. + req->status = 0;
  50127. + zero_setup_complete (gadget->ep0, req);
  50128. + }
  50129. + }
  50130. +
  50131. + /* device either stalls (value < 0) or reports success */
  50132. + return value;
  50133. +}
  50134. +
  50135. +static void
  50136. +zero_disconnect (struct usb_gadget *gadget)
  50137. +{
  50138. + struct zero_dev *dev = get_gadget_data (gadget);
  50139. + unsigned long flags;
  50140. +
  50141. + spin_lock_irqsave (&dev->lock, flags);
  50142. + zero_reset_config (dev);
  50143. +
  50144. + /* a more significant application might have some non-usb
  50145. + * activities to quiesce here, saving resources like power
  50146. + * or pushing the notification up a network stack.
  50147. + */
  50148. + spin_unlock_irqrestore (&dev->lock, flags);
  50149. +
  50150. + /* next we may get setup() calls to enumerate new connections;
  50151. + * or an unbind() during shutdown (including removing module).
  50152. + */
  50153. +}
  50154. +
  50155. +static void
  50156. +zero_autoresume (unsigned long _dev)
  50157. +{
  50158. + struct zero_dev *dev = (struct zero_dev *) _dev;
  50159. + int status;
  50160. +
  50161. + /* normally the host would be woken up for something
  50162. + * more significant than just a timer firing...
  50163. + */
  50164. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  50165. + status = usb_gadget_wakeup (dev->gadget);
  50166. + DBG (dev, "wakeup --> %d\n", status);
  50167. + }
  50168. +}
  50169. +
  50170. +/*-------------------------------------------------------------------------*/
  50171. +
  50172. +static void
  50173. +zero_unbind (struct usb_gadget *gadget)
  50174. +{
  50175. + struct zero_dev *dev = get_gadget_data (gadget);
  50176. +
  50177. + DBG (dev, "unbind\n");
  50178. +
  50179. + /* we've already been disconnected ... no i/o is active */
  50180. + if (dev->req)
  50181. + free_ep_req (gadget->ep0, dev->req);
  50182. + del_timer_sync (&dev->resume);
  50183. + kfree (dev);
  50184. + set_gadget_data (gadget, NULL);
  50185. +}
  50186. +
  50187. +static int
  50188. +zero_bind (struct usb_gadget *gadget)
  50189. +{
  50190. + struct zero_dev *dev;
  50191. + //struct usb_ep *ep;
  50192. +
  50193. + printk("binding\n");
  50194. + /*
  50195. + * DRIVER POLICY CHOICE: you may want to do this differently.
  50196. + * One thing to avoid is reusing a bcdDevice revision code
  50197. + * with different host-visible configurations or behavior
  50198. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  50199. + */
  50200. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  50201. +
  50202. +
  50203. + /* ok, we made sense of the hardware ... */
  50204. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  50205. + if (!dev)
  50206. + return -ENOMEM;
  50207. + memset (dev, 0, sizeof *dev);
  50208. + spin_lock_init (&dev->lock);
  50209. + dev->gadget = gadget;
  50210. + set_gadget_data (gadget, dev);
  50211. +
  50212. + /* preallocate control response and buffer */
  50213. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  50214. + if (!dev->req)
  50215. + goto enomem;
  50216. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  50217. + &dev->req->dma, GFP_KERNEL);
  50218. + if (!dev->req->buf)
  50219. + goto enomem;
  50220. +
  50221. + dev->req->complete = zero_setup_complete;
  50222. +
  50223. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  50224. +
  50225. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50226. + /* assume ep0 uses the same value for both speeds ... */
  50227. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  50228. +
  50229. + /* and that all endpoints are dual-speed */
  50230. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  50231. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  50232. +#endif
  50233. +
  50234. + usb_gadget_set_selfpowered (gadget);
  50235. +
  50236. + init_timer (&dev->resume);
  50237. + dev->resume.function = zero_autoresume;
  50238. + dev->resume.data = (unsigned long) dev;
  50239. +
  50240. + gadget->ep0->driver_data = dev;
  50241. +
  50242. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  50243. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  50244. + EP_OUT_NAME, EP_IN_NAME);
  50245. +
  50246. + snprintf (manufacturer, sizeof manufacturer,
  50247. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  50248. + gadget->name);
  50249. +
  50250. + return 0;
  50251. +
  50252. +enomem:
  50253. + zero_unbind (gadget);
  50254. + return -ENOMEM;
  50255. +}
  50256. +
  50257. +/*-------------------------------------------------------------------------*/
  50258. +
  50259. +static void
  50260. +zero_suspend (struct usb_gadget *gadget)
  50261. +{
  50262. + struct zero_dev *dev = get_gadget_data (gadget);
  50263. +
  50264. + if (gadget->speed == USB_SPEED_UNKNOWN)
  50265. + return;
  50266. +
  50267. + if (autoresume) {
  50268. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  50269. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  50270. + } else
  50271. + DBG (dev, "suspend\n");
  50272. +}
  50273. +
  50274. +static void
  50275. +zero_resume (struct usb_gadget *gadget)
  50276. +{
  50277. + struct zero_dev *dev = get_gadget_data (gadget);
  50278. +
  50279. + DBG (dev, "resume\n");
  50280. + del_timer (&dev->resume);
  50281. +}
  50282. +
  50283. +
  50284. +/*-------------------------------------------------------------------------*/
  50285. +
  50286. +static struct usb_gadget_driver zero_driver = {
  50287. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50288. + .speed = USB_SPEED_HIGH,
  50289. +#else
  50290. + .speed = USB_SPEED_FULL,
  50291. +#endif
  50292. + .function = (char *) longname,
  50293. + .bind = zero_bind,
  50294. + .unbind = zero_unbind,
  50295. +
  50296. + .setup = zero_setup,
  50297. + .disconnect = zero_disconnect,
  50298. +
  50299. + .suspend = zero_suspend,
  50300. + .resume = zero_resume,
  50301. +
  50302. + .driver = {
  50303. + .name = (char *) shortname,
  50304. + // .shutdown = ...
  50305. + // .suspend = ...
  50306. + // .resume = ...
  50307. + },
  50308. +};
  50309. +
  50310. +MODULE_AUTHOR ("David Brownell");
  50311. +MODULE_LICENSE ("Dual BSD/GPL");
  50312. +
  50313. +static struct proc_dir_entry *pdir, *pfile;
  50314. +
  50315. +static int isoc_read_data (char *page, char **start,
  50316. + off_t off, int count,
  50317. + int *eof, void *data)
  50318. +{
  50319. + int i;
  50320. + static int c = 0;
  50321. + static int done = 0;
  50322. + static int s = 0;
  50323. +
  50324. +/*
  50325. + printk ("\ncount: %d\n", count);
  50326. + printk ("rbuf_start: %d\n", rbuf_start);
  50327. + printk ("rbuf_len: %d\n", rbuf_len);
  50328. + printk ("off: %d\n", off);
  50329. + printk ("start: %p\n\n", *start);
  50330. +*/
  50331. + if (done) {
  50332. + c = 0;
  50333. + done = 0;
  50334. + *eof = 1;
  50335. + return 0;
  50336. + }
  50337. +
  50338. + if (c == 0) {
  50339. + if (rbuf_len == RBUF_LEN)
  50340. + s = rbuf_start;
  50341. + else s = 0;
  50342. + }
  50343. +
  50344. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  50345. + page[i] = rbuf[(c+s) % RBUF_LEN];
  50346. + }
  50347. + *start = page;
  50348. +
  50349. + if (c >= rbuf_len) {
  50350. + *eof = 1;
  50351. + done = 1;
  50352. + }
  50353. +
  50354. +
  50355. + return i;
  50356. +}
  50357. +
  50358. +static int __init init (void)
  50359. +{
  50360. +
  50361. + int retval = 0;
  50362. +
  50363. + pdir = proc_mkdir("isoc_test", NULL);
  50364. + if(pdir == NULL) {
  50365. + retval = -ENOMEM;
  50366. + printk("Error creating dir\n");
  50367. + goto done;
  50368. + }
  50369. + pdir->owner = THIS_MODULE;
  50370. +
  50371. + pfile = create_proc_read_entry("isoc_data",
  50372. + 0444, pdir,
  50373. + isoc_read_data,
  50374. + NULL);
  50375. + if (pfile == NULL) {
  50376. + retval = -ENOMEM;
  50377. + printk("Error creating file\n");
  50378. + goto no_file;
  50379. + }
  50380. + pfile->owner = THIS_MODULE;
  50381. +
  50382. + return usb_gadget_register_driver (&zero_driver);
  50383. +
  50384. + no_file:
  50385. + remove_proc_entry("isoc_data", NULL);
  50386. + done:
  50387. + return retval;
  50388. +}
  50389. +module_init (init);
  50390. +
  50391. +static void __exit cleanup (void)
  50392. +{
  50393. +
  50394. + usb_gadget_unregister_driver (&zero_driver);
  50395. +
  50396. + remove_proc_entry("isoc_data", pdir);
  50397. + remove_proc_entry("isoc_test", NULL);
  50398. +}
  50399. +module_exit (cleanup);
  50400. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  50401. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  50402. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-02-07 19:57:30.000000000 +0100
  50403. @@ -0,0 +1,142 @@
  50404. +/* ==========================================================================
  50405. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50406. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50407. + * otherwise expressly agreed to in writing between Synopsys and you.
  50408. + *
  50409. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50410. + * any End User Software License Agreement or Agreement for Licensed Product
  50411. + * with Synopsys or any supplement thereto. You are permitted to use and
  50412. + * redistribute this Software in source and binary forms, with or without
  50413. + * modification, provided that redistributions of source code must retain this
  50414. + * notice. You may not view, use, disclose, copy or distribute this file or
  50415. + * any information contained herein except pursuant to this license grant from
  50416. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50417. + * below, then you are not authorized to use the Software.
  50418. + *
  50419. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50420. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50421. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50422. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50423. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50424. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50425. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50426. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50427. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50428. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50429. + * DAMAGE.
  50430. + * ========================================================================== */
  50431. +
  50432. +#if !defined(__DWC_CFI_COMMON_H__)
  50433. +#define __DWC_CFI_COMMON_H__
  50434. +
  50435. +//#include <linux/types.h>
  50436. +
  50437. +/**
  50438. + * @file
  50439. + *
  50440. + * This file contains the CFI specific common constants, interfaces
  50441. + * (functions and macros) and structures for Linux. No PCD specific
  50442. + * data structure or definition is to be included in this file.
  50443. + *
  50444. + */
  50445. +
  50446. +/** This is a request for all Core Features */
  50447. +#define VEN_CORE_GET_FEATURES 0xB1
  50448. +
  50449. +/** This is a request to get the value of a specific Core Feature */
  50450. +#define VEN_CORE_GET_FEATURE 0xB2
  50451. +
  50452. +/** This command allows the host to set the value of a specific Core Feature */
  50453. +#define VEN_CORE_SET_FEATURE 0xB3
  50454. +
  50455. +/** This command allows the host to set the default values of
  50456. + * either all or any specific Core Feature
  50457. + */
  50458. +#define VEN_CORE_RESET_FEATURES 0xB4
  50459. +
  50460. +/** This command forces the PCD to write the deferred values of a Core Features */
  50461. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  50462. +
  50463. +/** This request reads a DWORD value from a register at the specified offset */
  50464. +#define VEN_CORE_READ_REGISTER 0xB6
  50465. +
  50466. +/** This request writes a DWORD value into a register at the specified offset */
  50467. +#define VEN_CORE_WRITE_REGISTER 0xB7
  50468. +
  50469. +/** This structure is the header of the Core Features dataset returned to
  50470. + * the Host
  50471. + */
  50472. +struct cfi_all_features_header {
  50473. +/** The features header structure length is */
  50474. +#define CFI_ALL_FEATURES_HDR_LEN 8
  50475. + /**
  50476. + * The total length of the features dataset returned to the Host
  50477. + */
  50478. + uint16_t wTotalLen;
  50479. +
  50480. + /**
  50481. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  50482. + * This field identifies the version of the CFI Specification with which
  50483. + * the device is compliant.
  50484. + */
  50485. + uint16_t wVersion;
  50486. +
  50487. + /** The ID of the Core */
  50488. + uint16_t wCoreID;
  50489. +#define CFI_CORE_ID_UDC 1
  50490. +#define CFI_CORE_ID_OTG 2
  50491. +#define CFI_CORE_ID_WUDEV 3
  50492. +
  50493. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  50494. + uint16_t wNumFeatures;
  50495. +} UPACKED;
  50496. +
  50497. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  50498. +
  50499. +/** This structure is a header of the Core Feature descriptor dataset returned to
  50500. + * the Host after the VEN_CORE_GET_FEATURES request
  50501. + */
  50502. +struct cfi_feature_desc_header {
  50503. +#define CFI_FEATURE_DESC_HDR_LEN 8
  50504. +
  50505. + /** The feature ID */
  50506. + uint16_t wFeatureID;
  50507. +
  50508. + /** Length of this feature descriptor in bytes - including the
  50509. + * length of the feature name string
  50510. + */
  50511. + uint16_t wLength;
  50512. +
  50513. + /** The data length of this feature in bytes */
  50514. + uint16_t wDataLength;
  50515. +
  50516. + /**
  50517. + * Attributes of this features
  50518. + * D0: Access rights
  50519. + * 0 - Read/Write
  50520. + * 1 - Read only
  50521. + */
  50522. + uint8_t bmAttributes;
  50523. +#define CFI_FEATURE_ATTR_RO 1
  50524. +#define CFI_FEATURE_ATTR_RW 0
  50525. +
  50526. + /** Length of the feature name in bytes */
  50527. + uint8_t bNameLen;
  50528. +
  50529. + /** The feature name buffer */
  50530. + //uint8_t *name;
  50531. +} UPACKED;
  50532. +
  50533. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  50534. +
  50535. +/**
  50536. + * This structure describes a NULL terminated string referenced by its id field.
  50537. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  50538. + */
  50539. +struct cfi_string {
  50540. + uint16_t id;
  50541. + const uint8_t *s;
  50542. +};
  50543. +typedef struct cfi_string cfi_string_t;
  50544. +
  50545. +#endif
  50546. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  50547. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  50548. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-02-07 19:57:30.000000000 +0100
  50549. @@ -0,0 +1,854 @@
  50550. +/* ==========================================================================
  50551. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  50552. + * $Revision: #12 $
  50553. + * $Date: 2011/10/26 $
  50554. + * $Change: 1873028 $
  50555. + *
  50556. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50557. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50558. + * otherwise expressly agreed to in writing between Synopsys and you.
  50559. + *
  50560. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50561. + * any End User Software License Agreement or Agreement for Licensed Product
  50562. + * with Synopsys or any supplement thereto. You are permitted to use and
  50563. + * redistribute this Software in source and binary forms, with or without
  50564. + * modification, provided that redistributions of source code must retain this
  50565. + * notice. You may not view, use, disclose, copy or distribute this file or
  50566. + * any information contained herein except pursuant to this license grant from
  50567. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50568. + * below, then you are not authorized to use the Software.
  50569. + *
  50570. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50571. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50572. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50573. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50574. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50575. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50576. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50577. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50578. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50579. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50580. + * DAMAGE.
  50581. + * ========================================================================== */
  50582. +
  50583. +#include "dwc_os.h"
  50584. +#include "dwc_otg_regs.h"
  50585. +#include "dwc_otg_cil.h"
  50586. +#include "dwc_otg_adp.h"
  50587. +
  50588. +/** @file
  50589. + *
  50590. + * This file contains the most of the Attach Detect Protocol implementation for
  50591. + * the driver to support OTG Rev2.0.
  50592. + *
  50593. + */
  50594. +
  50595. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  50596. +{
  50597. + adpctl_data_t adpctl;
  50598. +
  50599. + adpctl.d32 = value;
  50600. + adpctl.b.ar = 0x2;
  50601. +
  50602. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50603. +
  50604. + while (adpctl.b.ar) {
  50605. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50606. + }
  50607. +
  50608. +}
  50609. +
  50610. +/**
  50611. + * Function is called to read ADP registers
  50612. + */
  50613. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  50614. +{
  50615. + adpctl_data_t adpctl;
  50616. +
  50617. + adpctl.d32 = 0;
  50618. + adpctl.b.ar = 0x1;
  50619. +
  50620. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50621. +
  50622. + while (adpctl.b.ar) {
  50623. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50624. + }
  50625. +
  50626. + return adpctl.d32;
  50627. +}
  50628. +
  50629. +/**
  50630. + * Function is called to read ADPCTL register and filter Write-clear bits
  50631. + */
  50632. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  50633. +{
  50634. + adpctl_data_t adpctl;
  50635. +
  50636. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50637. + adpctl.b.adp_tmout_int = 0;
  50638. + adpctl.b.adp_prb_int = 0;
  50639. + adpctl.b.adp_tmout_int = 0;
  50640. +
  50641. + return adpctl.d32;
  50642. +}
  50643. +
  50644. +/**
  50645. + * Function is called to write ADP registers
  50646. + */
  50647. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  50648. + uint32_t set)
  50649. +{
  50650. + dwc_otg_adp_write_reg(core_if,
  50651. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  50652. +}
  50653. +
  50654. +static void adp_sense_timeout(void *ptr)
  50655. +{
  50656. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50657. + core_if->adp.sense_timer_started = 0;
  50658. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  50659. + if (core_if->adp_enable) {
  50660. + dwc_otg_adp_sense_stop(core_if);
  50661. + dwc_otg_adp_probe_start(core_if);
  50662. + }
  50663. +}
  50664. +
  50665. +/**
  50666. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  50667. + */
  50668. +static void adp_vbuson_timeout(void *ptr)
  50669. +{
  50670. + gpwrdn_data_t gpwrdn;
  50671. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50672. + hprt0_data_t hprt0 = {.d32 = 0 };
  50673. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  50674. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  50675. + if (core_if) {
  50676. + core_if->adp.vbuson_timer_started = 0;
  50677. + /* Turn off vbus */
  50678. + hprt0.b.prtpwr = 1;
  50679. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  50680. + gpwrdn.d32 = 0;
  50681. +
  50682. + /* Power off the core */
  50683. + if (core_if->power_down == 2) {
  50684. + /* Enable Wakeup Logic */
  50685. +// gpwrdn.b.wkupactiv = 1;
  50686. + gpwrdn.b.pmuactv = 0;
  50687. + gpwrdn.b.pwrdnrstn = 1;
  50688. + gpwrdn.b.pwrdnclmp = 1;
  50689. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50690. + gpwrdn.d32);
  50691. +
  50692. + /* Suspend the Phy Clock */
  50693. + pcgcctl.b.stoppclk = 1;
  50694. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  50695. +
  50696. + /* Switch on VDD */
  50697. +// gpwrdn.b.wkupactiv = 1;
  50698. + gpwrdn.b.pmuactv = 1;
  50699. + gpwrdn.b.pwrdnrstn = 1;
  50700. + gpwrdn.b.pwrdnclmp = 1;
  50701. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50702. + gpwrdn.d32);
  50703. + } else {
  50704. + /* Enable Power Down Logic */
  50705. + gpwrdn.b.pmuintsel = 1;
  50706. + gpwrdn.b.pmuactv = 1;
  50707. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50708. + }
  50709. +
  50710. + /* Power off the core */
  50711. + if (core_if->power_down == 2) {
  50712. + gpwrdn.d32 = 0;
  50713. + gpwrdn.b.pwrdnswtch = 1;
  50714. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  50715. + gpwrdn.d32, 0);
  50716. + }
  50717. +
  50718. + /* Unmask SRP detected interrupt from Power Down Logic */
  50719. + gpwrdn.d32 = 0;
  50720. + gpwrdn.b.srp_det_msk = 1;
  50721. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50722. +
  50723. + dwc_otg_adp_probe_start(core_if);
  50724. + dwc_otg_dump_global_registers(core_if);
  50725. + dwc_otg_dump_host_registers(core_if);
  50726. + }
  50727. +
  50728. +}
  50729. +
  50730. +/**
  50731. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  50732. + * not asserted within 1.1 seconds.
  50733. + *
  50734. + * @param core_if the pointer to core_if strucure.
  50735. + */
  50736. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  50737. +{
  50738. + core_if->adp.vbuson_timer_started = 1;
  50739. + if (core_if->adp.vbuson_timer)
  50740. + {
  50741. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  50742. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  50743. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  50744. + } else {
  50745. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  50746. + }
  50747. +}
  50748. +
  50749. +#if 0
  50750. +/**
  50751. + * Masks all DWC OTG core interrupts
  50752. + *
  50753. + */
  50754. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  50755. +{
  50756. + int i;
  50757. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  50758. +
  50759. + /* Mask Host Interrupts */
  50760. +
  50761. + /* Clear and disable HCINTs */
  50762. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  50763. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  50764. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  50765. +
  50766. + }
  50767. +
  50768. + /* Clear and disable HAINT */
  50769. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  50770. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  50771. +
  50772. + /* Mask Device Interrupts */
  50773. + if (!core_if->multiproc_int_enable) {
  50774. + /* Clear and disable IN Endpoint interrupts */
  50775. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  50776. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  50777. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50778. + diepint, 0xFFFFFFFF);
  50779. + }
  50780. +
  50781. + /* Clear and disable OUT Endpoint interrupts */
  50782. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  50783. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  50784. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50785. + doepint, 0xFFFFFFFF);
  50786. + }
  50787. +
  50788. + /* Clear and disable DAINT */
  50789. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  50790. + 0xFFFFFFFF);
  50791. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  50792. + } else {
  50793. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  50794. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50795. + diepeachintmsk[i], 0);
  50796. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50797. + diepint, 0xFFFFFFFF);
  50798. + }
  50799. +
  50800. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  50801. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50802. + doepeachintmsk[i], 0);
  50803. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50804. + doepint, 0xFFFFFFFF);
  50805. + }
  50806. +
  50807. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  50808. + 0);
  50809. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  50810. + 0xFFFFFFFF);
  50811. +
  50812. + }
  50813. +
  50814. + /* Disable interrupts */
  50815. + ahbcfg.b.glblintrmsk = 1;
  50816. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  50817. +
  50818. + /* Disable all interrupts. */
  50819. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  50820. +
  50821. + /* Clear any pending interrupts */
  50822. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50823. +
  50824. + /* Clear any pending OTG Interrupts */
  50825. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  50826. +}
  50827. +
  50828. +/**
  50829. + * Unmask Port Connection Detected interrupt
  50830. + *
  50831. + */
  50832. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  50833. +{
  50834. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  50835. +
  50836. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  50837. +}
  50838. +#endif
  50839. +
  50840. +/**
  50841. + * Starts the ADP Probing
  50842. + *
  50843. + * @param core_if the pointer to core_if structure.
  50844. + */
  50845. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  50846. +{
  50847. +
  50848. + adpctl_data_t adpctl = {.d32 = 0};
  50849. + gpwrdn_data_t gpwrdn;
  50850. +#if 0
  50851. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  50852. + .b.adp_sns_int = 1, b.adp_tmout_int};
  50853. +#endif
  50854. + dwc_otg_disable_global_interrupts(core_if);
  50855. + DWC_PRINTF("ADP Probe Start\n");
  50856. + core_if->adp.probe_enabled = 1;
  50857. +
  50858. + adpctl.b.adpres = 1;
  50859. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50860. +
  50861. + while (adpctl.b.adpres) {
  50862. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50863. + }
  50864. +
  50865. + adpctl.d32 = 0;
  50866. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50867. +
  50868. + /* In Host mode unmask SRP detected interrupt */
  50869. + gpwrdn.d32 = 0;
  50870. + gpwrdn.b.sts_chngint_msk = 1;
  50871. + if (!gpwrdn.b.idsts) {
  50872. + gpwrdn.b.srp_det_msk = 1;
  50873. + }
  50874. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50875. +
  50876. + adpctl.b.adp_tmout_int_msk = 1;
  50877. + adpctl.b.adp_prb_int_msk = 1;
  50878. + adpctl.b.prb_dschg = 1;
  50879. + adpctl.b.prb_delta = 1;
  50880. + adpctl.b.prb_per = 1;
  50881. + adpctl.b.adpen = 1;
  50882. + adpctl.b.enaprb = 1;
  50883. +
  50884. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50885. + DWC_PRINTF("ADP Probe Finish\n");
  50886. + return 0;
  50887. +}
  50888. +
  50889. +/**
  50890. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  50891. + * within 3 seconds.
  50892. + *
  50893. + * @param core_if the pointer to core_if strucure.
  50894. + */
  50895. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  50896. +{
  50897. + core_if->adp.sense_timer_started = 1;
  50898. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  50899. +}
  50900. +
  50901. +/**
  50902. + * Starts the ADP Sense
  50903. + *
  50904. + * @param core_if the pointer to core_if strucure.
  50905. + */
  50906. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  50907. +{
  50908. + adpctl_data_t adpctl;
  50909. +
  50910. + DWC_PRINTF("ADP Sense Start\n");
  50911. +
  50912. + /* Unmask ADP sense interrupt and mask all other from the core */
  50913. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50914. + adpctl.b.adp_sns_int_msk = 1;
  50915. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50916. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  50917. +
  50918. + /* Set ADP reset bit*/
  50919. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50920. + adpctl.b.adpres = 1;
  50921. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50922. +
  50923. + while (adpctl.b.adpres) {
  50924. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50925. + }
  50926. +
  50927. + adpctl.b.adpres = 0;
  50928. + adpctl.b.adpen = 1;
  50929. + adpctl.b.enasns = 1;
  50930. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50931. +
  50932. + dwc_otg_adp_sense_timer_start(core_if);
  50933. +
  50934. + return 0;
  50935. +}
  50936. +
  50937. +/**
  50938. + * Stops the ADP Probing
  50939. + *
  50940. + * @param core_if the pointer to core_if strucure.
  50941. + */
  50942. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  50943. +{
  50944. +
  50945. + adpctl_data_t adpctl;
  50946. + DWC_PRINTF("Stop ADP probe\n");
  50947. + core_if->adp.probe_enabled = 0;
  50948. + core_if->adp.probe_counter = 0;
  50949. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50950. +
  50951. + adpctl.b.adpen = 0;
  50952. + adpctl.b.adp_prb_int = 1;
  50953. + adpctl.b.adp_tmout_int = 1;
  50954. + adpctl.b.adp_sns_int = 1;
  50955. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50956. +
  50957. + return 0;
  50958. +}
  50959. +
  50960. +/**
  50961. + * Stops the ADP Sensing
  50962. + *
  50963. + * @param core_if the pointer to core_if strucure.
  50964. + */
  50965. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  50966. +{
  50967. + adpctl_data_t adpctl;
  50968. +
  50969. + core_if->adp.sense_enabled = 0;
  50970. +
  50971. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50972. + adpctl.b.enasns = 0;
  50973. + adpctl.b.adp_sns_int = 1;
  50974. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50975. +
  50976. + return 0;
  50977. +}
  50978. +
  50979. +/**
  50980. + * Called to turn on the VBUS after initial ADP probe in host mode.
  50981. + * If port power was already enabled in cil_hcd_start function then
  50982. + * only schedule a timer.
  50983. + *
  50984. + * @param core_if the pointer to core_if structure.
  50985. + */
  50986. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  50987. +{
  50988. + hprt0_data_t hprt0 = {.d32 = 0 };
  50989. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  50990. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  50991. +
  50992. + if (hprt0.b.prtpwr == 0) {
  50993. + hprt0.b.prtpwr = 1;
  50994. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  50995. + }
  50996. +
  50997. + dwc_otg_adp_vbuson_timer_start(core_if);
  50998. +}
  50999. +
  51000. +/**
  51001. + * Called right after driver is loaded
  51002. + * to perform initial actions for ADP
  51003. + *
  51004. + * @param core_if the pointer to core_if structure.
  51005. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  51006. + */
  51007. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  51008. +{
  51009. + gpwrdn_data_t gpwrdn;
  51010. +
  51011. + DWC_PRINTF("ADP Initial Start\n");
  51012. + core_if->adp.adp_started = 1;
  51013. +
  51014. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51015. + dwc_otg_disable_global_interrupts(core_if);
  51016. + if (is_host) {
  51017. + DWC_PRINTF("HOST MODE\n");
  51018. + /* Enable Power Down Logic Interrupt*/
  51019. + gpwrdn.d32 = 0;
  51020. + gpwrdn.b.pmuintsel = 1;
  51021. + gpwrdn.b.pmuactv = 1;
  51022. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51023. + /* Initialize first ADP probe to obtain Ramp Time value */
  51024. + core_if->adp.initial_probe = 1;
  51025. + dwc_otg_adp_probe_start(core_if);
  51026. + } else {
  51027. + gotgctl_data_t gotgctl;
  51028. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51029. + DWC_PRINTF("DEVICE MODE\n");
  51030. + if (gotgctl.b.bsesvld == 0) {
  51031. + /* Enable Power Down Logic Interrupt*/
  51032. + gpwrdn.d32 = 0;
  51033. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  51034. + gpwrdn.b.pmuintsel = 1;
  51035. + gpwrdn.b.pmuactv = 1;
  51036. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51037. + core_if->adp.initial_probe = 1;
  51038. + dwc_otg_adp_probe_start(core_if);
  51039. + } else {
  51040. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  51041. + core_if->op_state = B_PERIPHERAL;
  51042. + dwc_otg_core_init(core_if);
  51043. + dwc_otg_enable_global_interrupts(core_if);
  51044. + cil_pcd_start(core_if);
  51045. + dwc_otg_dump_global_registers(core_if);
  51046. + dwc_otg_dump_dev_registers(core_if);
  51047. + }
  51048. + }
  51049. +}
  51050. +
  51051. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  51052. +{
  51053. + core_if->adp.adp_started = 0;
  51054. + core_if->adp.initial_probe = 0;
  51055. + core_if->adp.probe_timer_values[0] = -1;
  51056. + core_if->adp.probe_timer_values[1] = -1;
  51057. + core_if->adp.probe_enabled = 0;
  51058. + core_if->adp.sense_enabled = 0;
  51059. + core_if->adp.sense_timer_started = 0;
  51060. + core_if->adp.vbuson_timer_started = 0;
  51061. + core_if->adp.probe_counter = 0;
  51062. + core_if->adp.gpwrdn = 0;
  51063. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  51064. + /* Initialize timers */
  51065. + core_if->adp.sense_timer =
  51066. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  51067. + core_if->adp.vbuson_timer =
  51068. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  51069. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  51070. + {
  51071. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  51072. + }
  51073. +}
  51074. +
  51075. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  51076. +{
  51077. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  51078. + gpwrdn.b.pmuintsel = 1;
  51079. + gpwrdn.b.pmuactv = 1;
  51080. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51081. +
  51082. + if (core_if->adp.probe_enabled)
  51083. + dwc_otg_adp_probe_stop(core_if);
  51084. + if (core_if->adp.sense_enabled)
  51085. + dwc_otg_adp_sense_stop(core_if);
  51086. + if (core_if->adp.sense_timer_started)
  51087. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51088. + if (core_if->adp.vbuson_timer_started)
  51089. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  51090. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  51091. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  51092. +}
  51093. +
  51094. +/////////////////////////////////////////////////////////////////////
  51095. +////////////// ADP Interrupt Handlers ///////////////////////////////
  51096. +/////////////////////////////////////////////////////////////////////
  51097. +/**
  51098. + * This function sets Ramp Timer values
  51099. + */
  51100. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  51101. +{
  51102. + if (core_if->adp.probe_timer_values[0] == -1) {
  51103. + core_if->adp.probe_timer_values[0] = val;
  51104. + core_if->adp.probe_timer_values[1] = -1;
  51105. + return 1;
  51106. + } else {
  51107. + core_if->adp.probe_timer_values[1] =
  51108. + core_if->adp.probe_timer_values[0];
  51109. + core_if->adp.probe_timer_values[0] = val;
  51110. + return 0;
  51111. + }
  51112. +}
  51113. +
  51114. +/**
  51115. + * This function compares Ramp Timer values
  51116. + */
  51117. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  51118. +{
  51119. + uint32_t diff;
  51120. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  51121. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  51122. + else
  51123. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  51124. + if(diff < 2) {
  51125. + return 0;
  51126. + } else {
  51127. + return 1;
  51128. + }
  51129. +}
  51130. +
  51131. +/**
  51132. + * This function handles ADP Probe Interrupts
  51133. + */
  51134. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  51135. + uint32_t val)
  51136. +{
  51137. + adpctl_data_t adpctl = {.d32 = 0 };
  51138. + gpwrdn_data_t gpwrdn, temp;
  51139. + adpctl.d32 = val;
  51140. +
  51141. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51142. + core_if->adp.probe_counter++;
  51143. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51144. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  51145. + DWC_PRINTF("RTIM value is 0\n");
  51146. + goto exit;
  51147. + }
  51148. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  51149. + core_if->adp.initial_probe) {
  51150. + core_if->adp.initial_probe = 0;
  51151. + dwc_otg_adp_probe_stop(core_if);
  51152. + gpwrdn.d32 = 0;
  51153. + gpwrdn.b.pmuactv = 1;
  51154. + gpwrdn.b.pmuintsel = 1;
  51155. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51156. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51157. +
  51158. + /* check which value is for device mode and which for Host mode */
  51159. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51160. + /*
  51161. + * Turn on VBUS after initial ADP probe.
  51162. + */
  51163. + core_if->op_state = A_HOST;
  51164. + dwc_otg_enable_global_interrupts(core_if);
  51165. + DWC_SPINUNLOCK(core_if->lock);
  51166. + cil_hcd_start(core_if);
  51167. + dwc_otg_adp_turnon_vbus(core_if);
  51168. + DWC_SPINLOCK(core_if->lock);
  51169. + } else {
  51170. + /*
  51171. + * Initiate SRP after initial ADP probe.
  51172. + */
  51173. + dwc_otg_enable_global_interrupts(core_if);
  51174. + dwc_otg_initiate_srp(core_if);
  51175. + }
  51176. + } else if (core_if->adp.probe_counter > 2){
  51177. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51178. + if (compare_timer_values(core_if)) {
  51179. + DWC_PRINTF("Difference in timer values !!! \n");
  51180. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  51181. + dwc_otg_adp_probe_stop(core_if);
  51182. +
  51183. + /* Power on the core */
  51184. + if (core_if->power_down == 2) {
  51185. + gpwrdn.b.pwrdnswtch = 1;
  51186. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51187. + gpwrdn, 0, gpwrdn.d32);
  51188. + }
  51189. +
  51190. + /* check which value is for device mode and which for Host mode */
  51191. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51192. + /* Disable Interrupt from Power Down Logic */
  51193. + gpwrdn.d32 = 0;
  51194. + gpwrdn.b.pmuintsel = 1;
  51195. + gpwrdn.b.pmuactv = 1;
  51196. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51197. + gpwrdn, gpwrdn.d32, 0);
  51198. +
  51199. + /*
  51200. + * Initialize the Core for Host mode.
  51201. + */
  51202. + core_if->op_state = A_HOST;
  51203. + dwc_otg_core_init(core_if);
  51204. + dwc_otg_enable_global_interrupts(core_if);
  51205. + cil_hcd_start(core_if);
  51206. + } else {
  51207. + gotgctl_data_t gotgctl;
  51208. + /* Mask SRP detected interrupt from Power Down Logic */
  51209. + gpwrdn.d32 = 0;
  51210. + gpwrdn.b.srp_det_msk = 1;
  51211. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51212. + gpwrdn, gpwrdn.d32, 0);
  51213. +
  51214. + /* Disable Power Down Logic */
  51215. + gpwrdn.d32 = 0;
  51216. + gpwrdn.b.pmuintsel = 1;
  51217. + gpwrdn.b.pmuactv = 1;
  51218. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51219. + gpwrdn, gpwrdn.d32, 0);
  51220. +
  51221. + /*
  51222. + * Initialize the Core for Device mode.
  51223. + */
  51224. + core_if->op_state = B_PERIPHERAL;
  51225. + dwc_otg_core_init(core_if);
  51226. + dwc_otg_enable_global_interrupts(core_if);
  51227. + cil_pcd_start(core_if);
  51228. +
  51229. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51230. + if (!gotgctl.b.bsesvld) {
  51231. + dwc_otg_initiate_srp(core_if);
  51232. + }
  51233. + }
  51234. + }
  51235. + if (core_if->power_down == 2) {
  51236. + if (gpwrdn.b.bsessvld) {
  51237. + /* Mask SRP detected interrupt from Power Down Logic */
  51238. + gpwrdn.d32 = 0;
  51239. + gpwrdn.b.srp_det_msk = 1;
  51240. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51241. +
  51242. + /* Disable Power Down Logic */
  51243. + gpwrdn.d32 = 0;
  51244. + gpwrdn.b.pmuactv = 1;
  51245. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51246. +
  51247. + /*
  51248. + * Initialize the Core for Device mode.
  51249. + */
  51250. + core_if->op_state = B_PERIPHERAL;
  51251. + dwc_otg_core_init(core_if);
  51252. + dwc_otg_enable_global_interrupts(core_if);
  51253. + cil_pcd_start(core_if);
  51254. + }
  51255. + }
  51256. + }
  51257. +exit:
  51258. + /* Clear interrupt */
  51259. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51260. + adpctl.b.adp_prb_int = 1;
  51261. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51262. +
  51263. + return 0;
  51264. +}
  51265. +
  51266. +/**
  51267. + * This function hadles ADP Sense Interrupt
  51268. + */
  51269. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  51270. +{
  51271. + adpctl_data_t adpctl;
  51272. + /* Stop ADP Sense timer */
  51273. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51274. +
  51275. + /* Restart ADP Sense timer */
  51276. + dwc_otg_adp_sense_timer_start(core_if);
  51277. +
  51278. + /* Clear interrupt */
  51279. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51280. + adpctl.b.adp_sns_int = 1;
  51281. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51282. +
  51283. + return 0;
  51284. +}
  51285. +
  51286. +/**
  51287. + * This function handles ADP Probe Interrupts
  51288. + */
  51289. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  51290. + uint32_t val)
  51291. +{
  51292. + adpctl_data_t adpctl = {.d32 = 0 };
  51293. + adpctl.d32 = val;
  51294. + set_timer_value(core_if, adpctl.b.rtim);
  51295. +
  51296. + /* Clear interrupt */
  51297. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51298. + adpctl.b.adp_tmout_int = 1;
  51299. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51300. +
  51301. + return 0;
  51302. +}
  51303. +
  51304. +/**
  51305. + * ADP Interrupt handler.
  51306. + *
  51307. + */
  51308. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  51309. +{
  51310. + int retval = 0;
  51311. + adpctl_data_t adpctl = {.d32 = 0};
  51312. +
  51313. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51314. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  51315. +
  51316. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  51317. + DWC_PRINTF("ADP Sense interrupt\n");
  51318. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  51319. + }
  51320. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  51321. + DWC_PRINTF("ADP timeout interrupt\n");
  51322. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  51323. + }
  51324. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  51325. + DWC_PRINTF("ADP Probe interrupt\n");
  51326. + adpctl.b.adp_prb_int = 1;
  51327. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  51328. + }
  51329. +
  51330. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  51331. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51332. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  51333. +
  51334. + return retval;
  51335. +}
  51336. +
  51337. +/**
  51338. + *
  51339. + * @param core_if Programming view of DWC_otg controller.
  51340. + */
  51341. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  51342. +{
  51343. +
  51344. +#ifndef DWC_HOST_ONLY
  51345. + hprt0_data_t hprt0;
  51346. + gpwrdn_data_t gpwrdn;
  51347. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  51348. +
  51349. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51350. + /* check which value is for device mode and which for Host mode */
  51351. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  51352. + DWC_PRINTF("SRP: Host mode\n");
  51353. +
  51354. + if (core_if->adp_enable) {
  51355. + dwc_otg_adp_probe_stop(core_if);
  51356. +
  51357. + /* Power on the core */
  51358. + if (core_if->power_down == 2) {
  51359. + gpwrdn.b.pwrdnswtch = 1;
  51360. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51361. + gpwrdn, 0, gpwrdn.d32);
  51362. + }
  51363. +
  51364. + core_if->op_state = A_HOST;
  51365. + dwc_otg_core_init(core_if);
  51366. + dwc_otg_enable_global_interrupts(core_if);
  51367. + cil_hcd_start(core_if);
  51368. + }
  51369. +
  51370. + /* Turn on the port power bit. */
  51371. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51372. + hprt0.b.prtpwr = 1;
  51373. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51374. +
  51375. + /* Start the Connection timer. So a message can be displayed
  51376. + * if connect does not occur within 10 seconds. */
  51377. + cil_hcd_session_start(core_if);
  51378. + } else {
  51379. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  51380. + if (core_if->adp_enable) {
  51381. + dwc_otg_adp_probe_stop(core_if);
  51382. +
  51383. + /* Power on the core */
  51384. + if (core_if->power_down == 2) {
  51385. + gpwrdn.b.pwrdnswtch = 1;
  51386. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51387. + gpwrdn, 0, gpwrdn.d32);
  51388. + }
  51389. +
  51390. + gpwrdn.d32 = 0;
  51391. + gpwrdn.b.pmuactv = 0;
  51392. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51393. + gpwrdn.d32);
  51394. +
  51395. + core_if->op_state = B_PERIPHERAL;
  51396. + dwc_otg_core_init(core_if);
  51397. + dwc_otg_enable_global_interrupts(core_if);
  51398. + cil_pcd_start(core_if);
  51399. + }
  51400. + }
  51401. +#endif
  51402. + return 1;
  51403. +}
  51404. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  51405. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  51406. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-02-07 19:57:30.000000000 +0100
  51407. @@ -0,0 +1,80 @@
  51408. +/* ==========================================================================
  51409. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  51410. + * $Revision: #7 $
  51411. + * $Date: 2011/10/24 $
  51412. + * $Change: 1871159 $
  51413. + *
  51414. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51415. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51416. + * otherwise expressly agreed to in writing between Synopsys and you.
  51417. + *
  51418. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51419. + * any End User Software License Agreement or Agreement for Licensed Product
  51420. + * with Synopsys or any supplement thereto. You are permitted to use and
  51421. + * redistribute this Software in source and binary forms, with or without
  51422. + * modification, provided that redistributions of source code must retain this
  51423. + * notice. You may not view, use, disclose, copy or distribute this file or
  51424. + * any information contained herein except pursuant to this license grant from
  51425. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51426. + * below, then you are not authorized to use the Software.
  51427. + *
  51428. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51429. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51430. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51431. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51432. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51433. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51434. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51435. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51436. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51437. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51438. + * DAMAGE.
  51439. + * ========================================================================== */
  51440. +
  51441. +#ifndef __DWC_OTG_ADP_H__
  51442. +#define __DWC_OTG_ADP_H__
  51443. +
  51444. +/**
  51445. + * @file
  51446. + *
  51447. + * This file contains the Attach Detect Protocol interfaces and defines
  51448. + * (functions) and structures for Linux.
  51449. + *
  51450. + */
  51451. +
  51452. +#define DWC_OTG_ADP_UNATTACHED 0
  51453. +#define DWC_OTG_ADP_ATTACHED 1
  51454. +#define DWC_OTG_ADP_UNKOWN 2
  51455. +
  51456. +typedef struct dwc_otg_adp {
  51457. + uint32_t adp_started;
  51458. + uint32_t initial_probe;
  51459. + int32_t probe_timer_values[2];
  51460. + uint32_t probe_enabled;
  51461. + uint32_t sense_enabled;
  51462. + dwc_timer_t *sense_timer;
  51463. + uint32_t sense_timer_started;
  51464. + dwc_timer_t *vbuson_timer;
  51465. + uint32_t vbuson_timer_started;
  51466. + uint32_t attached;
  51467. + uint32_t probe_counter;
  51468. + uint32_t gpwrdn;
  51469. +} dwc_otg_adp_t;
  51470. +
  51471. +/**
  51472. + * Attach Detect Protocol functions
  51473. + */
  51474. +
  51475. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  51476. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  51477. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  51478. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  51479. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  51480. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  51481. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  51482. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  51483. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  51484. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  51485. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  51486. +
  51487. +#endif //__DWC_OTG_ADP_H__
  51488. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  51489. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  51490. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-02-07 19:57:30.000000000 +0100
  51491. @@ -0,0 +1,1210 @@
  51492. +/* ==========================================================================
  51493. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  51494. + * $Revision: #44 $
  51495. + * $Date: 2010/11/29 $
  51496. + * $Change: 1636033 $
  51497. + *
  51498. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51499. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51500. + * otherwise expressly agreed to in writing between Synopsys and you.
  51501. + *
  51502. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51503. + * any End User Software License Agreement or Agreement for Licensed Product
  51504. + * with Synopsys or any supplement thereto. You are permitted to use and
  51505. + * redistribute this Software in source and binary forms, with or without
  51506. + * modification, provided that redistributions of source code must retain this
  51507. + * notice. You may not view, use, disclose, copy or distribute this file or
  51508. + * any information contained herein except pursuant to this license grant from
  51509. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51510. + * below, then you are not authorized to use the Software.
  51511. + *
  51512. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51513. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51514. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51515. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51516. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51517. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51518. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51519. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51520. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51521. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51522. + * DAMAGE.
  51523. + * ========================================================================== */
  51524. +
  51525. +/** @file
  51526. + *
  51527. + * The diagnostic interface will provide access to the controller for
  51528. + * bringing up the hardware and testing. The Linux driver attributes
  51529. + * feature will be used to provide the Linux Diagnostic
  51530. + * Interface. These attributes are accessed through sysfs.
  51531. + */
  51532. +
  51533. +/** @page "Linux Module Attributes"
  51534. + *
  51535. + * The Linux module attributes feature is used to provide the Linux
  51536. + * Diagnostic Interface. These attributes are accessed through sysfs.
  51537. + * The diagnostic interface will provide access to the controller for
  51538. + * bringing up the hardware and testing.
  51539. +
  51540. + The following table shows the attributes.
  51541. + <table>
  51542. + <tr>
  51543. + <td><b> Name</b></td>
  51544. + <td><b> Description</b></td>
  51545. + <td><b> Access</b></td>
  51546. + </tr>
  51547. +
  51548. + <tr>
  51549. + <td> mode </td>
  51550. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  51551. + <td> Read</td>
  51552. + </tr>
  51553. +
  51554. + <tr>
  51555. + <td> hnpcapable </td>
  51556. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  51557. + Read returns the current value.</td>
  51558. + <td> Read/Write</td>
  51559. + </tr>
  51560. +
  51561. + <tr>
  51562. + <td> srpcapable </td>
  51563. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  51564. + Read returns the current value.</td>
  51565. + <td> Read/Write</td>
  51566. + </tr>
  51567. +
  51568. + <tr>
  51569. + <td> hsic_connect </td>
  51570. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  51571. + Read returns the current value.</td>
  51572. + <td> Read/Write</td>
  51573. + </tr>
  51574. +
  51575. + <tr>
  51576. + <td> inv_sel_hsic </td>
  51577. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  51578. + Read returns the current value.</td>
  51579. + <td> Read/Write</td>
  51580. + </tr>
  51581. +
  51582. + <tr>
  51583. + <td> hnp </td>
  51584. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  51585. + <td> Read/Write</td>
  51586. + </tr>
  51587. +
  51588. + <tr>
  51589. + <td> srp </td>
  51590. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  51591. + <td> Read/Write</td>
  51592. + </tr>
  51593. +
  51594. + <tr>
  51595. + <td> buspower </td>
  51596. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  51597. + <td> Read/Write</td>
  51598. + </tr>
  51599. +
  51600. + <tr>
  51601. + <td> bussuspend </td>
  51602. + <td> Suspends the USB bus.</td>
  51603. + <td> Read/Write</td>
  51604. + </tr>
  51605. +
  51606. + <tr>
  51607. + <td> busconnected </td>
  51608. + <td> Gets the connection status of the bus</td>
  51609. + <td> Read</td>
  51610. + </tr>
  51611. +
  51612. + <tr>
  51613. + <td> gotgctl </td>
  51614. + <td> Gets or sets the Core Control Status Register.</td>
  51615. + <td> Read/Write</td>
  51616. + </tr>
  51617. +
  51618. + <tr>
  51619. + <td> gusbcfg </td>
  51620. + <td> Gets or sets the Core USB Configuration Register</td>
  51621. + <td> Read/Write</td>
  51622. + </tr>
  51623. +
  51624. + <tr>
  51625. + <td> grxfsiz </td>
  51626. + <td> Gets or sets the Receive FIFO Size Register</td>
  51627. + <td> Read/Write</td>
  51628. + </tr>
  51629. +
  51630. + <tr>
  51631. + <td> gnptxfsiz </td>
  51632. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  51633. + <td> Read/Write</td>
  51634. + </tr>
  51635. +
  51636. + <tr>
  51637. + <td> gpvndctl </td>
  51638. + <td> Gets or sets the PHY Vendor Control Register</td>
  51639. + <td> Read/Write</td>
  51640. + </tr>
  51641. +
  51642. + <tr>
  51643. + <td> ggpio </td>
  51644. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  51645. + or sets the upper 16 bits.</td>
  51646. + <td> Read/Write</td>
  51647. + </tr>
  51648. +
  51649. + <tr>
  51650. + <td> guid </td>
  51651. + <td> Gets or sets the value of the User ID Register</td>
  51652. + <td> Read/Write</td>
  51653. + </tr>
  51654. +
  51655. + <tr>
  51656. + <td> gsnpsid </td>
  51657. + <td> Gets the value of the Synopsys ID Regester</td>
  51658. + <td> Read</td>
  51659. + </tr>
  51660. +
  51661. + <tr>
  51662. + <td> devspeed </td>
  51663. + <td> Gets or sets the device speed setting in the DCFG register</td>
  51664. + <td> Read/Write</td>
  51665. + </tr>
  51666. +
  51667. + <tr>
  51668. + <td> enumspeed </td>
  51669. + <td> Gets the device enumeration Speed.</td>
  51670. + <td> Read</td>
  51671. + </tr>
  51672. +
  51673. + <tr>
  51674. + <td> hptxfsiz </td>
  51675. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  51676. + <td> Read</td>
  51677. + </tr>
  51678. +
  51679. + <tr>
  51680. + <td> hprt0 </td>
  51681. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  51682. + <td> Read/Write</td>
  51683. + </tr>
  51684. +
  51685. + <tr>
  51686. + <td> regoffset </td>
  51687. + <td> Sets the register offset for the next Register Access</td>
  51688. + <td> Read/Write</td>
  51689. + </tr>
  51690. +
  51691. + <tr>
  51692. + <td> regvalue </td>
  51693. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  51694. + <td> Read/Write</td>
  51695. + </tr>
  51696. +
  51697. + <tr>
  51698. + <td> remote_wakeup </td>
  51699. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  51700. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  51701. + Wakeup signalling bit in the Device Control Register is set for 1
  51702. + milli-second.</td>
  51703. + <td> Read/Write</td>
  51704. + </tr>
  51705. +
  51706. + <tr>
  51707. + <td> rem_wakeup_pwrdn </td>
  51708. + <td> On read, shows the status core - hibernated or not. On write, initiates
  51709. + a remote wakeup of the device from Hibernation. </td>
  51710. + <td> Read/Write</td>
  51711. + </tr>
  51712. +
  51713. + <tr>
  51714. + <td> mode_ch_tim_en </td>
  51715. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  51716. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  51717. + after Suspend or LPM. </td>
  51718. + <td> Read/Write</td>
  51719. + </tr>
  51720. +
  51721. + <tr>
  51722. + <td> fr_interval </td>
  51723. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  51724. + reload HFIR register during runtime. The application can write a value to this
  51725. + register only after the Port Enable bit of the Host Port Control and Status
  51726. + register (HPRT.PrtEnaPort) has been set </td>
  51727. + <td> Read/Write</td>
  51728. + </tr>
  51729. +
  51730. + <tr>
  51731. + <td> disconnect_us </td>
  51732. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  51733. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  51734. + <td> Read/Write</td>
  51735. + </tr>
  51736. +
  51737. + <tr>
  51738. + <td> regdump </td>
  51739. + <td> Dumps the contents of core registers.</td>
  51740. + <td> Read</td>
  51741. + </tr>
  51742. +
  51743. + <tr>
  51744. + <td> spramdump </td>
  51745. + <td> Dumps the contents of core registers.</td>
  51746. + <td> Read</td>
  51747. + </tr>
  51748. +
  51749. + <tr>
  51750. + <td> hcddump </td>
  51751. + <td> Dumps the current HCD state.</td>
  51752. + <td> Read</td>
  51753. + </tr>
  51754. +
  51755. + <tr>
  51756. + <td> hcd_frrem </td>
  51757. + <td> Shows the average value of the Frame Remaining
  51758. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  51759. + occurs. This can be used to determine the average interrupt latency. Also
  51760. + shows the average Frame Remaining value for start_transfer and the "a" and
  51761. + "b" sample points. The "a" and "b" sample points may be used during debugging
  51762. + bto determine how long it takes to execute a section of the HCD code.</td>
  51763. + <td> Read</td>
  51764. + </tr>
  51765. +
  51766. + <tr>
  51767. + <td> rd_reg_test </td>
  51768. + <td> Displays the time required to read the GNPTXFSIZ register many times
  51769. + (the output shows the number of times the register is read).
  51770. + <td> Read</td>
  51771. + </tr>
  51772. +
  51773. + <tr>
  51774. + <td> wr_reg_test </td>
  51775. + <td> Displays the time required to write the GNPTXFSIZ register many times
  51776. + (the output shows the number of times the register is written).
  51777. + <td> Read</td>
  51778. + </tr>
  51779. +
  51780. + <tr>
  51781. + <td> lpm_response </td>
  51782. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  51783. + <td> Write</td>
  51784. + </tr>
  51785. +
  51786. + <tr>
  51787. + <td> sleep_status </td>
  51788. + <td> Shows sleep status of device.
  51789. + <td> Read</td>
  51790. + </tr>
  51791. +
  51792. + </table>
  51793. +
  51794. + Example usage:
  51795. + To get the current mode:
  51796. + cat /sys/devices/lm0/mode
  51797. +
  51798. + To power down the USB:
  51799. + echo 0 > /sys/devices/lm0/buspower
  51800. + */
  51801. +
  51802. +#include "dwc_otg_os_dep.h"
  51803. +#include "dwc_os.h"
  51804. +#include "dwc_otg_driver.h"
  51805. +#include "dwc_otg_attr.h"
  51806. +#include "dwc_otg_core_if.h"
  51807. +#include "dwc_otg_pcd_if.h"
  51808. +#include "dwc_otg_hcd_if.h"
  51809. +
  51810. +/*
  51811. + * MACROs for defining sysfs attribute
  51812. + */
  51813. +#ifdef LM_INTERFACE
  51814. +
  51815. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51816. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51817. +{ \
  51818. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51819. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51820. + uint32_t val; \
  51821. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51822. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51823. +}
  51824. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51825. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51826. + const char *buf, size_t count) \
  51827. +{ \
  51828. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51829. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51830. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51831. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51832. + return count; \
  51833. +}
  51834. +
  51835. +#elif defined(PCI_INTERFACE)
  51836. +
  51837. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51838. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51839. +{ \
  51840. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51841. + uint32_t val; \
  51842. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51843. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51844. +}
  51845. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51846. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51847. + const char *buf, size_t count) \
  51848. +{ \
  51849. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51850. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51851. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51852. + return count; \
  51853. +}
  51854. +
  51855. +#elif defined(PLATFORM_INTERFACE)
  51856. +
  51857. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51858. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51859. +{ \
  51860. + struct platform_device *platform_dev = \
  51861. + container_of(_dev, struct platform_device, dev); \
  51862. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51863. + uint32_t val; \
  51864. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51865. + __func__, _dev, platform_dev, otg_dev); \
  51866. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51867. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51868. +}
  51869. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51870. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51871. + const char *buf, size_t count) \
  51872. +{ \
  51873. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51874. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51875. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51876. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51877. + return count; \
  51878. +}
  51879. +#endif
  51880. +
  51881. +/*
  51882. + * MACROs for defining sysfs attribute for 32-bit registers
  51883. + */
  51884. +#ifdef LM_INTERFACE
  51885. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51886. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51887. +{ \
  51888. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51889. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51890. + uint32_t val; \
  51891. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51892. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51893. +}
  51894. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51895. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51896. + const char *buf, size_t count) \
  51897. +{ \
  51898. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51899. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51900. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51901. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51902. + return count; \
  51903. +}
  51904. +#elif defined(PCI_INTERFACE)
  51905. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51906. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51907. +{ \
  51908. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51909. + uint32_t val; \
  51910. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51911. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51912. +}
  51913. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51914. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51915. + const char *buf, size_t count) \
  51916. +{ \
  51917. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51918. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51919. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51920. + return count; \
  51921. +}
  51922. +
  51923. +#elif defined(PLATFORM_INTERFACE)
  51924. +#include "dwc_otg_dbg.h"
  51925. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51926. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51927. +{ \
  51928. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51929. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51930. + uint32_t val; \
  51931. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51932. + __func__, _dev, platform_dev, otg_dev); \
  51933. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51934. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51935. +}
  51936. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51937. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51938. + const char *buf, size_t count) \
  51939. +{ \
  51940. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51941. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51942. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51943. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51944. + return count; \
  51945. +}
  51946. +
  51947. +#endif
  51948. +
  51949. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  51950. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51951. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51952. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51953. +
  51954. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  51955. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51956. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51957. +
  51958. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  51959. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51960. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51961. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51962. +
  51963. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  51964. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51965. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51966. +
  51967. +/** @name Functions for Show/Store of Attributes */
  51968. +/**@{*/
  51969. +
  51970. +/**
  51971. + * Helper function returning the otg_device structure of the given device
  51972. + */
  51973. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  51974. +{
  51975. + dwc_otg_device_t *otg_dev;
  51976. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  51977. + return otg_dev;
  51978. +}
  51979. +
  51980. +/**
  51981. + * Show the register offset of the Register Access.
  51982. + */
  51983. +static ssize_t regoffset_show(struct device *_dev,
  51984. + struct device_attribute *attr, char *buf)
  51985. +{
  51986. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51987. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  51988. + otg_dev->os_dep.reg_offset);
  51989. +}
  51990. +
  51991. +/**
  51992. + * Set the register offset for the next Register Access Read/Write
  51993. + */
  51994. +static ssize_t regoffset_store(struct device *_dev,
  51995. + struct device_attribute *attr,
  51996. + const char *buf, size_t count)
  51997. +{
  51998. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51999. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  52000. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  52001. + if (offset < SZ_256K) {
  52002. +#elif defined(PCI_INTERFACE)
  52003. + if (offset < 0x00040000) {
  52004. +#endif
  52005. + otg_dev->os_dep.reg_offset = offset;
  52006. + } else {
  52007. + dev_err(_dev, "invalid offset\n");
  52008. + }
  52009. +
  52010. + return count;
  52011. +}
  52012. +
  52013. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  52014. +
  52015. +/**
  52016. + * Show the value of the register at the offset in the reg_offset
  52017. + * attribute.
  52018. + */
  52019. +static ssize_t regvalue_show(struct device *_dev,
  52020. + struct device_attribute *attr, char *buf)
  52021. +{
  52022. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52023. + uint32_t val;
  52024. + volatile uint32_t *addr;
  52025. +
  52026. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52027. + /* Calculate the address */
  52028. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52029. + (uint8_t *) otg_dev->os_dep.base);
  52030. + val = DWC_READ_REG32(addr);
  52031. + return snprintf(buf,
  52032. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  52033. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  52034. + val);
  52035. + } else {
  52036. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  52037. + return sprintf(buf, "invalid offset\n");
  52038. + }
  52039. +}
  52040. +
  52041. +/**
  52042. + * Store the value in the register at the offset in the reg_offset
  52043. + * attribute.
  52044. + *
  52045. + */
  52046. +static ssize_t regvalue_store(struct device *_dev,
  52047. + struct device_attribute *attr,
  52048. + const char *buf, size_t count)
  52049. +{
  52050. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52051. + volatile uint32_t *addr;
  52052. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52053. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  52054. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52055. + /* Calculate the address */
  52056. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52057. + (uint8_t *) otg_dev->os_dep.base);
  52058. + DWC_WRITE_REG32(addr, val);
  52059. + } else {
  52060. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  52061. + otg_dev->os_dep.reg_offset);
  52062. + }
  52063. + return count;
  52064. +}
  52065. +
  52066. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  52067. +
  52068. +/*
  52069. + * Attributes
  52070. + */
  52071. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  52072. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  52073. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  52074. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  52075. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  52076. +
  52077. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52078. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52079. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  52080. +
  52081. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  52082. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  52083. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  52084. + "GUSBCFG");
  52085. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  52086. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  52087. + "GRXFSIZ");
  52088. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  52089. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  52090. + "GNPTXFSIZ");
  52091. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  52092. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  52093. + "GPVNDCTL");
  52094. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  52095. + &(otg_dev->core_if->core_global_regs->ggpio),
  52096. + "GGPIO");
  52097. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  52098. + "GUID");
  52099. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  52100. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  52101. + "GSNPSID");
  52102. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  52103. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  52104. +
  52105. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  52106. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  52107. + "HPTXFSIZ");
  52108. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  52109. +
  52110. +/**
  52111. + * @todo Add code to initiate the HNP.
  52112. + */
  52113. +/**
  52114. + * Show the HNP status bit
  52115. + */
  52116. +static ssize_t hnp_show(struct device *_dev,
  52117. + struct device_attribute *attr, char *buf)
  52118. +{
  52119. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52120. + return sprintf(buf, "HstNegScs = 0x%x\n",
  52121. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  52122. +}
  52123. +
  52124. +/**
  52125. + * Set the HNP Request bit
  52126. + */
  52127. +static ssize_t hnp_store(struct device *_dev,
  52128. + struct device_attribute *attr,
  52129. + const char *buf, size_t count)
  52130. +{
  52131. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52132. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52133. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  52134. + return count;
  52135. +}
  52136. +
  52137. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  52138. +
  52139. +/**
  52140. + * @todo Add code to initiate the SRP.
  52141. + */
  52142. +/**
  52143. + * Show the SRP status bit
  52144. + */
  52145. +static ssize_t srp_show(struct device *_dev,
  52146. + struct device_attribute *attr, char *buf)
  52147. +{
  52148. +#ifndef DWC_HOST_ONLY
  52149. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52150. + return sprintf(buf, "SesReqScs = 0x%x\n",
  52151. + dwc_otg_get_srpstatus(otg_dev->core_if));
  52152. +#else
  52153. + return sprintf(buf, "Host Only Mode!\n");
  52154. +#endif
  52155. +}
  52156. +
  52157. +/**
  52158. + * Set the SRP Request bit
  52159. + */
  52160. +static ssize_t srp_store(struct device *_dev,
  52161. + struct device_attribute *attr,
  52162. + const char *buf, size_t count)
  52163. +{
  52164. +#ifndef DWC_HOST_ONLY
  52165. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52166. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  52167. +#endif
  52168. + return count;
  52169. +}
  52170. +
  52171. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  52172. +
  52173. +/**
  52174. + * @todo Need to do more for power on/off?
  52175. + */
  52176. +/**
  52177. + * Show the Bus Power status
  52178. + */
  52179. +static ssize_t buspower_show(struct device *_dev,
  52180. + struct device_attribute *attr, char *buf)
  52181. +{
  52182. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52183. + return sprintf(buf, "Bus Power = 0x%x\n",
  52184. + dwc_otg_get_prtpower(otg_dev->core_if));
  52185. +}
  52186. +
  52187. +/**
  52188. + * Set the Bus Power status
  52189. + */
  52190. +static ssize_t buspower_store(struct device *_dev,
  52191. + struct device_attribute *attr,
  52192. + const char *buf, size_t count)
  52193. +{
  52194. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52195. + uint32_t on = simple_strtoul(buf, NULL, 16);
  52196. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  52197. + return count;
  52198. +}
  52199. +
  52200. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  52201. +
  52202. +/**
  52203. + * @todo Need to do more for suspend?
  52204. + */
  52205. +/**
  52206. + * Show the Bus Suspend status
  52207. + */
  52208. +static ssize_t bussuspend_show(struct device *_dev,
  52209. + struct device_attribute *attr, char *buf)
  52210. +{
  52211. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52212. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  52213. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  52214. +}
  52215. +
  52216. +/**
  52217. + * Set the Bus Suspend status
  52218. + */
  52219. +static ssize_t bussuspend_store(struct device *_dev,
  52220. + struct device_attribute *attr,
  52221. + const char *buf, size_t count)
  52222. +{
  52223. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52224. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52225. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  52226. + return count;
  52227. +}
  52228. +
  52229. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  52230. +
  52231. +/**
  52232. + * Show the Mode Change Ready Timer status
  52233. + */
  52234. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  52235. + struct device_attribute *attr, char *buf)
  52236. +{
  52237. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52238. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  52239. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  52240. +}
  52241. +
  52242. +/**
  52243. + * Set the Mode Change Ready Timer status
  52244. + */
  52245. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  52246. + struct device_attribute *attr,
  52247. + const char *buf, size_t count)
  52248. +{
  52249. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52250. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52251. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  52252. + return count;
  52253. +}
  52254. +
  52255. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  52256. +
  52257. +/**
  52258. + * Show the value of HFIR Frame Interval bitfield
  52259. + */
  52260. +static ssize_t fr_interval_show(struct device *_dev,
  52261. + struct device_attribute *attr, char *buf)
  52262. +{
  52263. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52264. + return sprintf(buf, "Frame Interval = 0x%x\n",
  52265. + dwc_otg_get_fr_interval(otg_dev->core_if));
  52266. +}
  52267. +
  52268. +/**
  52269. + * Set the HFIR Frame Interval value
  52270. + */
  52271. +static ssize_t fr_interval_store(struct device *_dev,
  52272. + struct device_attribute *attr,
  52273. + const char *buf, size_t count)
  52274. +{
  52275. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52276. + uint32_t in = simple_strtoul(buf, NULL, 10);
  52277. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  52278. + return count;
  52279. +}
  52280. +
  52281. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  52282. +
  52283. +/**
  52284. + * Show the status of Remote Wakeup.
  52285. + */
  52286. +static ssize_t remote_wakeup_show(struct device *_dev,
  52287. + struct device_attribute *attr, char *buf)
  52288. +{
  52289. +#ifndef DWC_HOST_ONLY
  52290. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52291. +
  52292. + return sprintf(buf,
  52293. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  52294. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  52295. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  52296. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  52297. +#else
  52298. + return sprintf(buf, "Host Only Mode!\n");
  52299. +#endif /* DWC_HOST_ONLY */
  52300. +}
  52301. +
  52302. +/**
  52303. + * Initiate a remote wakeup of the host. The Device control register
  52304. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  52305. + * flag is set.
  52306. + *
  52307. + */
  52308. +static ssize_t remote_wakeup_store(struct device *_dev,
  52309. + struct device_attribute *attr,
  52310. + const char *buf, size_t count)
  52311. +{
  52312. +#ifndef DWC_HOST_ONLY
  52313. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52314. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52315. +
  52316. + if (val & 1) {
  52317. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  52318. + } else {
  52319. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  52320. + }
  52321. +#endif /* DWC_HOST_ONLY */
  52322. + return count;
  52323. +}
  52324. +
  52325. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  52326. + remote_wakeup_store);
  52327. +
  52328. +/**
  52329. + * Show the whether core is hibernated or not.
  52330. + */
  52331. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  52332. + struct device_attribute *attr, char *buf)
  52333. +{
  52334. +#ifndef DWC_HOST_ONLY
  52335. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52336. +
  52337. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  52338. + DWC_PRINTF("Core is in hibernation\n");
  52339. + } else {
  52340. + DWC_PRINTF("Core is not in hibernation\n");
  52341. + }
  52342. +#endif /* DWC_HOST_ONLY */
  52343. + return 0;
  52344. +}
  52345. +
  52346. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  52347. + int rem_wakeup, int reset);
  52348. +
  52349. +/**
  52350. + * Initiate a remote wakeup of the device to exit from hibernation.
  52351. + */
  52352. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  52353. + struct device_attribute *attr,
  52354. + const char *buf, size_t count)
  52355. +{
  52356. +#ifndef DWC_HOST_ONLY
  52357. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52358. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  52359. +#endif
  52360. + return count;
  52361. +}
  52362. +
  52363. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  52364. + rem_wakeup_pwrdn_store);
  52365. +
  52366. +static ssize_t disconnect_us(struct device *_dev,
  52367. + struct device_attribute *attr,
  52368. + const char *buf, size_t count)
  52369. +{
  52370. +
  52371. +#ifndef DWC_HOST_ONLY
  52372. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52373. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52374. + DWC_PRINTF("The Passed value is %04x\n", val);
  52375. +
  52376. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  52377. +
  52378. +#endif /* DWC_HOST_ONLY */
  52379. + return count;
  52380. +}
  52381. +
  52382. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  52383. +
  52384. +/**
  52385. + * Dump global registers and either host or device registers (depending on the
  52386. + * current mode of the core).
  52387. + */
  52388. +static ssize_t regdump_show(struct device *_dev,
  52389. + struct device_attribute *attr, char *buf)
  52390. +{
  52391. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52392. +
  52393. + dwc_otg_dump_global_registers(otg_dev->core_if);
  52394. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  52395. + dwc_otg_dump_host_registers(otg_dev->core_if);
  52396. + } else {
  52397. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  52398. +
  52399. + }
  52400. + return sprintf(buf, "Register Dump\n");
  52401. +}
  52402. +
  52403. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  52404. +
  52405. +/**
  52406. + * Dump global registers and either host or device registers (depending on the
  52407. + * current mode of the core).
  52408. + */
  52409. +static ssize_t spramdump_show(struct device *_dev,
  52410. + struct device_attribute *attr, char *buf)
  52411. +{
  52412. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52413. +
  52414. + //dwc_otg_dump_spram(otg_dev->core_if);
  52415. +
  52416. + return sprintf(buf, "SPRAM Dump\n");
  52417. +}
  52418. +
  52419. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  52420. +
  52421. +/**
  52422. + * Dump the current hcd state.
  52423. + */
  52424. +static ssize_t hcddump_show(struct device *_dev,
  52425. + struct device_attribute *attr, char *buf)
  52426. +{
  52427. +#ifndef DWC_DEVICE_ONLY
  52428. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52429. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  52430. +#endif /* DWC_DEVICE_ONLY */
  52431. + return sprintf(buf, "HCD Dump\n");
  52432. +}
  52433. +
  52434. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  52435. +
  52436. +/**
  52437. + * Dump the average frame remaining at SOF. This can be used to
  52438. + * determine average interrupt latency. Frame remaining is also shown for
  52439. + * start transfer and two additional sample points.
  52440. + */
  52441. +static ssize_t hcd_frrem_show(struct device *_dev,
  52442. + struct device_attribute *attr, char *buf)
  52443. +{
  52444. +#ifndef DWC_DEVICE_ONLY
  52445. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52446. +
  52447. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  52448. +#endif /* DWC_DEVICE_ONLY */
  52449. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  52450. +}
  52451. +
  52452. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  52453. +
  52454. +/**
  52455. + * Displays the time required to read the GNPTXFSIZ register many times (the
  52456. + * output shows the number of times the register is read).
  52457. + */
  52458. +#define RW_REG_COUNT 10000000
  52459. +#define MSEC_PER_JIFFIE 1000/HZ
  52460. +static ssize_t rd_reg_test_show(struct device *_dev,
  52461. + struct device_attribute *attr, char *buf)
  52462. +{
  52463. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52464. + int i;
  52465. + int time;
  52466. + int start_jiffies;
  52467. +
  52468. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52469. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52470. + start_jiffies = jiffies;
  52471. + for (i = 0; i < RW_REG_COUNT; i++) {
  52472. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52473. + }
  52474. + time = jiffies - start_jiffies;
  52475. + return sprintf(buf,
  52476. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52477. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52478. +}
  52479. +
  52480. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  52481. +
  52482. +/**
  52483. + * Displays the time required to write the GNPTXFSIZ register many times (the
  52484. + * output shows the number of times the register is written).
  52485. + */
  52486. +static ssize_t wr_reg_test_show(struct device *_dev,
  52487. + struct device_attribute *attr, char *buf)
  52488. +{
  52489. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52490. + uint32_t reg_val;
  52491. + int i;
  52492. + int time;
  52493. + int start_jiffies;
  52494. +
  52495. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52496. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52497. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52498. + start_jiffies = jiffies;
  52499. + for (i = 0; i < RW_REG_COUNT; i++) {
  52500. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  52501. + }
  52502. + time = jiffies - start_jiffies;
  52503. + return sprintf(buf,
  52504. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52505. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52506. +}
  52507. +
  52508. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  52509. +
  52510. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52511. +
  52512. +/**
  52513. +* Show the lpm_response attribute.
  52514. +*/
  52515. +static ssize_t lpmresp_show(struct device *_dev,
  52516. + struct device_attribute *attr, char *buf)
  52517. +{
  52518. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52519. +
  52520. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  52521. + return sprintf(buf, "** LPM is DISABLED **\n");
  52522. +
  52523. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52524. + return sprintf(buf, "** Current mode is not device mode\n");
  52525. + }
  52526. + return sprintf(buf, "lpm_response = %d\n",
  52527. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  52528. +}
  52529. +
  52530. +/**
  52531. +* Store the lpm_response attribute.
  52532. +*/
  52533. +static ssize_t lpmresp_store(struct device *_dev,
  52534. + struct device_attribute *attr,
  52535. + const char *buf, size_t count)
  52536. +{
  52537. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52538. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52539. +
  52540. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  52541. + return 0;
  52542. + }
  52543. +
  52544. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52545. + return 0;
  52546. + }
  52547. +
  52548. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  52549. + return count;
  52550. +}
  52551. +
  52552. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  52553. +
  52554. +/**
  52555. +* Show the sleep_status attribute.
  52556. +*/
  52557. +static ssize_t sleepstatus_show(struct device *_dev,
  52558. + struct device_attribute *attr, char *buf)
  52559. +{
  52560. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52561. + return sprintf(buf, "Sleep Status = %d\n",
  52562. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  52563. +}
  52564. +
  52565. +/**
  52566. + * Store the sleep_status attribure.
  52567. + */
  52568. +static ssize_t sleepstatus_store(struct device *_dev,
  52569. + struct device_attribute *attr,
  52570. + const char *buf, size_t count)
  52571. +{
  52572. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52573. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  52574. +
  52575. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  52576. + if (dwc_otg_is_host_mode(core_if)) {
  52577. +
  52578. + DWC_PRINTF("Host initiated resume\n");
  52579. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  52580. + }
  52581. + }
  52582. +
  52583. + return count;
  52584. +}
  52585. +
  52586. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  52587. + sleepstatus_store);
  52588. +
  52589. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  52590. +
  52591. +/**@}*/
  52592. +
  52593. +/**
  52594. + * Create the device files
  52595. + */
  52596. +void dwc_otg_attr_create(
  52597. +#ifdef LM_INTERFACE
  52598. + struct lm_device *dev
  52599. +#elif defined(PCI_INTERFACE)
  52600. + struct pci_dev *dev
  52601. +#elif defined(PLATFORM_INTERFACE)
  52602. + struct platform_device *dev
  52603. +#endif
  52604. + )
  52605. +{
  52606. + int error;
  52607. +
  52608. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  52609. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  52610. + error = device_create_file(&dev->dev, &dev_attr_mode);
  52611. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  52612. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  52613. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  52614. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52615. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  52616. + error = device_create_file(&dev->dev, &dev_attr_srp);
  52617. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  52618. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  52619. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52620. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  52621. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  52622. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  52623. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  52624. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  52625. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  52626. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  52627. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  52628. + error = device_create_file(&dev->dev, &dev_attr_guid);
  52629. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  52630. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  52631. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  52632. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  52633. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  52634. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  52635. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52636. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  52637. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  52638. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  52639. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  52640. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  52641. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  52642. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  52643. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52644. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  52645. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  52646. +#endif
  52647. +}
  52648. +
  52649. +/**
  52650. + * Remove the device files
  52651. + */
  52652. +void dwc_otg_attr_remove(
  52653. +#ifdef LM_INTERFACE
  52654. + struct lm_device *dev
  52655. +#elif defined(PCI_INTERFACE)
  52656. + struct pci_dev *dev
  52657. +#elif defined(PLATFORM_INTERFACE)
  52658. + struct platform_device *dev
  52659. +#endif
  52660. + )
  52661. +{
  52662. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  52663. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  52664. + device_remove_file(&dev->dev, &dev_attr_mode);
  52665. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  52666. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  52667. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  52668. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52669. + device_remove_file(&dev->dev, &dev_attr_hnp);
  52670. + device_remove_file(&dev->dev, &dev_attr_srp);
  52671. + device_remove_file(&dev->dev, &dev_attr_buspower);
  52672. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  52673. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52674. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  52675. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  52676. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  52677. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  52678. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  52679. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  52680. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  52681. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  52682. + device_remove_file(&dev->dev, &dev_attr_guid);
  52683. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  52684. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  52685. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  52686. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  52687. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  52688. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  52689. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52690. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  52691. + device_remove_file(&dev->dev, &dev_attr_regdump);
  52692. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  52693. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  52694. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  52695. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  52696. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  52697. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52698. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  52699. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  52700. +#endif
  52701. +}
  52702. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  52703. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  52704. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-02-07 19:57:30.000000000 +0100
  52705. @@ -0,0 +1,89 @@
  52706. +/* ==========================================================================
  52707. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  52708. + * $Revision: #13 $
  52709. + * $Date: 2010/06/21 $
  52710. + * $Change: 1532021 $
  52711. + *
  52712. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52713. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52714. + * otherwise expressly agreed to in writing between Synopsys and you.
  52715. + *
  52716. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52717. + * any End User Software License Agreement or Agreement for Licensed Product
  52718. + * with Synopsys or any supplement thereto. You are permitted to use and
  52719. + * redistribute this Software in source and binary forms, with or without
  52720. + * modification, provided that redistributions of source code must retain this
  52721. + * notice. You may not view, use, disclose, copy or distribute this file or
  52722. + * any information contained herein except pursuant to this license grant from
  52723. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52724. + * below, then you are not authorized to use the Software.
  52725. + *
  52726. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52727. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52728. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52729. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52730. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52731. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52732. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52733. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52734. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52735. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52736. + * DAMAGE.
  52737. + * ========================================================================== */
  52738. +
  52739. +#if !defined(__DWC_OTG_ATTR_H__)
  52740. +#define __DWC_OTG_ATTR_H__
  52741. +
  52742. +/** @file
  52743. + * This file contains the interface to the Linux device attributes.
  52744. + */
  52745. +extern struct device_attribute dev_attr_regoffset;
  52746. +extern struct device_attribute dev_attr_regvalue;
  52747. +
  52748. +extern struct device_attribute dev_attr_mode;
  52749. +extern struct device_attribute dev_attr_hnpcapable;
  52750. +extern struct device_attribute dev_attr_srpcapable;
  52751. +extern struct device_attribute dev_attr_hnp;
  52752. +extern struct device_attribute dev_attr_srp;
  52753. +extern struct device_attribute dev_attr_buspower;
  52754. +extern struct device_attribute dev_attr_bussuspend;
  52755. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  52756. +extern struct device_attribute dev_attr_fr_interval;
  52757. +extern struct device_attribute dev_attr_busconnected;
  52758. +extern struct device_attribute dev_attr_gotgctl;
  52759. +extern struct device_attribute dev_attr_gusbcfg;
  52760. +extern struct device_attribute dev_attr_grxfsiz;
  52761. +extern struct device_attribute dev_attr_gnptxfsiz;
  52762. +extern struct device_attribute dev_attr_gpvndctl;
  52763. +extern struct device_attribute dev_attr_ggpio;
  52764. +extern struct device_attribute dev_attr_guid;
  52765. +extern struct device_attribute dev_attr_gsnpsid;
  52766. +extern struct device_attribute dev_attr_devspeed;
  52767. +extern struct device_attribute dev_attr_enumspeed;
  52768. +extern struct device_attribute dev_attr_hptxfsiz;
  52769. +extern struct device_attribute dev_attr_hprt0;
  52770. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52771. +extern struct device_attribute dev_attr_lpm_response;
  52772. +extern struct device_attribute devi_attr_sleep_status;
  52773. +#endif
  52774. +
  52775. +void dwc_otg_attr_create(
  52776. +#ifdef LM_INTERFACE
  52777. + struct lm_device *dev
  52778. +#elif defined(PCI_INTERFACE)
  52779. + struct pci_dev *dev
  52780. +#elif defined(PLATFORM_INTERFACE)
  52781. + struct platform_device *dev
  52782. +#endif
  52783. + );
  52784. +
  52785. +void dwc_otg_attr_remove(
  52786. +#ifdef LM_INTERFACE
  52787. + struct lm_device *dev
  52788. +#elif defined(PCI_INTERFACE)
  52789. + struct pci_dev *dev
  52790. +#elif defined(PLATFORM_INTERFACE)
  52791. + struct platform_device *dev
  52792. +#endif
  52793. + );
  52794. +#endif
  52795. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  52796. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  52797. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-02-07 19:57:30.000000000 +0100
  52798. @@ -0,0 +1,1876 @@
  52799. +/* ==========================================================================
  52800. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52801. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52802. + * otherwise expressly agreed to in writing between Synopsys and you.
  52803. + *
  52804. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52805. + * any End User Software License Agreement or Agreement for Licensed Product
  52806. + * with Synopsys or any supplement thereto. You are permitted to use and
  52807. + * redistribute this Software in source and binary forms, with or without
  52808. + * modification, provided that redistributions of source code must retain this
  52809. + * notice. You may not view, use, disclose, copy or distribute this file or
  52810. + * any information contained herein except pursuant to this license grant from
  52811. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52812. + * below, then you are not authorized to use the Software.
  52813. + *
  52814. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52815. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52816. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52817. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52818. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52819. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52820. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52821. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52822. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52823. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52824. + * DAMAGE.
  52825. + * ========================================================================== */
  52826. +
  52827. +/** @file
  52828. + *
  52829. + * This file contains the most of the CFI(Core Feature Interface)
  52830. + * implementation for the OTG.
  52831. + */
  52832. +
  52833. +#ifdef DWC_UTE_CFI
  52834. +
  52835. +#include "dwc_otg_pcd.h"
  52836. +#include "dwc_otg_cfi.h"
  52837. +
  52838. +/** This definition should actually migrate to the Portability Library */
  52839. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  52840. +
  52841. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  52842. +
  52843. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  52844. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  52845. + struct dwc_otg_pcd *pcd,
  52846. + struct cfi_usb_ctrlrequest *ctrl_req);
  52847. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  52848. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52849. + struct cfi_usb_ctrlrequest *req);
  52850. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52851. + struct cfi_usb_ctrlrequest *req);
  52852. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52853. + struct cfi_usb_ctrlrequest *req);
  52854. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  52855. + struct cfi_usb_ctrlrequest *req);
  52856. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  52857. +
  52858. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  52859. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  52860. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  52861. +
  52862. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  52863. +
  52864. +/** This is the header of the all features descriptor */
  52865. +static cfi_all_features_header_t all_props_desc_header = {
  52866. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  52867. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  52868. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  52869. +};
  52870. +
  52871. +/** This is an array of statically allocated feature descriptors */
  52872. +static cfi_feature_desc_header_t prop_descs[] = {
  52873. +
  52874. + /* FT_ID_DMA_MODE */
  52875. + {
  52876. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  52877. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52878. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  52879. + },
  52880. +
  52881. + /* FT_ID_DMA_BUFFER_SETUP */
  52882. + {
  52883. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  52884. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52885. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52886. + },
  52887. +
  52888. + /* FT_ID_DMA_BUFF_ALIGN */
  52889. + {
  52890. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  52891. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52892. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52893. + },
  52894. +
  52895. + /* FT_ID_DMA_CONCAT_SETUP */
  52896. + {
  52897. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  52898. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52899. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52900. + },
  52901. +
  52902. + /* FT_ID_DMA_CIRCULAR */
  52903. + {
  52904. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  52905. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52906. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52907. + },
  52908. +
  52909. + /* FT_ID_THRESHOLD_SETUP */
  52910. + {
  52911. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  52912. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52913. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52914. + },
  52915. +
  52916. + /* FT_ID_DFIFO_DEPTH */
  52917. + {
  52918. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  52919. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  52920. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52921. + },
  52922. +
  52923. + /* FT_ID_TX_FIFO_DEPTH */
  52924. + {
  52925. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  52926. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52927. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52928. + },
  52929. +
  52930. + /* FT_ID_RX_FIFO_DEPTH */
  52931. + {
  52932. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  52933. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52934. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52935. + }
  52936. +};
  52937. +
  52938. +/** The table of feature names */
  52939. +cfi_string_t prop_name_table[] = {
  52940. + {FT_ID_DMA_MODE, "dma_mode"},
  52941. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  52942. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  52943. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  52944. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  52945. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  52946. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  52947. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  52948. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  52949. + {}
  52950. +};
  52951. +
  52952. +/************************************************************************/
  52953. +
  52954. +/**
  52955. + * Returns the name of the feature by its ID
  52956. + * or NULL if no featute ID matches.
  52957. + *
  52958. + */
  52959. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  52960. +{
  52961. + cfi_string_t *pstr;
  52962. + *len = 0;
  52963. +
  52964. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  52965. + if (pstr->id == prop_id) {
  52966. + *len = DWC_STRLEN(pstr->s);
  52967. + return pstr->s;
  52968. + }
  52969. + }
  52970. + return NULL;
  52971. +}
  52972. +
  52973. +/**
  52974. + * This function handles all CFI specific control requests.
  52975. + *
  52976. + * Return a negative value to stall the DCE.
  52977. + */
  52978. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  52979. +{
  52980. + int retval = 0;
  52981. + dwc_otg_pcd_ep_t *ep = NULL;
  52982. + cfiobject_t *cfi = pcd->cfi;
  52983. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  52984. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  52985. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  52986. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  52987. + uint32_t regaddr = 0;
  52988. + uint32_t regval = 0;
  52989. +
  52990. + /* Save this Control Request in the CFI object.
  52991. + * The data field will be assigned in the data stage completion CB function.
  52992. + */
  52993. + cfi->ctrl_req = *ctrl;
  52994. + cfi->ctrl_req.data = NULL;
  52995. +
  52996. + cfi->need_gadget_att = 0;
  52997. + cfi->need_status_in_complete = 0;
  52998. +
  52999. + switch (ctrl->bRequest) {
  53000. + case VEN_CORE_GET_FEATURES:
  53001. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  53002. + if (retval >= 0) {
  53003. + //dump_msg(cfi->buf_in.buf, retval);
  53004. + ep = &pcd->ep0;
  53005. +
  53006. + retval = min((uint16_t) retval, wLen);
  53007. + /* Transfer this buffer to the host through the EP0-IN EP */
  53008. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53009. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53010. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53011. + ep->dwc_ep.xfer_len = retval;
  53012. + ep->dwc_ep.xfer_count = 0;
  53013. + ep->dwc_ep.sent_zlp = 0;
  53014. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53015. +
  53016. + pcd->ep0_pending = 1;
  53017. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53018. + }
  53019. + retval = 0;
  53020. + break;
  53021. +
  53022. + case VEN_CORE_GET_FEATURE:
  53023. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  53024. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  53025. + pcd, ctrl);
  53026. + if (retval >= 0) {
  53027. + ep = &pcd->ep0;
  53028. +
  53029. + retval = min((uint16_t) retval, wLen);
  53030. + /* Transfer this buffer to the host through the EP0-IN EP */
  53031. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53032. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53033. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53034. + ep->dwc_ep.xfer_len = retval;
  53035. + ep->dwc_ep.xfer_count = 0;
  53036. + ep->dwc_ep.sent_zlp = 0;
  53037. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53038. +
  53039. + pcd->ep0_pending = 1;
  53040. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53041. + }
  53042. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  53043. + dump_msg(cfi->buf_in.buf, retval);
  53044. + break;
  53045. +
  53046. + case VEN_CORE_SET_FEATURE:
  53047. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  53048. + /* Set up an XFER to get the data stage of the control request,
  53049. + * which is the new value of the feature to be modified.
  53050. + */
  53051. + ep = &pcd->ep0;
  53052. + ep->dwc_ep.is_in = 0;
  53053. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53054. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53055. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53056. + ep->dwc_ep.xfer_len = wLen;
  53057. + ep->dwc_ep.xfer_count = 0;
  53058. + ep->dwc_ep.sent_zlp = 0;
  53059. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53060. +
  53061. + pcd->ep0_pending = 1;
  53062. + /* Read the control write's data stage */
  53063. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53064. + retval = 0;
  53065. + break;
  53066. +
  53067. + case VEN_CORE_RESET_FEATURES:
  53068. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  53069. + cfi->need_gadget_att = 1;
  53070. + cfi->need_status_in_complete = 1;
  53071. + retval = cfi_preproc_reset(pcd, ctrl);
  53072. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  53073. + break;
  53074. +
  53075. + case VEN_CORE_ACTIVATE_FEATURES:
  53076. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  53077. + break;
  53078. +
  53079. + case VEN_CORE_READ_REGISTER:
  53080. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  53081. + /* wValue optionally contains the HI WORD of the register offset and
  53082. + * wIndex contains the LOW WORD of the register offset
  53083. + */
  53084. + if (wValue == 0) {
  53085. + /* @TODO - MAS - fix the access to the base field */
  53086. + regaddr = 0;
  53087. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  53088. + //GET_CORE_IF(pcd)->co
  53089. + regaddr |= wIndex;
  53090. + } else {
  53091. + regaddr = (wValue << 16) | wIndex;
  53092. + }
  53093. +
  53094. + /* Read a 32-bit value of the memory at the regaddr */
  53095. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  53096. +
  53097. + ep = &pcd->ep0;
  53098. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  53099. + ep->dwc_ep.is_in = 1;
  53100. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53101. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53102. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53103. + ep->dwc_ep.xfer_len = wLen;
  53104. + ep->dwc_ep.xfer_count = 0;
  53105. + ep->dwc_ep.sent_zlp = 0;
  53106. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53107. +
  53108. + pcd->ep0_pending = 1;
  53109. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53110. + cfi->need_gadget_att = 0;
  53111. + retval = 0;
  53112. + break;
  53113. +
  53114. + case VEN_CORE_WRITE_REGISTER:
  53115. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  53116. + /* Set up an XFER to get the data stage of the control request,
  53117. + * which is the new value of the register to be modified.
  53118. + */
  53119. + ep = &pcd->ep0;
  53120. + ep->dwc_ep.is_in = 0;
  53121. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53122. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53123. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53124. + ep->dwc_ep.xfer_len = wLen;
  53125. + ep->dwc_ep.xfer_count = 0;
  53126. + ep->dwc_ep.sent_zlp = 0;
  53127. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53128. +
  53129. + pcd->ep0_pending = 1;
  53130. + /* Read the control write's data stage */
  53131. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53132. + retval = 0;
  53133. + break;
  53134. +
  53135. + default:
  53136. + retval = -DWC_E_NOT_SUPPORTED;
  53137. + break;
  53138. + }
  53139. +
  53140. + return retval;
  53141. +}
  53142. +
  53143. +/**
  53144. + * This function prepares the core features descriptors and copies its
  53145. + * raw representation into the buffer <buf>.
  53146. + *
  53147. + * The buffer structure is as follows:
  53148. + * all_features_header (8 bytes)
  53149. + * features_#1 (8 bytes + feature name string length)
  53150. + * features_#2 (8 bytes + feature name string length)
  53151. + * .....
  53152. + * features_#n - where n=the total count of feature descriptors
  53153. + */
  53154. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  53155. +{
  53156. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  53157. + cfi_feature_desc_header_t *prop;
  53158. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  53159. + cfi_all_features_header_t *tmp;
  53160. + uint8_t *tmpbuf = buf;
  53161. + const uint8_t *pname = NULL;
  53162. + int i, j, namelen = 0, totlen;
  53163. +
  53164. + /* Prepare and copy the core features into the buffer */
  53165. + CFI_INFO("%s:\n", __func__);
  53166. +
  53167. + tmp = (cfi_all_features_header_t *) tmpbuf;
  53168. + *tmp = *all_props_hdr;
  53169. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  53170. +
  53171. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  53172. + for (i = 0; i < j; i++, prop_hdr++) {
  53173. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  53174. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  53175. + *prop = *prop_hdr;
  53176. +
  53177. + prop->bNameLen = namelen;
  53178. + prop->wLength =
  53179. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  53180. + namelen);
  53181. +
  53182. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  53183. + dwc_memcpy(tmpbuf, pname, namelen);
  53184. + tmpbuf += namelen;
  53185. + }
  53186. +
  53187. + totlen = tmpbuf - buf;
  53188. +
  53189. + if (totlen > 0) {
  53190. + tmp = (cfi_all_features_header_t *) buf;
  53191. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  53192. + }
  53193. +
  53194. + return totlen;
  53195. +}
  53196. +
  53197. +/**
  53198. + * This function releases all the dynamic memory in the CFI object.
  53199. + */
  53200. +static void cfi_release(cfiobject_t * cfiobj)
  53201. +{
  53202. + cfi_ep_t *cfiep;
  53203. + dwc_list_link_t *tmp;
  53204. +
  53205. + CFI_INFO("%s\n", __func__);
  53206. +
  53207. + if (cfiobj->buf_in.buf) {
  53208. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  53209. + cfiobj->buf_in.addr);
  53210. + cfiobj->buf_in.buf = NULL;
  53211. + }
  53212. +
  53213. + if (cfiobj->buf_out.buf) {
  53214. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  53215. + cfiobj->buf_out.addr);
  53216. + cfiobj->buf_out.buf = NULL;
  53217. + }
  53218. +
  53219. + /* Free the Buffer Setup values for each EP */
  53220. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  53221. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  53222. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53223. + cfi_free_ep_bs_dyn_data(cfiep);
  53224. + }
  53225. +}
  53226. +
  53227. +/**
  53228. + * This function frees the dynamically allocated EP buffer setup data.
  53229. + */
  53230. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  53231. +{
  53232. + if (cfiep->bm_sg) {
  53233. + DWC_FREE(cfiep->bm_sg);
  53234. + cfiep->bm_sg = NULL;
  53235. + }
  53236. +
  53237. + if (cfiep->bm_align) {
  53238. + DWC_FREE(cfiep->bm_align);
  53239. + cfiep->bm_align = NULL;
  53240. + }
  53241. +
  53242. + if (cfiep->bm_concat) {
  53243. + if (NULL != cfiep->bm_concat->wTxBytes) {
  53244. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53245. + cfiep->bm_concat->wTxBytes = NULL;
  53246. + }
  53247. + DWC_FREE(cfiep->bm_concat);
  53248. + cfiep->bm_concat = NULL;
  53249. + }
  53250. +}
  53251. +
  53252. +/**
  53253. + * This function initializes the default values of the features
  53254. + * for a specific endpoint and should be called only once when
  53255. + * the EP is enabled first time.
  53256. + */
  53257. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  53258. +{
  53259. + int retval = 0;
  53260. +
  53261. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  53262. + if (NULL == cfiep->bm_sg) {
  53263. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  53264. + return -DWC_E_NO_MEMORY;
  53265. + }
  53266. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53267. +
  53268. + /* For the Concatenation feature's default value we do not allocate
  53269. + * memory for the wTxBytes field - it will be done in the set_feature_value
  53270. + * request handler.
  53271. + */
  53272. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  53273. + if (NULL == cfiep->bm_concat) {
  53274. + CFI_INFO
  53275. + ("Failed to allocate memory for CONCATENATION feature value\n");
  53276. + DWC_FREE(cfiep->bm_sg);
  53277. + return -DWC_E_NO_MEMORY;
  53278. + }
  53279. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53280. +
  53281. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  53282. + if (NULL == cfiep->bm_align) {
  53283. + CFI_INFO
  53284. + ("Failed to allocate memory for Alignment feature value\n");
  53285. + DWC_FREE(cfiep->bm_sg);
  53286. + DWC_FREE(cfiep->bm_concat);
  53287. + return -DWC_E_NO_MEMORY;
  53288. + }
  53289. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  53290. +
  53291. + return retval;
  53292. +}
  53293. +
  53294. +/**
  53295. + * The callback function that notifies the CFI on the activation of
  53296. + * an endpoint in the PCD. The following steps are done in this function:
  53297. + *
  53298. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  53299. + * active endpoint)
  53300. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  53301. + * Set the Buffer Mode to standard
  53302. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  53303. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  53304. + */
  53305. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53306. + struct dwc_otg_pcd_ep *ep)
  53307. +{
  53308. + cfi_ep_t *cfiep;
  53309. + int retval = -DWC_E_NOT_SUPPORTED;
  53310. +
  53311. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  53312. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  53313. + /* MAS - Check whether this endpoint already is in the list */
  53314. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53315. +
  53316. + if (NULL == cfiep) {
  53317. + /* Allocate a cfi_ep_t object */
  53318. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  53319. + if (NULL == cfiep) {
  53320. + CFI_INFO
  53321. + ("Unable to allocate memory for <cfiep> in function %s\n",
  53322. + __func__);
  53323. + return -DWC_E_NO_MEMORY;
  53324. + }
  53325. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  53326. +
  53327. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  53328. + cfiep->ep = ep;
  53329. +
  53330. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  53331. + ep->dwc_ep.descs =
  53332. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  53333. + sizeof(dwc_otg_dma_desc_t),
  53334. + &ep->dwc_ep.descs_dma_addr);
  53335. +
  53336. + if (NULL == ep->dwc_ep.descs) {
  53337. + DWC_FREE(cfiep);
  53338. + return -DWC_E_NO_MEMORY;
  53339. + }
  53340. +
  53341. + DWC_LIST_INIT(&cfiep->lh);
  53342. +
  53343. + /* Set the buffer mode to BM_STANDARD. It will be modified
  53344. + * when building descriptors for a specific buffer mode */
  53345. + ep->dwc_ep.buff_mode = BM_STANDARD;
  53346. +
  53347. + /* Create and initialize the default values for this EP's Buffer modes */
  53348. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  53349. + return retval;
  53350. +
  53351. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  53352. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  53353. + retval = 0;
  53354. + } else { /* The sought EP already is in the list */
  53355. + CFI_INFO("%s: The sought EP already is in the list\n",
  53356. + __func__);
  53357. + }
  53358. +
  53359. + return retval;
  53360. +}
  53361. +
  53362. +/**
  53363. + * This function is called when the data stage of a 3-stage Control Write request
  53364. + * is complete.
  53365. + *
  53366. + */
  53367. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  53368. + struct dwc_otg_pcd *pcd)
  53369. +{
  53370. + uint32_t addr, reg_value;
  53371. + uint16_t wIndex, wValue;
  53372. + uint8_t bRequest;
  53373. + uint8_t *buf = cfi->buf_out.buf;
  53374. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  53375. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  53376. + int retval = -DWC_E_NOT_SUPPORTED;
  53377. +
  53378. + CFI_INFO("%s\n", __func__);
  53379. +
  53380. + bRequest = ctrl_req->bRequest;
  53381. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  53382. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  53383. +
  53384. + /*
  53385. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  53386. + * The request should be already saved in the command stage by now.
  53387. + */
  53388. + ctrl_req->data = cfi->buf_out.buf;
  53389. + cfi->need_status_in_complete = 0;
  53390. + cfi->need_gadget_att = 0;
  53391. +
  53392. + switch (bRequest) {
  53393. + case VEN_CORE_WRITE_REGISTER:
  53394. + /* The buffer contains raw data of the new value for the register */
  53395. + reg_value = *((uint32_t *) buf);
  53396. + if (wValue == 0) {
  53397. + addr = 0;
  53398. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  53399. + addr += wIndex;
  53400. + } else {
  53401. + addr = (wValue << 16) | wIndex;
  53402. + }
  53403. +
  53404. + //writel(reg_value, addr);
  53405. +
  53406. + retval = 0;
  53407. + cfi->need_status_in_complete = 1;
  53408. + break;
  53409. +
  53410. + case VEN_CORE_SET_FEATURE:
  53411. + /* The buffer contains raw data of the new value of the feature */
  53412. + retval = cfi_set_feature_value(pcd);
  53413. + if (retval < 0)
  53414. + return retval;
  53415. +
  53416. + cfi->need_status_in_complete = 1;
  53417. + break;
  53418. +
  53419. + default:
  53420. + break;
  53421. + }
  53422. +
  53423. + return retval;
  53424. +}
  53425. +
  53426. +/**
  53427. + * This function builds the DMA descriptors for the SG buffer mode.
  53428. + */
  53429. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53430. + dwc_otg_pcd_request_t * req)
  53431. +{
  53432. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53433. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  53434. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53435. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53436. + dma_addr_t buff_addr = req->dma;
  53437. + int i;
  53438. + uint32_t txsize, off;
  53439. +
  53440. + txsize = sgval->wSize;
  53441. + off = sgval->bOffset;
  53442. +
  53443. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  53444. +// __func__, cfiep->ep->ep.name, txsize, off);
  53445. +
  53446. + for (i = 0; i < sgval->bCount; i++) {
  53447. + desc->status.b.bs = BS_HOST_BUSY;
  53448. + desc->buf = buff_addr;
  53449. + desc->status.b.l = 0;
  53450. + desc->status.b.ioc = 0;
  53451. + desc->status.b.sp = 0;
  53452. + desc->status.b.bytes = txsize;
  53453. + desc->status.b.bs = BS_HOST_READY;
  53454. +
  53455. + /* Set the next address of the buffer */
  53456. + buff_addr += txsize + off;
  53457. + desc_last = desc;
  53458. + desc++;
  53459. + }
  53460. +
  53461. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53462. + desc_last->status.b.l = 1;
  53463. + desc_last->status.b.ioc = 1;
  53464. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53465. + /* Save the last DMA descriptor pointer */
  53466. + cfiep->dma_desc_last = desc_last;
  53467. + cfiep->desc_count = sgval->bCount;
  53468. +}
  53469. +
  53470. +/**
  53471. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  53472. + */
  53473. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53474. + dwc_otg_pcd_request_t * req)
  53475. +{
  53476. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53477. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  53478. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53479. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53480. + dma_addr_t buff_addr = req->dma;
  53481. + int i;
  53482. + uint16_t *txsize;
  53483. +
  53484. + txsize = concatval->wTxBytes;
  53485. +
  53486. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  53487. + desc->buf = buff_addr;
  53488. + desc->status.b.bs = BS_HOST_BUSY;
  53489. + desc->status.b.l = 0;
  53490. + desc->status.b.ioc = 0;
  53491. + desc->status.b.sp = 0;
  53492. + desc->status.b.bytes = *txsize;
  53493. + desc->status.b.bs = BS_HOST_READY;
  53494. +
  53495. + txsize++;
  53496. + /* Set the next address of the buffer */
  53497. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  53498. + desc_last = desc;
  53499. + desc++;
  53500. + }
  53501. +
  53502. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53503. + desc_last->status.b.l = 1;
  53504. + desc_last->status.b.ioc = 1;
  53505. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53506. + cfiep->dma_desc_last = desc_last;
  53507. + cfiep->desc_count = concatval->hdr.bDescCount;
  53508. +}
  53509. +
  53510. +/**
  53511. + * This function builds the DMA descriptors for the Circular buffer mode
  53512. + */
  53513. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53514. + dwc_otg_pcd_request_t * req)
  53515. +{
  53516. + /* @todo: MAS - add implementation when this feature needs to be tested */
  53517. +}
  53518. +
  53519. +/**
  53520. + * This function builds the DMA descriptors for the Alignment buffer mode
  53521. + */
  53522. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53523. + dwc_otg_pcd_request_t * req)
  53524. +{
  53525. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53526. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  53527. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53528. + dma_addr_t buff_addr = req->dma;
  53529. +
  53530. + desc->status.b.bs = BS_HOST_BUSY;
  53531. + desc->status.b.l = 1;
  53532. + desc->status.b.ioc = 1;
  53533. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  53534. + desc->status.b.bytes = req->length;
  53535. + /* Adjust the buffer alignment */
  53536. + desc->buf = (buff_addr + alignval->bAlign);
  53537. + desc->status.b.bs = BS_HOST_READY;
  53538. + cfiep->dma_desc_last = desc;
  53539. + cfiep->desc_count = 1;
  53540. +}
  53541. +
  53542. +/**
  53543. + * This function builds the DMA descriptors chain for different modes of the
  53544. + * buffer setup of an endpoint.
  53545. + */
  53546. +static void cfi_build_descriptors(struct cfiobject *cfi,
  53547. + struct dwc_otg_pcd *pcd,
  53548. + struct dwc_otg_pcd_ep *ep,
  53549. + dwc_otg_pcd_request_t * req)
  53550. +{
  53551. + cfi_ep_t *cfiep;
  53552. +
  53553. + /* Get the cfiep by the dwc_otg_pcd_ep */
  53554. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53555. + if (NULL == cfiep) {
  53556. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  53557. + __func__);
  53558. + return;
  53559. + }
  53560. +
  53561. + cfiep->xfer_len = req->length;
  53562. +
  53563. + /* Iterate through all the DMA descriptors */
  53564. + switch (cfiep->ep->dwc_ep.buff_mode) {
  53565. + case BM_SG:
  53566. + cfi_build_sg_descs(cfi, cfiep, req);
  53567. + break;
  53568. +
  53569. + case BM_CONCAT:
  53570. + cfi_build_concat_descs(cfi, cfiep, req);
  53571. + break;
  53572. +
  53573. + case BM_CIRCULAR:
  53574. + cfi_build_circ_descs(cfi, cfiep, req);
  53575. + break;
  53576. +
  53577. + case BM_ALIGN:
  53578. + cfi_build_align_descs(cfi, cfiep, req);
  53579. + break;
  53580. +
  53581. + default:
  53582. + break;
  53583. + }
  53584. +}
  53585. +
  53586. +/**
  53587. + * Allocate DMA buffer for different Buffer modes.
  53588. + */
  53589. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53590. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  53591. + unsigned size, gfp_t flags)
  53592. +{
  53593. + return DWC_DMA_ALLOC(size, dma);
  53594. +}
  53595. +
  53596. +/**
  53597. + * This function initializes the CFI object.
  53598. + */
  53599. +int init_cfi(cfiobject_t * cfiobj)
  53600. +{
  53601. + CFI_INFO("%s\n", __func__);
  53602. +
  53603. + /* Allocate a buffer for IN XFERs */
  53604. + cfiobj->buf_in.buf =
  53605. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  53606. + if (NULL == cfiobj->buf_in.buf) {
  53607. + CFI_INFO("Unable to allocate buffer for INs\n");
  53608. + return -DWC_E_NO_MEMORY;
  53609. + }
  53610. +
  53611. + /* Allocate a buffer for OUT XFERs */
  53612. + cfiobj->buf_out.buf =
  53613. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  53614. + if (NULL == cfiobj->buf_out.buf) {
  53615. + CFI_INFO("Unable to allocate buffer for OUT\n");
  53616. + return -DWC_E_NO_MEMORY;
  53617. + }
  53618. +
  53619. + /* Initialize the callback function pointers */
  53620. + cfiobj->ops.release = cfi_release;
  53621. + cfiobj->ops.ep_enable = cfi_ep_enable;
  53622. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  53623. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  53624. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  53625. +
  53626. + /* Initialize the list of active endpoints in the CFI object */
  53627. + DWC_LIST_INIT(&cfiobj->active_eps);
  53628. +
  53629. + return 0;
  53630. +}
  53631. +
  53632. +/**
  53633. + * This function reads the required feature's current value into the buffer
  53634. + *
  53635. + * @retval: Returns negative as error, or the data length of the feature
  53636. + */
  53637. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53638. + struct dwc_otg_pcd *pcd,
  53639. + struct cfi_usb_ctrlrequest *ctrl_req)
  53640. +{
  53641. + int retval = -DWC_E_NOT_SUPPORTED;
  53642. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53643. + uint16_t dfifo, rxfifo, txfifo;
  53644. +
  53645. + switch (ctrl_req->wIndex) {
  53646. + /* Whether the DDMA is enabled or not */
  53647. + case FT_ID_DMA_MODE:
  53648. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  53649. + retval = 1;
  53650. + break;
  53651. +
  53652. + case FT_ID_DMA_BUFFER_SETUP:
  53653. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  53654. + break;
  53655. +
  53656. + case FT_ID_DMA_BUFF_ALIGN:
  53657. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  53658. + break;
  53659. +
  53660. + case FT_ID_DMA_CONCAT_SETUP:
  53661. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  53662. + break;
  53663. +
  53664. + case FT_ID_DMA_CIRCULAR:
  53665. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  53666. + break;
  53667. +
  53668. + case FT_ID_THRESHOLD_SETUP:
  53669. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  53670. + break;
  53671. +
  53672. + case FT_ID_DFIFO_DEPTH:
  53673. + dfifo = get_dfifo_size(coreif);
  53674. + *((uint16_t *) buf) = dfifo;
  53675. + retval = sizeof(uint16_t);
  53676. + break;
  53677. +
  53678. + case FT_ID_TX_FIFO_DEPTH:
  53679. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  53680. + if (retval >= 0) {
  53681. + txfifo = retval;
  53682. + *((uint16_t *) buf) = txfifo;
  53683. + retval = sizeof(uint16_t);
  53684. + }
  53685. + break;
  53686. +
  53687. + case FT_ID_RX_FIFO_DEPTH:
  53688. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  53689. + if (retval >= 0) {
  53690. + rxfifo = retval;
  53691. + *((uint16_t *) buf) = rxfifo;
  53692. + retval = sizeof(uint16_t);
  53693. + }
  53694. + break;
  53695. + }
  53696. +
  53697. + return retval;
  53698. +}
  53699. +
  53700. +/**
  53701. + * This function resets the SG for the specified EP to its default value
  53702. + */
  53703. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  53704. +{
  53705. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53706. + return 0;
  53707. +}
  53708. +
  53709. +/**
  53710. + * This function resets the Alignment for the specified EP to its default value
  53711. + */
  53712. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  53713. +{
  53714. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53715. + return 0;
  53716. +}
  53717. +
  53718. +/**
  53719. + * This function resets the Concatenation for the specified EP to its default value
  53720. + * This function will also set the value of the wTxBytes field to NULL after
  53721. + * freeing the memory previously allocated for this field.
  53722. + */
  53723. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  53724. +{
  53725. + /* First we need to free the wTxBytes field */
  53726. + if (cfiep->bm_concat->wTxBytes) {
  53727. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53728. + cfiep->bm_concat->wTxBytes = NULL;
  53729. + }
  53730. +
  53731. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53732. + return 0;
  53733. +}
  53734. +
  53735. +/**
  53736. + * This function resets all the buffer setups of the specified endpoint
  53737. + */
  53738. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  53739. +{
  53740. + cfi_reset_sg_val(cfiep);
  53741. + cfi_reset_align_val(cfiep);
  53742. + cfi_reset_concat_val(cfiep);
  53743. + return 0;
  53744. +}
  53745. +
  53746. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  53747. + uint8_t rx_rst, uint8_t tx_rst)
  53748. +{
  53749. + int retval = -DWC_E_INVALID;
  53750. + uint16_t tx_siz[15];
  53751. + uint16_t rx_siz = 0;
  53752. + dwc_otg_pcd_ep_t *ep = NULL;
  53753. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  53754. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53755. +
  53756. + if (rx_rst) {
  53757. + rx_siz = params->dev_rx_fifo_size;
  53758. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  53759. + }
  53760. +
  53761. + if (tx_rst) {
  53762. + if (ep_addr == 0) {
  53763. + int i;
  53764. +
  53765. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53766. + tx_siz[i] =
  53767. + core_if->core_params->dev_tx_fifo_size[i];
  53768. + core_if->core_params->dev_tx_fifo_size[i] =
  53769. + core_if->init_txfsiz[i];
  53770. + }
  53771. + } else {
  53772. +
  53773. + ep = get_ep_by_addr(pcd, ep_addr);
  53774. +
  53775. + if (NULL == ep) {
  53776. + CFI_INFO
  53777. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  53778. + __func__, ep_addr);
  53779. + return -DWC_E_INVALID;
  53780. + }
  53781. +
  53782. + tx_siz[0] =
  53783. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  53784. + 1];
  53785. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  53786. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  53787. + dwc_ep.tx_fifo_num -
  53788. + 1];
  53789. + }
  53790. + }
  53791. +
  53792. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53793. + retval = 0;
  53794. + } else {
  53795. + CFI_INFO
  53796. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  53797. + __func__);
  53798. + if (rx_rst) {
  53799. + params->dev_rx_fifo_size = rx_siz;
  53800. + }
  53801. +
  53802. + if (tx_rst) {
  53803. + if (ep_addr == 0) {
  53804. + int i;
  53805. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  53806. + i++) {
  53807. + core_if->
  53808. + core_params->dev_tx_fifo_size[i] =
  53809. + tx_siz[i];
  53810. + }
  53811. + } else {
  53812. + params->dev_tx_fifo_size[ep->
  53813. + dwc_ep.tx_fifo_num -
  53814. + 1] = tx_siz[0];
  53815. + }
  53816. + }
  53817. + retval = -DWC_E_INVALID;
  53818. + }
  53819. + return retval;
  53820. +}
  53821. +
  53822. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  53823. +{
  53824. + int retval = 0;
  53825. + cfi_ep_t *cfiep;
  53826. + cfiobject_t *cfi = pcd->cfi;
  53827. + dwc_list_link_t *tmp;
  53828. +
  53829. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  53830. + if (retval < 0) {
  53831. + return retval;
  53832. + }
  53833. +
  53834. + /* If the EP address is known then reset the features for only that EP */
  53835. + if (addr) {
  53836. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53837. + if (NULL == cfiep) {
  53838. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53839. + __func__, addr);
  53840. + return -DWC_E_INVALID;
  53841. + }
  53842. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53843. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53844. + }
  53845. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53846. + else {
  53847. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53848. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53849. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53850. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53851. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53852. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53853. + if (retval < 0) {
  53854. + CFI_INFO
  53855. + ("%s: Error resetting the feature Reset All\n",
  53856. + __func__);
  53857. + return retval;
  53858. + }
  53859. + }
  53860. + }
  53861. + return retval;
  53862. +}
  53863. +
  53864. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  53865. + uint8_t addr)
  53866. +{
  53867. + int retval = 0;
  53868. + cfi_ep_t *cfiep;
  53869. + cfiobject_t *cfi = pcd->cfi;
  53870. + dwc_list_link_t *tmp;
  53871. +
  53872. + /* If the EP address is known then reset the features for only that EP */
  53873. + if (addr) {
  53874. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53875. + if (NULL == cfiep) {
  53876. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53877. + __func__, addr);
  53878. + return -DWC_E_INVALID;
  53879. + }
  53880. + retval = cfi_reset_sg_val(cfiep);
  53881. + }
  53882. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53883. + else {
  53884. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53885. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53886. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53887. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53888. + retval = cfi_reset_sg_val(cfiep);
  53889. + if (retval < 0) {
  53890. + CFI_INFO
  53891. + ("%s: Error resetting the feature Buffer Setup\n",
  53892. + __func__);
  53893. + return retval;
  53894. + }
  53895. + }
  53896. + }
  53897. + return retval;
  53898. +}
  53899. +
  53900. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53901. +{
  53902. + int retval = 0;
  53903. + cfi_ep_t *cfiep;
  53904. + cfiobject_t *cfi = pcd->cfi;
  53905. + dwc_list_link_t *tmp;
  53906. +
  53907. + /* If the EP address is known then reset the features for only that EP */
  53908. + if (addr) {
  53909. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53910. + if (NULL == cfiep) {
  53911. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53912. + __func__, addr);
  53913. + return -DWC_E_INVALID;
  53914. + }
  53915. + retval = cfi_reset_concat_val(cfiep);
  53916. + }
  53917. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53918. + else {
  53919. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53920. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53921. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53922. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53923. + retval = cfi_reset_concat_val(cfiep);
  53924. + if (retval < 0) {
  53925. + CFI_INFO
  53926. + ("%s: Error resetting the feature Concatenation Value\n",
  53927. + __func__);
  53928. + return retval;
  53929. + }
  53930. + }
  53931. + }
  53932. + return retval;
  53933. +}
  53934. +
  53935. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53936. +{
  53937. + int retval = 0;
  53938. + cfi_ep_t *cfiep;
  53939. + cfiobject_t *cfi = pcd->cfi;
  53940. + dwc_list_link_t *tmp;
  53941. +
  53942. + /* If the EP address is known then reset the features for only that EP */
  53943. + if (addr) {
  53944. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53945. + if (NULL == cfiep) {
  53946. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53947. + __func__, addr);
  53948. + return -DWC_E_INVALID;
  53949. + }
  53950. + retval = cfi_reset_align_val(cfiep);
  53951. + }
  53952. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53953. + else {
  53954. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53955. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53956. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53957. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53958. + retval = cfi_reset_align_val(cfiep);
  53959. + if (retval < 0) {
  53960. + CFI_INFO
  53961. + ("%s: Error resetting the feature Aliignment Value\n",
  53962. + __func__);
  53963. + return retval;
  53964. + }
  53965. + }
  53966. + }
  53967. + return retval;
  53968. +
  53969. +}
  53970. +
  53971. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53972. + struct cfi_usb_ctrlrequest *req)
  53973. +{
  53974. + int retval = 0;
  53975. +
  53976. + switch (req->wIndex) {
  53977. + case 0:
  53978. + /* Reset all features */
  53979. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  53980. + break;
  53981. +
  53982. + case FT_ID_DMA_BUFFER_SETUP:
  53983. + /* Reset the SG buffer setup */
  53984. + retval =
  53985. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  53986. + break;
  53987. +
  53988. + case FT_ID_DMA_CONCAT_SETUP:
  53989. + /* Reset the Concatenation buffer setup */
  53990. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  53991. + break;
  53992. +
  53993. + case FT_ID_DMA_BUFF_ALIGN:
  53994. + /* Reset the Alignment buffer setup */
  53995. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  53996. + break;
  53997. +
  53998. + case FT_ID_TX_FIFO_DEPTH:
  53999. + retval =
  54000. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  54001. + pcd->cfi->need_gadget_att = 0;
  54002. + break;
  54003. +
  54004. + case FT_ID_RX_FIFO_DEPTH:
  54005. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  54006. + pcd->cfi->need_gadget_att = 0;
  54007. + break;
  54008. + default:
  54009. + break;
  54010. + }
  54011. + return retval;
  54012. +}
  54013. +
  54014. +/**
  54015. + * This function sets a new value for the SG buffer setup.
  54016. + */
  54017. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54018. +{
  54019. + uint8_t inaddr, outaddr;
  54020. + cfi_ep_t *epin, *epout;
  54021. + ddma_sg_buffer_setup_t *psgval;
  54022. + uint32_t desccount, size;
  54023. +
  54024. + CFI_INFO("%s\n", __func__);
  54025. +
  54026. + psgval = (ddma_sg_buffer_setup_t *) buf;
  54027. + desccount = (uint32_t) psgval->bCount;
  54028. + size = (uint32_t) psgval->wSize;
  54029. +
  54030. + /* Check the DMA descriptor count */
  54031. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  54032. + CFI_INFO
  54033. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  54034. + __func__, MAX_DMA_DESCS_PER_EP);
  54035. + return -DWC_E_INVALID;
  54036. + }
  54037. +
  54038. + /* Check the DMA descriptor count */
  54039. +
  54040. + if (size == 0) {
  54041. +
  54042. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  54043. + __func__);
  54044. +
  54045. + return -DWC_E_INVALID;
  54046. +
  54047. + }
  54048. +
  54049. + inaddr = psgval->bInEndpointAddress;
  54050. + outaddr = psgval->bOutEndpointAddress;
  54051. +
  54052. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  54053. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  54054. +
  54055. + if (NULL == epin || NULL == epout) {
  54056. + CFI_INFO
  54057. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  54058. + __func__, inaddr, outaddr);
  54059. + return -DWC_E_INVALID;
  54060. + }
  54061. +
  54062. + epin->ep->dwc_ep.buff_mode = BM_SG;
  54063. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54064. +
  54065. + epout->ep->dwc_ep.buff_mode = BM_SG;
  54066. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54067. +
  54068. + return 0;
  54069. +}
  54070. +
  54071. +/**
  54072. + * This function sets a new value for the buffer Alignment setup.
  54073. + */
  54074. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54075. +{
  54076. + cfi_ep_t *ep;
  54077. + uint8_t addr;
  54078. + ddma_align_buffer_setup_t *palignval;
  54079. +
  54080. + palignval = (ddma_align_buffer_setup_t *) buf;
  54081. + addr = palignval->bEndpointAddress;
  54082. +
  54083. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54084. +
  54085. + if (NULL == ep) {
  54086. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54087. + __func__, addr);
  54088. + return -DWC_E_INVALID;
  54089. + }
  54090. +
  54091. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  54092. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  54093. +
  54094. + return 0;
  54095. +}
  54096. +
  54097. +/**
  54098. + * This function sets a new value for the Concatenation buffer setup.
  54099. + */
  54100. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54101. +{
  54102. + uint8_t addr;
  54103. + cfi_ep_t *ep;
  54104. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  54105. + uint16_t *pVals;
  54106. + uint32_t desccount;
  54107. + int i;
  54108. + uint16_t mps;
  54109. +
  54110. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  54111. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  54112. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  54113. +
  54114. + /* Check the DMA descriptor count */
  54115. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  54116. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  54117. + __func__, MAX_DMA_DESCS_PER_EP);
  54118. + return -DWC_E_INVALID;
  54119. + }
  54120. +
  54121. + addr = pConcatValHdr->bEndpointAddress;
  54122. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54123. + if (NULL == ep) {
  54124. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54125. + __func__, addr);
  54126. + return -DWC_E_INVALID;
  54127. + }
  54128. +
  54129. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  54130. +
  54131. +#if 0
  54132. + for (i = 0; i < desccount; i++) {
  54133. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  54134. + }
  54135. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  54136. +#endif
  54137. +
  54138. + /* Check the wTxSizes to be less than or equal to the mps */
  54139. + for (i = 0; i < desccount; i++) {
  54140. + if (pVals[i] > mps) {
  54141. + CFI_INFO
  54142. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  54143. + __func__, i, pVals[i]);
  54144. + return -DWC_E_INVALID;
  54145. + }
  54146. + }
  54147. +
  54148. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  54149. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  54150. +
  54151. + /* Free the previously allocated storage for the wTxBytes */
  54152. + if (ep->bm_concat->wTxBytes) {
  54153. + DWC_FREE(ep->bm_concat->wTxBytes);
  54154. + }
  54155. +
  54156. + /* Allocate a new storage for the wTxBytes field */
  54157. + ep->bm_concat->wTxBytes =
  54158. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54159. + if (NULL == ep->bm_concat->wTxBytes) {
  54160. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  54161. + return -DWC_E_NO_MEMORY;
  54162. + }
  54163. +
  54164. + /* Copy the new values into the wTxBytes filed */
  54165. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  54166. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54167. +
  54168. + return 0;
  54169. +}
  54170. +
  54171. +/**
  54172. + * This function calculates the total of all FIFO sizes
  54173. + *
  54174. + * @param core_if Programming view of DWC_otg controller
  54175. + *
  54176. + * @return The total of data FIFO sizes.
  54177. + *
  54178. + */
  54179. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  54180. +{
  54181. + dwc_otg_core_params_t *params = core_if->core_params;
  54182. + uint16_t dfifo_total = 0;
  54183. + int i;
  54184. +
  54185. + /* The shared RxFIFO size */
  54186. + dfifo_total =
  54187. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54188. +
  54189. + /* Add up each TxFIFO size to the total */
  54190. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54191. + dfifo_total += params->dev_tx_fifo_size[i];
  54192. + }
  54193. +
  54194. + return dfifo_total;
  54195. +}
  54196. +
  54197. +/**
  54198. + * This function returns Rx FIFO size
  54199. + *
  54200. + * @param core_if Programming view of DWC_otg controller
  54201. + *
  54202. + * @return The total of data FIFO sizes.
  54203. + *
  54204. + */
  54205. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  54206. +{
  54207. + switch (wValue >> 8) {
  54208. + case 0:
  54209. + return (core_if->pwron_rxfsiz <
  54210. + 32768) ? core_if->pwron_rxfsiz : 32768;
  54211. + break;
  54212. + case 1:
  54213. + return core_if->core_params->dev_rx_fifo_size;
  54214. + break;
  54215. + default:
  54216. + return -DWC_E_INVALID;
  54217. + break;
  54218. + }
  54219. +}
  54220. +
  54221. +/**
  54222. + * This function returns Tx FIFO size for IN EP
  54223. + *
  54224. + * @param core_if Programming view of DWC_otg controller
  54225. + *
  54226. + * @return The total of data FIFO sizes.
  54227. + *
  54228. + */
  54229. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  54230. +{
  54231. + dwc_otg_pcd_ep_t *ep;
  54232. +
  54233. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  54234. +
  54235. + if (NULL == ep) {
  54236. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54237. + __func__, wValue & 0xff);
  54238. + return -DWC_E_INVALID;
  54239. + }
  54240. +
  54241. + if (!ep->dwc_ep.is_in) {
  54242. + CFI_INFO
  54243. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  54244. + __func__, wValue & 0xff);
  54245. + return -DWC_E_INVALID;
  54246. + }
  54247. +
  54248. + switch (wValue >> 8) {
  54249. + case 0:
  54250. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  54251. + [ep->dwc_ep.tx_fifo_num - 1] <
  54252. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  54253. + dwc_ep.tx_fifo_num
  54254. + - 1] : 32768;
  54255. + break;
  54256. + case 1:
  54257. + return GET_CORE_IF(pcd)->core_params->
  54258. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  54259. + break;
  54260. + default:
  54261. + return -DWC_E_INVALID;
  54262. + break;
  54263. + }
  54264. +}
  54265. +
  54266. +/**
  54267. + * This function checks if the submitted combination of
  54268. + * device mode FIFO sizes is possible or not.
  54269. + *
  54270. + * @param core_if Programming view of DWC_otg controller
  54271. + *
  54272. + * @return 1 if possible, 0 otherwise.
  54273. + *
  54274. + */
  54275. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  54276. +{
  54277. + uint16_t dfifo_actual = 0;
  54278. + dwc_otg_core_params_t *params = core_if->core_params;
  54279. + uint16_t start_addr = 0;
  54280. + int i;
  54281. +
  54282. + dfifo_actual =
  54283. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54284. +
  54285. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54286. + dfifo_actual += params->dev_tx_fifo_size[i];
  54287. + }
  54288. +
  54289. + if (dfifo_actual > core_if->total_fifo_size) {
  54290. + return 0;
  54291. + }
  54292. +
  54293. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  54294. + return 0;
  54295. +
  54296. + if (params->dev_nperio_tx_fifo_size > 32768
  54297. + || params->dev_nperio_tx_fifo_size < 16)
  54298. + return 0;
  54299. +
  54300. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54301. +
  54302. + if (params->dev_tx_fifo_size[i] > 768
  54303. + || params->dev_tx_fifo_size[i] < 4)
  54304. + return 0;
  54305. + }
  54306. +
  54307. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  54308. + return 0;
  54309. + start_addr = params->dev_rx_fifo_size;
  54310. +
  54311. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  54312. + return 0;
  54313. + start_addr += params->dev_nperio_tx_fifo_size;
  54314. +
  54315. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54316. +
  54317. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  54318. + return 0;
  54319. + start_addr += params->dev_tx_fifo_size[i];
  54320. + }
  54321. +
  54322. + return 1;
  54323. +}
  54324. +
  54325. +/**
  54326. + * This function resizes Device mode FIFOs
  54327. + *
  54328. + * @param core_if Programming view of DWC_otg controller
  54329. + *
  54330. + * @return 1 if successful, 0 otherwise
  54331. + *
  54332. + */
  54333. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  54334. +{
  54335. + int i = 0;
  54336. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  54337. + dwc_otg_core_params_t *params = core_if->core_params;
  54338. + uint32_t rx_fifo_size;
  54339. + fifosize_data_t nptxfifosize;
  54340. + fifosize_data_t txfifosize[15];
  54341. +
  54342. + uint32_t rx_fsz_bak;
  54343. + uint32_t nptxfsz_bak;
  54344. + uint32_t txfsz_bak[15];
  54345. +
  54346. + uint16_t start_address;
  54347. + uint8_t retval = 1;
  54348. +
  54349. + if (!check_fifo_sizes(core_if)) {
  54350. + return 0;
  54351. + }
  54352. +
  54353. + /* Configure data FIFO sizes */
  54354. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  54355. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  54356. + rx_fifo_size = params->dev_rx_fifo_size;
  54357. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  54358. +
  54359. + /*
  54360. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  54361. + * Indexes of the FIFO size module parameters in the
  54362. + * dev_tx_fifo_size array and the FIFO size registers in
  54363. + * the dtxfsiz array run from 0 to 14.
  54364. + */
  54365. +
  54366. + /* Non-periodic Tx FIFO */
  54367. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  54368. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  54369. + start_address = params->dev_rx_fifo_size;
  54370. + nptxfifosize.b.startaddr = start_address;
  54371. +
  54372. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  54373. +
  54374. + start_address += nptxfifosize.b.depth;
  54375. +
  54376. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54377. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  54378. +
  54379. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  54380. + txfifosize[i].b.startaddr = start_address;
  54381. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54382. + txfifosize[i].d32);
  54383. +
  54384. + start_address += txfifosize[i].b.depth;
  54385. + }
  54386. +
  54387. + /** Check if register values are set correctly */
  54388. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  54389. + retval = 0;
  54390. + }
  54391. +
  54392. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  54393. + retval = 0;
  54394. + }
  54395. +
  54396. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54397. + if (txfifosize[i].d32 !=
  54398. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  54399. + retval = 0;
  54400. + }
  54401. + }
  54402. +
  54403. + /** If register values are not set correctly, reset old values */
  54404. + if (retval == 0) {
  54405. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  54406. +
  54407. + /* Non-periodic Tx FIFO */
  54408. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  54409. +
  54410. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54411. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54412. + txfsz_bak[i]);
  54413. + }
  54414. + }
  54415. + } else {
  54416. + return 0;
  54417. + }
  54418. +
  54419. + /* Flush the FIFOs */
  54420. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  54421. + dwc_otg_flush_rx_fifo(core_if);
  54422. +
  54423. + return retval;
  54424. +}
  54425. +
  54426. +/**
  54427. + * This function sets a new value for the buffer Alignment setup.
  54428. + */
  54429. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54430. +{
  54431. + int retval;
  54432. + uint32_t fsiz;
  54433. + uint16_t size;
  54434. + uint16_t ep_addr;
  54435. + dwc_otg_pcd_ep_t *ep;
  54436. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54437. + tx_fifo_size_setup_t *ptxfifoval;
  54438. +
  54439. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  54440. + ep_addr = ptxfifoval->bEndpointAddress;
  54441. + size = ptxfifoval->wDepth;
  54442. +
  54443. + ep = get_ep_by_addr(pcd, ep_addr);
  54444. +
  54445. + CFI_INFO
  54446. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  54447. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  54448. +
  54449. + if (NULL == ep) {
  54450. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54451. + __func__, ep_addr);
  54452. + return -DWC_E_INVALID;
  54453. + }
  54454. +
  54455. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  54456. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  54457. +
  54458. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54459. + retval = 0;
  54460. + } else {
  54461. + CFI_INFO
  54462. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  54463. + __func__, ep_addr);
  54464. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  54465. + retval = -DWC_E_INVALID;
  54466. + }
  54467. +
  54468. + return retval;
  54469. +}
  54470. +
  54471. +/**
  54472. + * This function sets a new value for the buffer Alignment setup.
  54473. + */
  54474. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54475. +{
  54476. + int retval;
  54477. + uint32_t fsiz;
  54478. + uint16_t size;
  54479. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54480. + rx_fifo_size_setup_t *prxfifoval;
  54481. +
  54482. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  54483. + size = prxfifoval->wDepth;
  54484. +
  54485. + fsiz = params->dev_rx_fifo_size;
  54486. + params->dev_rx_fifo_size = size;
  54487. +
  54488. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54489. + retval = 0;
  54490. + } else {
  54491. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  54492. + __func__);
  54493. + params->dev_rx_fifo_size = fsiz;
  54494. + retval = -DWC_E_INVALID;
  54495. + }
  54496. +
  54497. + return retval;
  54498. +}
  54499. +
  54500. +/**
  54501. + * This function reads the SG of an EP's buffer setup into the buffer buf
  54502. + */
  54503. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54504. + struct cfi_usb_ctrlrequest *req)
  54505. +{
  54506. + int retval = -DWC_E_INVALID;
  54507. + uint8_t addr;
  54508. + cfi_ep_t *ep;
  54509. +
  54510. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54511. + addr = req->wValue & 0xFF;
  54512. + if (addr == 0) /* The address should be non-zero */
  54513. + return retval;
  54514. +
  54515. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54516. + if (NULL == ep) {
  54517. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54518. + __func__, addr);
  54519. + return retval;
  54520. + }
  54521. +
  54522. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  54523. + retval = BS_SG_VAL_DESC_LEN;
  54524. + return retval;
  54525. +}
  54526. +
  54527. +/**
  54528. + * This function reads the Concatenation value of an EP's buffer mode into
  54529. + * the buffer buf
  54530. + */
  54531. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54532. + struct cfi_usb_ctrlrequest *req)
  54533. +{
  54534. + int retval = -DWC_E_INVALID;
  54535. + uint8_t addr;
  54536. + cfi_ep_t *ep;
  54537. + uint8_t desc_count;
  54538. +
  54539. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54540. + addr = req->wValue & 0xFF;
  54541. + if (addr == 0) /* The address should be non-zero */
  54542. + return retval;
  54543. +
  54544. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54545. + if (NULL == ep) {
  54546. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54547. + __func__, addr);
  54548. + return retval;
  54549. + }
  54550. +
  54551. + /* Copy the header to the buffer */
  54552. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  54553. + /* Advance the buffer pointer by the header size */
  54554. + buf += BS_CONCAT_VAL_HDR_LEN;
  54555. +
  54556. + desc_count = ep->bm_concat->hdr.bDescCount;
  54557. + /* Copy alll the wTxBytes to the buffer */
  54558. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  54559. +
  54560. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  54561. + return retval;
  54562. +}
  54563. +
  54564. +/**
  54565. + * This function reads the buffer Alignment value of an EP's buffer mode into
  54566. + * the buffer buf
  54567. + *
  54568. + * @return The total number of bytes copied to the buffer or negative error code.
  54569. + */
  54570. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54571. + struct cfi_usb_ctrlrequest *req)
  54572. +{
  54573. + int retval = -DWC_E_INVALID;
  54574. + uint8_t addr;
  54575. + cfi_ep_t *ep;
  54576. +
  54577. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54578. + addr = req->wValue & 0xFF;
  54579. + if (addr == 0) /* The address should be non-zero */
  54580. + return retval;
  54581. +
  54582. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54583. + if (NULL == ep) {
  54584. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54585. + __func__, addr);
  54586. + return retval;
  54587. + }
  54588. +
  54589. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  54590. + retval = BS_ALIGN_VAL_HDR_LEN;
  54591. +
  54592. + return retval;
  54593. +}
  54594. +
  54595. +/**
  54596. + * This function sets a new value for the specified feature
  54597. + *
  54598. + * @param pcd A pointer to the PCD object
  54599. + *
  54600. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  54601. + */
  54602. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  54603. +{
  54604. + int retval = -DWC_E_NOT_SUPPORTED;
  54605. + uint16_t wIndex, wValue;
  54606. + uint8_t bRequest;
  54607. + struct dwc_otg_core_if *coreif;
  54608. + cfiobject_t *cfi = pcd->cfi;
  54609. + struct cfi_usb_ctrlrequest *ctrl_req;
  54610. + uint8_t *buf;
  54611. + ctrl_req = &cfi->ctrl_req;
  54612. +
  54613. + buf = pcd->cfi->ctrl_req.data;
  54614. +
  54615. + coreif = GET_CORE_IF(pcd);
  54616. + bRequest = ctrl_req->bRequest;
  54617. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54618. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54619. +
  54620. + /* See which feature is to be modified */
  54621. + switch (wIndex) {
  54622. + case FT_ID_DMA_BUFFER_SETUP:
  54623. + /* Modify the feature */
  54624. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  54625. + return retval;
  54626. +
  54627. + /* And send this request to the gadget */
  54628. + cfi->need_gadget_att = 1;
  54629. + break;
  54630. +
  54631. + case FT_ID_DMA_BUFF_ALIGN:
  54632. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  54633. + return retval;
  54634. + cfi->need_gadget_att = 1;
  54635. + break;
  54636. +
  54637. + case FT_ID_DMA_CONCAT_SETUP:
  54638. + /* Modify the feature */
  54639. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  54640. + return retval;
  54641. + cfi->need_gadget_att = 1;
  54642. + break;
  54643. +
  54644. + case FT_ID_DMA_CIRCULAR:
  54645. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  54646. + break;
  54647. +
  54648. + case FT_ID_THRESHOLD_SETUP:
  54649. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  54650. + break;
  54651. +
  54652. + case FT_ID_DFIFO_DEPTH:
  54653. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  54654. + break;
  54655. +
  54656. + case FT_ID_TX_FIFO_DEPTH:
  54657. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  54658. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  54659. + return retval;
  54660. + cfi->need_gadget_att = 0;
  54661. + break;
  54662. +
  54663. + case FT_ID_RX_FIFO_DEPTH:
  54664. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  54665. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  54666. + return retval;
  54667. + cfi->need_gadget_att = 0;
  54668. + break;
  54669. + }
  54670. +
  54671. + return retval;
  54672. +}
  54673. +
  54674. +#endif //DWC_UTE_CFI
  54675. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  54676. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  54677. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-02-07 19:57:30.000000000 +0100
  54678. @@ -0,0 +1,320 @@
  54679. +/* ==========================================================================
  54680. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54681. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54682. + * otherwise expressly agreed to in writing between Synopsys and you.
  54683. + *
  54684. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54685. + * any End User Software License Agreement or Agreement for Licensed Product
  54686. + * with Synopsys or any supplement thereto. You are permitted to use and
  54687. + * redistribute this Software in source and binary forms, with or without
  54688. + * modification, provided that redistributions of source code must retain this
  54689. + * notice. You may not view, use, disclose, copy or distribute this file or
  54690. + * any information contained herein except pursuant to this license grant from
  54691. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54692. + * below, then you are not authorized to use the Software.
  54693. + *
  54694. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54695. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54696. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54697. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54698. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54699. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54700. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54701. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54702. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54703. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54704. + * DAMAGE.
  54705. + * ========================================================================== */
  54706. +
  54707. +#if !defined(__DWC_OTG_CFI_H__)
  54708. +#define __DWC_OTG_CFI_H__
  54709. +
  54710. +#include "dwc_otg_pcd.h"
  54711. +#include "dwc_cfi_common.h"
  54712. +
  54713. +/**
  54714. + * @file
  54715. + * This file contains the CFI related OTG PCD specific common constants,
  54716. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  54717. + * optional interface for internal testing purposes that a DUT may implement to
  54718. + * support testing of configurable features.
  54719. + *
  54720. + */
  54721. +
  54722. +struct dwc_otg_pcd;
  54723. +struct dwc_otg_pcd_ep;
  54724. +
  54725. +/** OTG CFI Features (properties) ID constants */
  54726. +/** This is a request for all Core Features */
  54727. +#define FT_ID_DMA_MODE 0x0001
  54728. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  54729. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  54730. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  54731. +#define FT_ID_DMA_CIRCULAR 0x0005
  54732. +#define FT_ID_THRESHOLD_SETUP 0x0006
  54733. +#define FT_ID_DFIFO_DEPTH 0x0007
  54734. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  54735. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  54736. +
  54737. +/**********************************************************/
  54738. +#define CFI_INFO_DEF
  54739. +
  54740. +#ifdef CFI_INFO_DEF
  54741. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  54742. +#else
  54743. +#define CFI_INFO(fmt...)
  54744. +#endif
  54745. +
  54746. +#define min(x,y) ({ \
  54747. + x < y ? x : y; })
  54748. +
  54749. +#define max(x,y) ({ \
  54750. + x > y ? x : y; })
  54751. +
  54752. +/**
  54753. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  54754. + * also used for setting up a buffer for Circular DDMA.
  54755. + */
  54756. +struct _ddma_sg_buffer_setup {
  54757. +#define BS_SG_VAL_DESC_LEN 6
  54758. + /* The OUT EP address */
  54759. + uint8_t bOutEndpointAddress;
  54760. + /* The IN EP address */
  54761. + uint8_t bInEndpointAddress;
  54762. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  54763. + uint8_t bOffset;
  54764. + /* The number of transfer segments (a DMA descriptors per each segment) */
  54765. + uint8_t bCount;
  54766. + /* Size (in byte) of each transfer segment */
  54767. + uint16_t wSize;
  54768. +} __attribute__ ((packed));
  54769. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  54770. +
  54771. +/** Descriptor DMA Concatenation Buffer setup structure */
  54772. +struct _ddma_concat_buffer_setup_hdr {
  54773. +#define BS_CONCAT_VAL_HDR_LEN 4
  54774. + /* The endpoint for which the buffer is to be set up */
  54775. + uint8_t bEndpointAddress;
  54776. + /* The count of descriptors to be used */
  54777. + uint8_t bDescCount;
  54778. + /* The total size of the transfer */
  54779. + uint16_t wSize;
  54780. +} __attribute__ ((packed));
  54781. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  54782. +
  54783. +/** Descriptor DMA Concatenation Buffer setup structure */
  54784. +struct _ddma_concat_buffer_setup {
  54785. + /* The SG header */
  54786. + ddma_concat_buffer_setup_hdr_t hdr;
  54787. +
  54788. + /* The XFER sizes pointer (allocated dynamically) */
  54789. + uint16_t *wTxBytes;
  54790. +} __attribute__ ((packed));
  54791. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  54792. +
  54793. +/** Descriptor DMA Alignment Buffer setup structure */
  54794. +struct _ddma_align_buffer_setup {
  54795. +#define BS_ALIGN_VAL_HDR_LEN 2
  54796. + uint8_t bEndpointAddress;
  54797. + uint8_t bAlign;
  54798. +} __attribute__ ((packed));
  54799. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  54800. +
  54801. +/** Transmit FIFO Size setup structure */
  54802. +struct _tx_fifo_size_setup {
  54803. + uint8_t bEndpointAddress;
  54804. + uint16_t wDepth;
  54805. +} __attribute__ ((packed));
  54806. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  54807. +
  54808. +/** Transmit FIFO Size setup structure */
  54809. +struct _rx_fifo_size_setup {
  54810. + uint16_t wDepth;
  54811. +} __attribute__ ((packed));
  54812. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  54813. +
  54814. +/**
  54815. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  54816. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  54817. + * to the data returned in the data stage of a 3-stage Control Write requests.
  54818. + */
  54819. +struct cfi_usb_ctrlrequest {
  54820. + uint8_t bRequestType;
  54821. + uint8_t bRequest;
  54822. + uint16_t wValue;
  54823. + uint16_t wIndex;
  54824. + uint16_t wLength;
  54825. + uint8_t *data;
  54826. +} UPACKED;
  54827. +
  54828. +/*---------------------------------------------------------------------------*/
  54829. +
  54830. +/**
  54831. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  54832. + * This structure is used to store the buffer setup data for any
  54833. + * enabled endpoint in the PCD.
  54834. + */
  54835. +struct cfi_ep {
  54836. + /* Entry for the list container */
  54837. + dwc_list_link_t lh;
  54838. + /* Pointer to the active PCD endpoint structure */
  54839. + struct dwc_otg_pcd_ep *ep;
  54840. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  54841. + struct dwc_otg_dma_desc *dma_desc_last;
  54842. + /* The SG feature value */
  54843. + ddma_sg_buffer_setup_t *bm_sg;
  54844. + /* The Circular feature value */
  54845. + ddma_sg_buffer_setup_t *bm_circ;
  54846. + /* The Concatenation feature value */
  54847. + ddma_concat_buffer_setup_t *bm_concat;
  54848. + /* The Alignment feature value */
  54849. + ddma_align_buffer_setup_t *bm_align;
  54850. + /* XFER length */
  54851. + uint32_t xfer_len;
  54852. + /*
  54853. + * Count of DMA descriptors currently used.
  54854. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  54855. + * defined in the dwc_otg_cil.h
  54856. + */
  54857. + uint32_t desc_count;
  54858. +};
  54859. +typedef struct cfi_ep cfi_ep_t;
  54860. +
  54861. +typedef struct cfi_dma_buff {
  54862. +#define CFI_IN_BUF_LEN 1024
  54863. +#define CFI_OUT_BUF_LEN 1024
  54864. + dma_addr_t addr;
  54865. + uint8_t *buf;
  54866. +} cfi_dma_buff_t;
  54867. +
  54868. +struct cfiobject;
  54869. +
  54870. +/**
  54871. + * This is the interface for the CFI operations.
  54872. + *
  54873. + * @param ep_enable Called when any endpoint is enabled and activated.
  54874. + * @param release Called when the CFI object is released and it needs to correctly
  54875. + * deallocate the dynamic memory
  54876. + * @param ctrl_write_complete Called when the data stage of the request is complete
  54877. + */
  54878. +typedef struct cfi_ops {
  54879. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54880. + struct dwc_otg_pcd_ep * ep);
  54881. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54882. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  54883. + unsigned size, gfp_t flags);
  54884. + void (*release) (struct cfiobject * cfi);
  54885. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  54886. + struct dwc_otg_pcd * pcd);
  54887. + void (*build_descriptors) (struct cfiobject * cfi,
  54888. + struct dwc_otg_pcd * pcd,
  54889. + struct dwc_otg_pcd_ep * ep,
  54890. + dwc_otg_pcd_request_t * req);
  54891. +} cfi_ops_t;
  54892. +
  54893. +struct cfiobject {
  54894. + cfi_ops_t ops;
  54895. + struct dwc_otg_pcd *pcd;
  54896. + struct usb_gadget *gadget;
  54897. +
  54898. + /* Buffers used to send/receive CFI-related request data */
  54899. + cfi_dma_buff_t buf_in;
  54900. + cfi_dma_buff_t buf_out;
  54901. +
  54902. + /* CFI specific Control request wrapper */
  54903. + struct cfi_usb_ctrlrequest ctrl_req;
  54904. +
  54905. + /* The list of active EP's in the PCD of type cfi_ep_t */
  54906. + dwc_list_link_t active_eps;
  54907. +
  54908. + /* This flag shall control the propagation of a specific request
  54909. + * to the gadget's processing routines.
  54910. + * 0 - no gadget handling
  54911. + * 1 - the gadget needs to know about this request (w/o completing a status
  54912. + * phase - just return a 0 to the _setup callback)
  54913. + */
  54914. + uint8_t need_gadget_att;
  54915. +
  54916. + /* Flag indicating whether the status IN phase needs to be
  54917. + * completed by the PCD
  54918. + */
  54919. + uint8_t need_status_in_complete;
  54920. +};
  54921. +typedef struct cfiobject cfiobject_t;
  54922. +
  54923. +#define DUMP_MSG
  54924. +
  54925. +#if defined(DUMP_MSG)
  54926. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54927. +{
  54928. + unsigned int start, num, i;
  54929. + char line[52], *p;
  54930. +
  54931. + if (length >= 512)
  54932. + return;
  54933. +
  54934. + start = 0;
  54935. + while (length > 0) {
  54936. + num = min(length, 16u);
  54937. + p = line;
  54938. + for (i = 0; i < num; ++i) {
  54939. + if (i == 8)
  54940. + *p++ = ' ';
  54941. + DWC_SPRINTF(p, " %02x", buf[i]);
  54942. + p += 3;
  54943. + }
  54944. + *p = 0;
  54945. + DWC_DEBUG("%6x: %s\n", start, line);
  54946. + buf += num;
  54947. + start += num;
  54948. + length -= num;
  54949. + }
  54950. +}
  54951. +#else
  54952. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54953. +{
  54954. +}
  54955. +#endif
  54956. +
  54957. +/**
  54958. + * This function returns a pointer to cfi_ep_t object with the addr address.
  54959. + */
  54960. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  54961. + uint8_t addr)
  54962. +{
  54963. + struct cfi_ep *pcfiep;
  54964. + dwc_list_link_t *tmp;
  54965. +
  54966. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54967. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54968. +
  54969. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  54970. + return pcfiep;
  54971. + }
  54972. + }
  54973. +
  54974. + return NULL;
  54975. +}
  54976. +
  54977. +/**
  54978. + * This function returns a pointer to cfi_ep_t object that matches
  54979. + * the dwc_otg_pcd_ep object.
  54980. + */
  54981. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  54982. + struct dwc_otg_pcd_ep *ep)
  54983. +{
  54984. + struct cfi_ep *pcfiep = NULL;
  54985. + dwc_list_link_t *tmp;
  54986. +
  54987. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54988. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54989. + if (pcfiep->ep == ep) {
  54990. + return pcfiep;
  54991. + }
  54992. + }
  54993. + return NULL;
  54994. +}
  54995. +
  54996. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  54997. +
  54998. +#endif /* (__DWC_OTG_CFI_H__) */
  54999. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  55000. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  55001. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-02-07 19:57:30.000000000 +0100
  55002. @@ -0,0 +1,7151 @@
  55003. +/* ==========================================================================
  55004. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  55005. + * $Revision: #191 $
  55006. + * $Date: 2012/08/10 $
  55007. + * $Change: 2047372 $
  55008. + *
  55009. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55010. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55011. + * otherwise expressly agreed to in writing between Synopsys and you.
  55012. + *
  55013. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55014. + * any End User Software License Agreement or Agreement for Licensed Product
  55015. + * with Synopsys or any supplement thereto. You are permitted to use and
  55016. + * redistribute this Software in source and binary forms, with or without
  55017. + * modification, provided that redistributions of source code must retain this
  55018. + * notice. You may not view, use, disclose, copy or distribute this file or
  55019. + * any information contained herein except pursuant to this license grant from
  55020. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55021. + * below, then you are not authorized to use the Software.
  55022. + *
  55023. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55024. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55025. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55026. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55027. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55028. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55029. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55030. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55031. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55032. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55033. + * DAMAGE.
  55034. + * ========================================================================== */
  55035. +
  55036. +/** @file
  55037. + *
  55038. + * The Core Interface Layer provides basic services for accessing and
  55039. + * managing the DWC_otg hardware. These services are used by both the
  55040. + * Host Controller Driver and the Peripheral Controller Driver.
  55041. + *
  55042. + * The CIL manages the memory map for the core so that the HCD and PCD
  55043. + * don't have to do this separately. It also handles basic tasks like
  55044. + * reading/writing the registers and data FIFOs in the controller.
  55045. + * Some of the data access functions provide encapsulation of several
  55046. + * operations required to perform a task, such as writing multiple
  55047. + * registers to start a transfer. Finally, the CIL performs basic
  55048. + * services that are not specific to either the host or device modes
  55049. + * of operation. These services include management of the OTG Host
  55050. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  55051. + * Diagnostic API is also provided to allow testing of the controller
  55052. + * hardware.
  55053. + *
  55054. + * The Core Interface Layer has the following requirements:
  55055. + * - Provides basic controller operations.
  55056. + * - Minimal use of OS services.
  55057. + * - The OS services used will be abstracted by using inline functions
  55058. + * or macros.
  55059. + *
  55060. + */
  55061. +
  55062. +#include "dwc_os.h"
  55063. +#include "dwc_otg_regs.h"
  55064. +#include "dwc_otg_cil.h"
  55065. +
  55066. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  55067. +
  55068. +/**
  55069. + * This function is called to initialize the DWC_otg CSR data
  55070. + * structures. The register addresses in the device and host
  55071. + * structures are initialized from the base address supplied by the
  55072. + * caller. The calling function must make the OS calls to get the
  55073. + * base address of the DWC_otg controller registers. The core_params
  55074. + * argument holds the parameters that specify how the core should be
  55075. + * configured.
  55076. + *
  55077. + * @param reg_base_addr Base address of DWC_otg core registers
  55078. + *
  55079. + */
  55080. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  55081. +{
  55082. + dwc_otg_core_if_t *core_if = 0;
  55083. + dwc_otg_dev_if_t *dev_if = 0;
  55084. + dwc_otg_host_if_t *host_if = 0;
  55085. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  55086. + int i = 0;
  55087. +
  55088. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  55089. +
  55090. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  55091. +
  55092. + if (core_if == NULL) {
  55093. + DWC_DEBUGPL(DBG_CIL,
  55094. + "Allocation of dwc_otg_core_if_t failed\n");
  55095. + return 0;
  55096. + }
  55097. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  55098. +
  55099. + /*
  55100. + * Allocate the Device Mode structures.
  55101. + */
  55102. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  55103. +
  55104. + if (dev_if == NULL) {
  55105. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  55106. + DWC_FREE(core_if);
  55107. + return 0;
  55108. + }
  55109. +
  55110. + dev_if->dev_global_regs =
  55111. + (dwc_otg_device_global_regs_t *) (reg_base +
  55112. + DWC_DEV_GLOBAL_REG_OFFSET);
  55113. +
  55114. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55115. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  55116. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  55117. + (i * DWC_EP_REG_OFFSET));
  55118. +
  55119. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  55120. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  55121. + (i * DWC_EP_REG_OFFSET));
  55122. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  55123. + i, &dev_if->in_ep_regs[i]->diepctl);
  55124. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  55125. + i, &dev_if->out_ep_regs[i]->doepctl);
  55126. + }
  55127. +
  55128. + dev_if->speed = 0; // unknown
  55129. +
  55130. + core_if->dev_if = dev_if;
  55131. +
  55132. + /*
  55133. + * Allocate the Host Mode structures.
  55134. + */
  55135. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  55136. +
  55137. + if (host_if == NULL) {
  55138. + DWC_DEBUGPL(DBG_CIL,
  55139. + "Allocation of dwc_otg_host_if_t failed\n");
  55140. + DWC_FREE(dev_if);
  55141. + DWC_FREE(core_if);
  55142. + return 0;
  55143. + }
  55144. +
  55145. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  55146. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  55147. +
  55148. + host_if->hprt0 =
  55149. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  55150. +
  55151. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55152. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  55153. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  55154. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  55155. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  55156. + i, &host_if->hc_regs[i]->hcchar);
  55157. + }
  55158. +
  55159. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  55160. + core_if->host_if = host_if;
  55161. +
  55162. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55163. + core_if->data_fifo[i] =
  55164. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  55165. + (i * DWC_OTG_DATA_FIFO_SIZE));
  55166. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  55167. + i, (unsigned long)core_if->data_fifo[i]);
  55168. + }
  55169. +
  55170. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  55171. +
  55172. + /* Initiate lx_state to L3 disconnected state */
  55173. + core_if->lx_state = DWC_OTG_L3;
  55174. + /*
  55175. + * Store the contents of the hardware configuration registers here for
  55176. + * easy access later.
  55177. + */
  55178. + core_if->hwcfg1.d32 =
  55179. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  55180. + core_if->hwcfg2.d32 =
  55181. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  55182. + core_if->hwcfg3.d32 =
  55183. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  55184. + core_if->hwcfg4.d32 =
  55185. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  55186. +
  55187. + /* Force host mode to get HPTXFSIZ exact power on value */
  55188. + {
  55189. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55190. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55191. + gusbcfg.b.force_host_mode = 1;
  55192. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55193. + dwc_mdelay(100);
  55194. + core_if->hptxfsiz.d32 =
  55195. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55196. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55197. + gusbcfg.b.force_host_mode = 0;
  55198. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55199. + dwc_mdelay(100);
  55200. + }
  55201. +
  55202. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  55203. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  55204. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  55205. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  55206. +
  55207. + core_if->hcfg.d32 =
  55208. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55209. + core_if->dcfg.d32 =
  55210. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55211. +
  55212. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  55213. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  55214. +
  55215. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  55216. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  55217. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  55218. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  55219. + core_if->hwcfg2.b.num_host_chan);
  55220. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  55221. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  55222. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  55223. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  55224. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  55225. + core_if->hwcfg2.b.dev_token_q_depth);
  55226. +
  55227. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  55228. + core_if->hwcfg3.b.dfifo_depth);
  55229. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  55230. + core_if->hwcfg3.b.xfer_size_cntr_width);
  55231. +
  55232. + /*
  55233. + * Set the SRP sucess bit for FS-I2c
  55234. + */
  55235. + core_if->srp_success = 0;
  55236. + core_if->srp_timer_started = 0;
  55237. +
  55238. + /*
  55239. + * Create new workqueue and init works
  55240. + */
  55241. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  55242. + if (core_if->wq_otg == 0) {
  55243. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  55244. + DWC_FREE(host_if);
  55245. + DWC_FREE(dev_if);
  55246. + DWC_FREE(core_if);
  55247. + return 0;
  55248. + }
  55249. +
  55250. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  55251. +
  55252. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  55253. + (core_if->snpsid >> 12 & 0xF),
  55254. + (core_if->snpsid >> 8 & 0xF),
  55255. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  55256. +
  55257. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  55258. + w_wakeup_detected, core_if);
  55259. + if (core_if->wkp_timer == 0) {
  55260. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  55261. + DWC_FREE(host_if);
  55262. + DWC_FREE(dev_if);
  55263. + DWC_WORKQ_FREE(core_if->wq_otg);
  55264. + DWC_FREE(core_if);
  55265. + return 0;
  55266. + }
  55267. +
  55268. + if (dwc_otg_setup_params(core_if)) {
  55269. + DWC_WARN("Error while setting core params\n");
  55270. + }
  55271. +
  55272. + core_if->hibernation_suspend = 0;
  55273. +
  55274. + /** ADP initialization */
  55275. + dwc_otg_adp_init(core_if);
  55276. +
  55277. + return core_if;
  55278. +}
  55279. +
  55280. +/**
  55281. + * This function frees the structures allocated by dwc_otg_cil_init().
  55282. + *
  55283. + * @param core_if The core interface pointer returned from
  55284. + * dwc_otg_cil_init().
  55285. + *
  55286. + */
  55287. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  55288. +{
  55289. + dctl_data_t dctl = {.d32 = 0 };
  55290. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  55291. +
  55292. + /* Disable all interrupts */
  55293. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  55294. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  55295. +
  55296. + dctl.b.sftdiscon = 1;
  55297. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  55298. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  55299. + dctl.d32);
  55300. + }
  55301. +
  55302. + if (core_if->wq_otg) {
  55303. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  55304. + DWC_WORKQ_FREE(core_if->wq_otg);
  55305. + }
  55306. + if (core_if->dev_if) {
  55307. + DWC_FREE(core_if->dev_if);
  55308. + }
  55309. + if (core_if->host_if) {
  55310. + DWC_FREE(core_if->host_if);
  55311. + }
  55312. +
  55313. + /** Remove ADP Stuff */
  55314. + dwc_otg_adp_remove(core_if);
  55315. + if (core_if->core_params) {
  55316. + DWC_FREE(core_if->core_params);
  55317. + }
  55318. + if (core_if->wkp_timer) {
  55319. + DWC_TIMER_FREE(core_if->wkp_timer);
  55320. + }
  55321. + if (core_if->srp_timer) {
  55322. + DWC_TIMER_FREE(core_if->srp_timer);
  55323. + }
  55324. + DWC_FREE(core_if);
  55325. +}
  55326. +
  55327. +/**
  55328. + * This function enables the controller's Global Interrupt in the AHB Config
  55329. + * register.
  55330. + *
  55331. + * @param core_if Programming view of DWC_otg controller.
  55332. + */
  55333. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  55334. +{
  55335. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55336. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  55337. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  55338. +}
  55339. +
  55340. +/**
  55341. + * This function disables the controller's Global Interrupt in the AHB Config
  55342. + * register.
  55343. + *
  55344. + * @param core_if Programming view of DWC_otg controller.
  55345. + */
  55346. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  55347. +{
  55348. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55349. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  55350. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  55351. +}
  55352. +
  55353. +/**
  55354. + * This function initializes the commmon interrupts, used in both
  55355. + * device and host modes.
  55356. + *
  55357. + * @param core_if Programming view of the DWC_otg controller
  55358. + *
  55359. + */
  55360. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  55361. +{
  55362. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55363. + gintmsk_data_t intr_mask = {.d32 = 0 };
  55364. +
  55365. + /* Clear any pending OTG Interrupts */
  55366. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  55367. +
  55368. + /* Clear any pending interrupts */
  55369. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  55370. +
  55371. + /*
  55372. + * Enable the interrupts in the GINTMSK.
  55373. + */
  55374. + intr_mask.b.modemismatch = 1;
  55375. + intr_mask.b.otgintr = 1;
  55376. +
  55377. + if (!core_if->dma_enable) {
  55378. + intr_mask.b.rxstsqlvl = 1;
  55379. + }
  55380. +
  55381. + intr_mask.b.conidstschng = 1;
  55382. + intr_mask.b.wkupintr = 1;
  55383. + intr_mask.b.disconnect = 0;
  55384. + intr_mask.b.usbsuspend = 1;
  55385. + intr_mask.b.sessreqintr = 1;
  55386. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55387. + if (core_if->core_params->lpm_enable) {
  55388. + intr_mask.b.lpmtranrcvd = 1;
  55389. + }
  55390. +#endif
  55391. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  55392. +}
  55393. +
  55394. +/*
  55395. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55396. + * Hibernation. This function is for exiting from Device mode hibernation by
  55397. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55398. + * @param core_if Programming view of DWC_otg controller.
  55399. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55400. + * @param reset - indicates whether resume is initiated by Reset.
  55401. + */
  55402. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  55403. + int rem_wakeup, int reset)
  55404. +{
  55405. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55406. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  55407. + dctl_data_t dctl = {.d32 = 0 };
  55408. +
  55409. + int timeout = 2000;
  55410. +
  55411. + if (!core_if->hibernation_suspend) {
  55412. + DWC_PRINTF("Already exited from Hibernation\n");
  55413. + return 1;
  55414. + }
  55415. +
  55416. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  55417. + /* Switch-on voltage to the core */
  55418. + gpwrdn.b.pwrdnswtch = 1;
  55419. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55420. + dwc_udelay(10);
  55421. +
  55422. + /* Reset core */
  55423. + gpwrdn.d32 = 0;
  55424. + gpwrdn.b.pwrdnrstn = 1;
  55425. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55426. + dwc_udelay(10);
  55427. +
  55428. + /* Assert Restore signal */
  55429. + gpwrdn.d32 = 0;
  55430. + gpwrdn.b.restore = 1;
  55431. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55432. + dwc_udelay(10);
  55433. +
  55434. + /* Disable power clamps */
  55435. + gpwrdn.d32 = 0;
  55436. + gpwrdn.b.pwrdnclmp = 1;
  55437. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55438. +
  55439. + if (rem_wakeup) {
  55440. + dwc_udelay(70);
  55441. + }
  55442. +
  55443. + /* Deassert Reset core */
  55444. + gpwrdn.d32 = 0;
  55445. + gpwrdn.b.pwrdnrstn = 1;
  55446. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55447. + dwc_udelay(10);
  55448. +
  55449. + /* Disable PMU interrupt */
  55450. + gpwrdn.d32 = 0;
  55451. + gpwrdn.b.pmuintsel = 1;
  55452. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55453. +
  55454. + /* Mask interrupts from gpwrdn */
  55455. + gpwrdn.d32 = 0;
  55456. + gpwrdn.b.connect_det_msk = 1;
  55457. + gpwrdn.b.srp_det_msk = 1;
  55458. + gpwrdn.b.disconn_det_msk = 1;
  55459. + gpwrdn.b.rst_det_msk = 1;
  55460. + gpwrdn.b.lnstchng_msk = 1;
  55461. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55462. +
  55463. + /* Indicates that we are going out from hibernation */
  55464. + core_if->hibernation_suspend = 0;
  55465. +
  55466. + /*
  55467. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  55468. + * indicates restore from remote_wakeup
  55469. + */
  55470. + restore_essential_regs(core_if, rem_wakeup, 0);
  55471. +
  55472. + /*
  55473. + * Wait a little for seeing new value of variable hibernation_suspend if
  55474. + * Restore done interrupt received before polling
  55475. + */
  55476. + dwc_udelay(10);
  55477. +
  55478. + if (core_if->hibernation_suspend == 0) {
  55479. + /*
  55480. + * Wait For Restore_done Interrupt. This mechanism of polling the
  55481. + * interrupt is introduced to avoid any possible race conditions
  55482. + */
  55483. + do {
  55484. + gintsts_data_t gintsts;
  55485. + gintsts.d32 =
  55486. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55487. + if (gintsts.b.restoredone) {
  55488. + gintsts.d32 = 0;
  55489. + gintsts.b.restoredone = 1;
  55490. + DWC_WRITE_REG32(&core_if->core_global_regs->
  55491. + gintsts, gintsts.d32);
  55492. + DWC_PRINTF("Restore Done Interrupt seen\n");
  55493. + break;
  55494. + }
  55495. + dwc_udelay(10);
  55496. + } while (--timeout);
  55497. + if (!timeout) {
  55498. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  55499. + }
  55500. + }
  55501. + /* Clear all pending interupts */
  55502. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55503. +
  55504. + /* De-assert Restore */
  55505. + gpwrdn.d32 = 0;
  55506. + gpwrdn.b.restore = 1;
  55507. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55508. + dwc_udelay(10);
  55509. +
  55510. + if (!rem_wakeup) {
  55511. + pcgcctl.d32 = 0;
  55512. + pcgcctl.b.rstpdwnmodule = 1;
  55513. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  55514. + }
  55515. +
  55516. + /* Restore GUSBCFG and DCFG */
  55517. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55518. + core_if->gr_backup->gusbcfg_local);
  55519. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  55520. + core_if->dr_backup->dcfg);
  55521. +
  55522. + /* De-assert Wakeup Logic */
  55523. + gpwrdn.d32 = 0;
  55524. + gpwrdn.b.pmuactv = 1;
  55525. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55526. + dwc_udelay(10);
  55527. +
  55528. + if (!rem_wakeup) {
  55529. + /* Set Device programming done bit */
  55530. + dctl.b.pwronprgdone = 1;
  55531. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  55532. + } else {
  55533. + /* Start Remote Wakeup Signaling */
  55534. + dctl.d32 = core_if->dr_backup->dctl;
  55535. + dctl.b.rmtwkupsig = 1;
  55536. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  55537. + }
  55538. +
  55539. + dwc_mdelay(2);
  55540. + /* Clear all pending interupts */
  55541. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55542. +
  55543. + /* Restore global registers */
  55544. + dwc_otg_restore_global_regs(core_if);
  55545. + /* Restore device global registers */
  55546. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  55547. +
  55548. + if (rem_wakeup) {
  55549. + dwc_mdelay(7);
  55550. + dctl.d32 = 0;
  55551. + dctl.b.rmtwkupsig = 1;
  55552. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  55553. + }
  55554. +
  55555. + core_if->hibernation_suspend = 0;
  55556. + /* The core will be in ON STATE */
  55557. + core_if->lx_state = DWC_OTG_L0;
  55558. + DWC_PRINTF("Hibernation recovery completes here\n");
  55559. +
  55560. + return 1;
  55561. +}
  55562. +
  55563. +/*
  55564. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55565. + * Hibernation. This function is for exiting from Host mode hibernation by
  55566. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55567. + * @param core_if Programming view of DWC_otg controller.
  55568. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55569. + * @param reset - indicates whether resume is initiated by Reset.
  55570. + */
  55571. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  55572. + int rem_wakeup, int reset)
  55573. +{
  55574. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55575. + hprt0_data_t hprt0 = {.d32 = 0 };
  55576. +
  55577. + int timeout = 2000;
  55578. +
  55579. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  55580. + /* Switch-on voltage to the core */
  55581. + gpwrdn.b.pwrdnswtch = 1;
  55582. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55583. + dwc_udelay(10);
  55584. +
  55585. + /* Reset core */
  55586. + gpwrdn.d32 = 0;
  55587. + gpwrdn.b.pwrdnrstn = 1;
  55588. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55589. + dwc_udelay(10);
  55590. +
  55591. + /* Assert Restore signal */
  55592. + gpwrdn.d32 = 0;
  55593. + gpwrdn.b.restore = 1;
  55594. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55595. + dwc_udelay(10);
  55596. +
  55597. + /* Disable power clamps */
  55598. + gpwrdn.d32 = 0;
  55599. + gpwrdn.b.pwrdnclmp = 1;
  55600. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55601. +
  55602. + if (!rem_wakeup) {
  55603. + dwc_udelay(50);
  55604. + }
  55605. +
  55606. + /* Deassert Reset core */
  55607. + gpwrdn.d32 = 0;
  55608. + gpwrdn.b.pwrdnrstn = 1;
  55609. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55610. + dwc_udelay(10);
  55611. +
  55612. + /* Disable PMU interrupt */
  55613. + gpwrdn.d32 = 0;
  55614. + gpwrdn.b.pmuintsel = 1;
  55615. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55616. +
  55617. + gpwrdn.d32 = 0;
  55618. + gpwrdn.b.connect_det_msk = 1;
  55619. + gpwrdn.b.srp_det_msk = 1;
  55620. + gpwrdn.b.disconn_det_msk = 1;
  55621. + gpwrdn.b.rst_det_msk = 1;
  55622. + gpwrdn.b.lnstchng_msk = 1;
  55623. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55624. +
  55625. + /* Indicates that we are going out from hibernation */
  55626. + core_if->hibernation_suspend = 0;
  55627. +
  55628. + /* Set Restore Essential Regs bit in PCGCCTL register */
  55629. + restore_essential_regs(core_if, rem_wakeup, 1);
  55630. +
  55631. + /* Wait a little for seeing new value of variable hibernation_suspend if
  55632. + * Restore done interrupt received before polling */
  55633. + dwc_udelay(10);
  55634. +
  55635. + if (core_if->hibernation_suspend == 0) {
  55636. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  55637. + * interrupt is introduced to avoid any possible race conditions
  55638. + */
  55639. + do {
  55640. + gintsts_data_t gintsts;
  55641. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55642. + if (gintsts.b.restoredone) {
  55643. + gintsts.d32 = 0;
  55644. + gintsts.b.restoredone = 1;
  55645. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  55646. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  55647. + break;
  55648. + }
  55649. + dwc_udelay(10);
  55650. + } while (--timeout);
  55651. + if (!timeout) {
  55652. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  55653. + }
  55654. + }
  55655. +
  55656. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  55657. + core_if->hibernation_suspend = 0;
  55658. +
  55659. + /* This step is not described in functional spec but if not wait for this
  55660. + * delay, mismatch interrupts occurred because just after restore core is
  55661. + * in Device mode(gintsts.curmode == 0) */
  55662. + dwc_mdelay(100);
  55663. +
  55664. + /* Clear all pending interrupts */
  55665. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55666. +
  55667. + /* De-assert Restore */
  55668. + gpwrdn.d32 = 0;
  55669. + gpwrdn.b.restore = 1;
  55670. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55671. + dwc_udelay(10);
  55672. +
  55673. + /* Restore GUSBCFG and HCFG */
  55674. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55675. + core_if->gr_backup->gusbcfg_local);
  55676. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  55677. + core_if->hr_backup->hcfg_local);
  55678. +
  55679. + /* De-assert Wakeup Logic */
  55680. + gpwrdn.d32 = 0;
  55681. + gpwrdn.b.pmuactv = 1;
  55682. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55683. + dwc_udelay(10);
  55684. +
  55685. + /* Start the Resume operation by programming HPRT0 */
  55686. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55687. + hprt0.b.prtpwr = 1;
  55688. + hprt0.b.prtena = 0;
  55689. + hprt0.b.prtsusp = 0;
  55690. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55691. +
  55692. + DWC_PRINTF("Resume Starts Now\n");
  55693. + if (!reset) { // Indicates it is Resume Operation
  55694. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55695. + hprt0.b.prtres = 1;
  55696. + hprt0.b.prtpwr = 1;
  55697. + hprt0.b.prtena = 0;
  55698. + hprt0.b.prtsusp = 0;
  55699. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55700. +
  55701. + if (!rem_wakeup)
  55702. + hprt0.b.prtres = 0;
  55703. + /* Wait for Resume time and then program HPRT again */
  55704. + dwc_mdelay(100);
  55705. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55706. +
  55707. + } else { // Indicates it is Reset Operation
  55708. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55709. + hprt0.b.prtrst = 1;
  55710. + hprt0.b.prtpwr = 1;
  55711. + hprt0.b.prtena = 0;
  55712. + hprt0.b.prtsusp = 0;
  55713. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55714. + /* Wait for Reset time and then program HPRT again */
  55715. + dwc_mdelay(60);
  55716. + hprt0.b.prtrst = 0;
  55717. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55718. + }
  55719. + /* Clear all interrupt status */
  55720. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  55721. + hprt0.b.prtconndet = 1;
  55722. + hprt0.b.prtenchng = 1;
  55723. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55724. +
  55725. + /* Clear all pending interupts */
  55726. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55727. +
  55728. + /* Restore global registers */
  55729. + dwc_otg_restore_global_regs(core_if);
  55730. + /* Restore host global registers */
  55731. + dwc_otg_restore_host_regs(core_if, reset);
  55732. +
  55733. + /* The core will be in ON STATE */
  55734. + core_if->lx_state = DWC_OTG_L0;
  55735. + DWC_PRINTF("Hibernation recovery is complete here\n");
  55736. + return 0;
  55737. +}
  55738. +
  55739. +/** Saves some register values into system memory. */
  55740. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  55741. +{
  55742. + struct dwc_otg_global_regs_backup *gr;
  55743. + int i;
  55744. +
  55745. + gr = core_if->gr_backup;
  55746. + if (!gr) {
  55747. + gr = DWC_ALLOC(sizeof(*gr));
  55748. + if (!gr) {
  55749. + return -DWC_E_NO_MEMORY;
  55750. + }
  55751. + core_if->gr_backup = gr;
  55752. + }
  55753. +
  55754. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  55755. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55756. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  55757. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55758. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  55759. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  55760. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55761. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55762. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  55763. +#endif
  55764. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  55765. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  55766. + gr->gdfifocfg_local =
  55767. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  55768. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55769. + gr->dtxfsiz_local[i] =
  55770. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  55771. + }
  55772. +
  55773. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  55774. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  55775. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55776. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  55777. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  55778. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  55779. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  55780. + gr->gnptxfsiz_local);
  55781. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  55782. + gr->hptxfsiz_local);
  55783. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55784. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  55785. +#endif
  55786. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  55787. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  55788. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  55789. +
  55790. + return 0;
  55791. +}
  55792. +
  55793. +/** Saves GINTMSK register before setting the msk bits. */
  55794. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  55795. +{
  55796. + struct dwc_otg_global_regs_backup *gr;
  55797. +
  55798. + gr = core_if->gr_backup;
  55799. + if (!gr) {
  55800. + gr = DWC_ALLOC(sizeof(*gr));
  55801. + if (!gr) {
  55802. + return -DWC_E_NO_MEMORY;
  55803. + }
  55804. + core_if->gr_backup = gr;
  55805. + }
  55806. +
  55807. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55808. +
  55809. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  55810. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55811. +
  55812. + return 0;
  55813. +}
  55814. +
  55815. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  55816. +{
  55817. + struct dwc_otg_dev_regs_backup *dr;
  55818. + int i;
  55819. +
  55820. + dr = core_if->dr_backup;
  55821. + if (!dr) {
  55822. + dr = DWC_ALLOC(sizeof(*dr));
  55823. + if (!dr) {
  55824. + return -DWC_E_NO_MEMORY;
  55825. + }
  55826. + core_if->dr_backup = dr;
  55827. + }
  55828. +
  55829. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55830. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  55831. + dr->daintmsk =
  55832. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  55833. + dr->diepmsk =
  55834. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  55835. + dr->doepmsk =
  55836. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  55837. +
  55838. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55839. + dr->diepctl[i] =
  55840. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  55841. + dr->dieptsiz[i] =
  55842. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  55843. + dr->diepdma[i] =
  55844. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  55845. + }
  55846. +
  55847. + DWC_DEBUGPL(DBG_ANY,
  55848. + "=============Backing Host registers==============\n");
  55849. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  55850. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  55851. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  55852. + dr->daintmsk);
  55853. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  55854. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  55855. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55856. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  55857. + dr->diepctl[i]);
  55858. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  55859. + i, dr->dieptsiz[i]);
  55860. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  55861. + dr->diepdma[i]);
  55862. + }
  55863. +
  55864. + return 0;
  55865. +}
  55866. +
  55867. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  55868. +{
  55869. + struct dwc_otg_host_regs_backup *hr;
  55870. + int i;
  55871. +
  55872. + hr = core_if->hr_backup;
  55873. + if (!hr) {
  55874. + hr = DWC_ALLOC(sizeof(*hr));
  55875. + if (!hr) {
  55876. + return -DWC_E_NO_MEMORY;
  55877. + }
  55878. + core_if->hr_backup = hr;
  55879. + }
  55880. +
  55881. + hr->hcfg_local =
  55882. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55883. + hr->haintmsk_local =
  55884. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  55885. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55886. + hr->hcintmsk_local[i] =
  55887. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  55888. + }
  55889. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  55890. + hr->hfir_local =
  55891. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  55892. +
  55893. + DWC_DEBUGPL(DBG_ANY,
  55894. + "=============Backing Host registers===============\n");
  55895. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  55896. + hr->hcfg_local);
  55897. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  55898. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55899. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  55900. + hr->hcintmsk_local[i]);
  55901. + }
  55902. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  55903. + hr->hprt0_local);
  55904. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  55905. + hr->hfir_local);
  55906. +
  55907. + return 0;
  55908. +}
  55909. +
  55910. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  55911. +{
  55912. + struct dwc_otg_global_regs_backup *gr;
  55913. + int i;
  55914. +
  55915. + gr = core_if->gr_backup;
  55916. + if (!gr) {
  55917. + return -DWC_E_INVALID;
  55918. + }
  55919. +
  55920. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  55921. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  55922. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  55923. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  55924. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  55925. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  55926. + gr->gnptxfsiz_local);
  55927. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  55928. + gr->hptxfsiz_local);
  55929. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  55930. + gr->gdfifocfg_local);
  55931. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55932. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  55933. + gr->dtxfsiz_local[i]);
  55934. + }
  55935. +
  55936. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55937. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  55938. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  55939. + (gr->gahbcfg_local));
  55940. + return 0;
  55941. +}
  55942. +
  55943. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  55944. +{
  55945. + struct dwc_otg_dev_regs_backup *dr;
  55946. + int i;
  55947. +
  55948. + dr = core_if->dr_backup;
  55949. +
  55950. + if (!dr) {
  55951. + return -DWC_E_INVALID;
  55952. + }
  55953. +
  55954. + if (!rem_wakeup) {
  55955. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  55956. + dr->dctl);
  55957. + }
  55958. +
  55959. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  55960. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  55961. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  55962. +
  55963. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55964. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  55965. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  55966. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  55967. + }
  55968. +
  55969. + return 0;
  55970. +}
  55971. +
  55972. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  55973. +{
  55974. + struct dwc_otg_host_regs_backup *hr;
  55975. + int i;
  55976. + hr = core_if->hr_backup;
  55977. +
  55978. + if (!hr) {
  55979. + return -DWC_E_INVALID;
  55980. + }
  55981. +
  55982. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  55983. + //if (!reset)
  55984. + //{
  55985. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  55986. + //}
  55987. +
  55988. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  55989. + hr->haintmsk_local);
  55990. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55991. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  55992. + hr->hcintmsk_local[i]);
  55993. + }
  55994. +
  55995. + return 0;
  55996. +}
  55997. +
  55998. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  55999. +{
  56000. + struct dwc_otg_global_regs_backup *gr;
  56001. +
  56002. + gr = core_if->gr_backup;
  56003. +
  56004. + /* Restore values for LPM and I2C */
  56005. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56006. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  56007. +#endif
  56008. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  56009. +
  56010. + return 0;
  56011. +}
  56012. +
  56013. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  56014. +{
  56015. + struct dwc_otg_global_regs_backup *gr;
  56016. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56017. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  56018. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56019. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56020. +
  56021. + /* Restore LPM and I2C registers */
  56022. + restore_lpm_i2c_regs(core_if);
  56023. +
  56024. + /* Set PCGCCTL to 0 */
  56025. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  56026. +
  56027. + gr = core_if->gr_backup;
  56028. + /* Load restore values for [31:14] bits */
  56029. + DWC_WRITE_REG32(core_if->pcgcctl,
  56030. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  56031. +
  56032. + /* Umnask global Interrupt in GAHBCFG and restore it */
  56033. + gahbcfg.d32 = gr->gahbcfg_local;
  56034. + gahbcfg.b.glblintrmsk = 1;
  56035. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  56036. +
  56037. + /* Clear all pending interupts */
  56038. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56039. +
  56040. + /* Unmask restore done interrupt */
  56041. + gintmsk.b.restoredone = 1;
  56042. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  56043. +
  56044. + /* Restore GUSBCFG and HCFG/DCFG */
  56045. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  56046. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56047. +
  56048. + if (is_host) {
  56049. + hcfg_data_t hcfg = {.d32 = 0 };
  56050. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  56051. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56052. + hcfg.d32);
  56053. +
  56054. + /* Load restore values for [31:14] bits */
  56055. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56056. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56057. +
  56058. + if (rmode)
  56059. + pcgcctl.b.restoremode = 1;
  56060. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56061. + dwc_udelay(10);
  56062. +
  56063. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  56064. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  56065. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56066. + pcgcctl.b.ess_reg_restored = 1;
  56067. + if (rmode)
  56068. + pcgcctl.b.restoremode = 1;
  56069. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56070. + } else {
  56071. + dcfg_data_t dcfg = {.d32 = 0 };
  56072. + dcfg.d32 = core_if->dr_backup->dcfg;
  56073. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56074. +
  56075. + /* Load restore values for [31:14] bits */
  56076. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56077. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56078. + if (!rmode) {
  56079. + pcgcctl.d32 |= 0x208;
  56080. + }
  56081. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56082. + dwc_udelay(10);
  56083. +
  56084. + /* Load restore values for [31:14] bits */
  56085. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56086. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56087. + pcgcctl.b.ess_reg_restored = 1;
  56088. + if (!rmode)
  56089. + pcgcctl.d32 |= 0x208;
  56090. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56091. + }
  56092. +
  56093. + return 0;
  56094. +}
  56095. +
  56096. +/**
  56097. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  56098. + * type.
  56099. + */
  56100. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  56101. +{
  56102. + uint32_t val;
  56103. + hcfg_data_t hcfg;
  56104. +
  56105. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56106. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56107. + (core_if->core_params->ulpi_fs_ls)) ||
  56108. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56109. + /* Full speed PHY */
  56110. + val = DWC_HCFG_48_MHZ;
  56111. + } else {
  56112. + /* High speed PHY running at full speed or high speed */
  56113. + val = DWC_HCFG_30_60_MHZ;
  56114. + }
  56115. +
  56116. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  56117. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56118. + hcfg.b.fslspclksel = val;
  56119. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  56120. +}
  56121. +
  56122. +/**
  56123. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  56124. + * and the enumeration speed of the device.
  56125. + */
  56126. +static void init_devspd(dwc_otg_core_if_t * core_if)
  56127. +{
  56128. + uint32_t val;
  56129. + dcfg_data_t dcfg;
  56130. +
  56131. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56132. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56133. + (core_if->core_params->ulpi_fs_ls)) ||
  56134. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56135. + /* Full speed PHY */
  56136. + val = 0x3;
  56137. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  56138. + /* High speed PHY running at full speed */
  56139. + val = 0x1;
  56140. + } else {
  56141. + /* High speed PHY running at high speed */
  56142. + val = 0x0;
  56143. + }
  56144. +
  56145. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  56146. +
  56147. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56148. + dcfg.b.devspd = val;
  56149. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56150. +}
  56151. +
  56152. +/**
  56153. + * This function calculates the number of IN EPS
  56154. + * using GHWCFG1 and GHWCFG2 registers values
  56155. + *
  56156. + * @param core_if Programming view of the DWC_otg controller
  56157. + */
  56158. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  56159. +{
  56160. + uint32_t num_in_eps = 0;
  56161. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56162. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  56163. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  56164. + int i;
  56165. +
  56166. + for (i = 0; i < num_eps; ++i) {
  56167. + if (!(hwcfg1 & 0x1))
  56168. + num_in_eps++;
  56169. +
  56170. + hwcfg1 >>= 2;
  56171. + }
  56172. +
  56173. + if (core_if->hwcfg4.b.ded_fifo_en) {
  56174. + num_in_eps =
  56175. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  56176. + }
  56177. +
  56178. + return num_in_eps;
  56179. +}
  56180. +
  56181. +/**
  56182. + * This function calculates the number of OUT EPS
  56183. + * using GHWCFG1 and GHWCFG2 registers values
  56184. + *
  56185. + * @param core_if Programming view of the DWC_otg controller
  56186. + */
  56187. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  56188. +{
  56189. + uint32_t num_out_eps = 0;
  56190. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56191. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  56192. + int i;
  56193. +
  56194. + for (i = 0; i < num_eps; ++i) {
  56195. + if (!(hwcfg1 & 0x1))
  56196. + num_out_eps++;
  56197. +
  56198. + hwcfg1 >>= 2;
  56199. + }
  56200. + return num_out_eps;
  56201. +}
  56202. +
  56203. +/**
  56204. + * This function initializes the DWC_otg controller registers and
  56205. + * prepares the core for device mode or host mode operation.
  56206. + *
  56207. + * @param core_if Programming view of the DWC_otg controller
  56208. + *
  56209. + */
  56210. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  56211. +{
  56212. + int i = 0;
  56213. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56214. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56215. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56216. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  56217. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  56218. +
  56219. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  56220. + core_if, global_regs);
  56221. +
  56222. + /* Common Initialization */
  56223. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56224. +
  56225. + /* Program the ULPI External VBUS bit if needed */
  56226. + usbcfg.b.ulpi_ext_vbus_drv =
  56227. + (core_if->core_params->phy_ulpi_ext_vbus ==
  56228. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  56229. +
  56230. + /* Set external TS Dline pulsing */
  56231. + usbcfg.b.term_sel_dl_pulse =
  56232. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  56233. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56234. +
  56235. + /* Reset the Controller */
  56236. + dwc_otg_core_reset(core_if);
  56237. +
  56238. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  56239. + core_if->power_down = core_if->core_params->power_down;
  56240. + core_if->otg_sts = 0;
  56241. +
  56242. + /* Initialize parameters from Hardware configuration registers. */
  56243. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  56244. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  56245. +
  56246. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  56247. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  56248. +
  56249. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56250. + dev_if->perio_tx_fifo_size[i] =
  56251. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56252. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  56253. + i, dev_if->perio_tx_fifo_size[i]);
  56254. + }
  56255. +
  56256. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56257. + dev_if->tx_fifo_size[i] =
  56258. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56259. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  56260. + i, dev_if->tx_fifo_size[i]);
  56261. + }
  56262. +
  56263. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  56264. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  56265. + core_if->nperio_tx_fifo_size =
  56266. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  56267. +
  56268. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  56269. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  56270. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  56271. + core_if->nperio_tx_fifo_size);
  56272. +
  56273. + /* This programming sequence needs to happen in FS mode before any other
  56274. + * programming occurs */
  56275. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  56276. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56277. + /* If FS mode with FS PHY */
  56278. +
  56279. + /* core_init() is now called on every switch so only call the
  56280. + * following for the first time through. */
  56281. + if (!core_if->phy_init_done) {
  56282. + core_if->phy_init_done = 1;
  56283. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  56284. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56285. + usbcfg.b.physel = 1;
  56286. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56287. +
  56288. + /* Reset after a PHY select */
  56289. + dwc_otg_core_reset(core_if);
  56290. + }
  56291. +
  56292. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  56293. + * do this on HNP Dev/Host mode switches (done in dev_init and
  56294. + * host_init). */
  56295. + if (dwc_otg_is_host_mode(core_if)) {
  56296. + init_fslspclksel(core_if);
  56297. + } else {
  56298. + init_devspd(core_if);
  56299. + }
  56300. +
  56301. + if (core_if->core_params->i2c_enable) {
  56302. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  56303. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  56304. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56305. + usbcfg.b.otgutmifssel = 1;
  56306. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56307. +
  56308. + /* Program GI2CCTL.I2CEn */
  56309. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  56310. + i2cctl.b.i2cdevaddr = 1;
  56311. + i2cctl.b.i2cen = 0;
  56312. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56313. + i2cctl.b.i2cen = 1;
  56314. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56315. + }
  56316. +
  56317. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  56318. + else {
  56319. + /* High speed PHY. */
  56320. + if (!core_if->phy_init_done) {
  56321. + core_if->phy_init_done = 1;
  56322. + /* HS PHY parameters. These parameters are preserved
  56323. + * during soft reset so only program the first time. Do
  56324. + * a soft reset immediately after setting phyif. */
  56325. +
  56326. + if (core_if->core_params->phy_type == 2) {
  56327. + /* ULPI interface */
  56328. + usbcfg.b.ulpi_utmi_sel = 1;
  56329. + usbcfg.b.phyif = 0;
  56330. + usbcfg.b.ddrsel =
  56331. + core_if->core_params->phy_ulpi_ddr;
  56332. + } else if (core_if->core_params->phy_type == 1) {
  56333. + /* UTMI+ interface */
  56334. + usbcfg.b.ulpi_utmi_sel = 0;
  56335. + if (core_if->core_params->phy_utmi_width == 16) {
  56336. + usbcfg.b.phyif = 1;
  56337. +
  56338. + } else {
  56339. + usbcfg.b.phyif = 0;
  56340. + }
  56341. + } else {
  56342. + DWC_ERROR("FS PHY TYPE\n");
  56343. + }
  56344. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56345. + /* Reset after setting the PHY parameters */
  56346. + dwc_otg_core_reset(core_if);
  56347. + }
  56348. + }
  56349. +
  56350. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56351. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56352. + (core_if->core_params->ulpi_fs_ls)) {
  56353. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  56354. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56355. + usbcfg.b.ulpi_fsls = 1;
  56356. + usbcfg.b.ulpi_clk_sus_m = 1;
  56357. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56358. + } else {
  56359. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56360. + usbcfg.b.ulpi_fsls = 0;
  56361. + usbcfg.b.ulpi_clk_sus_m = 0;
  56362. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56363. + }
  56364. +
  56365. + /* Program the GAHBCFG Register. */
  56366. + switch (core_if->hwcfg2.b.architecture) {
  56367. +
  56368. + case DWC_SLAVE_ONLY_ARCH:
  56369. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  56370. + ahbcfg.b.nptxfemplvl_txfemplvl =
  56371. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56372. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56373. + core_if->dma_enable = 0;
  56374. + core_if->dma_desc_enable = 0;
  56375. + break;
  56376. +
  56377. + case DWC_EXT_DMA_ARCH:
  56378. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  56379. + {
  56380. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  56381. + ahbcfg.b.hburstlen = 0;
  56382. + while (brst_sz > 1) {
  56383. + ahbcfg.b.hburstlen++;
  56384. + brst_sz >>= 1;
  56385. + }
  56386. + }
  56387. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56388. + core_if->dma_desc_enable =
  56389. + (core_if->core_params->dma_desc_enable != 0);
  56390. + break;
  56391. +
  56392. + case DWC_INT_DMA_ARCH:
  56393. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  56394. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  56395. + Host mode ISOC in issue fix - vahrama */
  56396. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  56397. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  56398. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56399. + core_if->dma_desc_enable =
  56400. + (core_if->core_params->dma_desc_enable != 0);
  56401. + break;
  56402. +
  56403. + }
  56404. + if (core_if->dma_enable) {
  56405. + if (core_if->dma_desc_enable) {
  56406. + DWC_PRINTF("Using Descriptor DMA mode\n");
  56407. + } else {
  56408. + DWC_PRINTF("Using Buffer DMA mode\n");
  56409. +
  56410. + }
  56411. + } else {
  56412. + DWC_PRINTF("Using Slave mode\n");
  56413. + core_if->dma_desc_enable = 0;
  56414. + }
  56415. +
  56416. + if (core_if->core_params->ahb_single) {
  56417. + ahbcfg.b.ahbsingle = 1;
  56418. + }
  56419. +
  56420. + ahbcfg.b.dmaenable = core_if->dma_enable;
  56421. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  56422. +
  56423. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  56424. +
  56425. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  56426. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  56427. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  56428. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  56429. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  56430. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  56431. +
  56432. + /*
  56433. + * Program the GUSBCFG register.
  56434. + */
  56435. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56436. +
  56437. + switch (core_if->hwcfg2.b.op_mode) {
  56438. + case DWC_MODE_HNP_SRP_CAPABLE:
  56439. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  56440. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  56441. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56442. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56443. + break;
  56444. +
  56445. + case DWC_MODE_SRP_ONLY_CAPABLE:
  56446. + usbcfg.b.hnpcap = 0;
  56447. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56448. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56449. + break;
  56450. +
  56451. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  56452. + usbcfg.b.hnpcap = 0;
  56453. + usbcfg.b.srpcap = 0;
  56454. + break;
  56455. +
  56456. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  56457. + usbcfg.b.hnpcap = 0;
  56458. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56459. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56460. + break;
  56461. +
  56462. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  56463. + usbcfg.b.hnpcap = 0;
  56464. + usbcfg.b.srpcap = 0;
  56465. + break;
  56466. +
  56467. + case DWC_MODE_SRP_CAPABLE_HOST:
  56468. + usbcfg.b.hnpcap = 0;
  56469. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56470. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56471. + break;
  56472. +
  56473. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  56474. + usbcfg.b.hnpcap = 0;
  56475. + usbcfg.b.srpcap = 0;
  56476. + break;
  56477. + }
  56478. +
  56479. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56480. +
  56481. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56482. + if (core_if->core_params->lpm_enable) {
  56483. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  56484. +
  56485. + /* To enable LPM support set lpm_cap_en bit */
  56486. + lpmcfg.b.lpm_cap_en = 1;
  56487. +
  56488. + /* Make AppL1Res ACK */
  56489. + lpmcfg.b.appl_resp = 1;
  56490. +
  56491. + /* Retry 3 times */
  56492. + lpmcfg.b.retry_count = 3;
  56493. +
  56494. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  56495. + 0, lpmcfg.d32);
  56496. +
  56497. + }
  56498. +#endif
  56499. + if (core_if->core_params->ic_usb_cap) {
  56500. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56501. + gusbcfg.b.ic_usb_cap = 1;
  56502. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  56503. + 0, gusbcfg.d32);
  56504. + }
  56505. + {
  56506. + gotgctl_data_t gotgctl = {.d32 = 0 };
  56507. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  56508. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  56509. + gotgctl.d32);
  56510. + /* Set OTG version supported */
  56511. + core_if->otg_ver = core_if->core_params->otg_ver;
  56512. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  56513. + core_if->core_params->otg_ver, core_if->otg_ver);
  56514. + }
  56515. +
  56516. +
  56517. + /* Enable common interrupts */
  56518. + dwc_otg_enable_common_interrupts(core_if);
  56519. +
  56520. + /* Do device or host intialization based on mode during PCD
  56521. + * and HCD initialization */
  56522. + if (dwc_otg_is_host_mode(core_if)) {
  56523. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  56524. + core_if->op_state = A_HOST;
  56525. + } else {
  56526. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  56527. + core_if->op_state = B_PERIPHERAL;
  56528. +#ifdef DWC_DEVICE_ONLY
  56529. + dwc_otg_core_dev_init(core_if);
  56530. +#endif
  56531. + }
  56532. +}
  56533. +
  56534. +/**
  56535. + * This function enables the Device mode interrupts.
  56536. + *
  56537. + * @param core_if Programming view of DWC_otg controller
  56538. + */
  56539. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  56540. +{
  56541. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56542. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56543. +
  56544. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  56545. +
  56546. + /* Disable all interrupts. */
  56547. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56548. +
  56549. + /* Clear any pending interrupts */
  56550. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56551. +
  56552. + /* Enable the common interrupts */
  56553. + dwc_otg_enable_common_interrupts(core_if);
  56554. +
  56555. + /* Enable interrupts */
  56556. + intr_mask.b.usbreset = 1;
  56557. + intr_mask.b.enumdone = 1;
  56558. + /* Disable Disconnect interrupt in Device mode */
  56559. + intr_mask.b.disconnect = 0;
  56560. +
  56561. + if (!core_if->multiproc_int_enable) {
  56562. + intr_mask.b.inepintr = 1;
  56563. + intr_mask.b.outepintr = 1;
  56564. + }
  56565. +
  56566. + intr_mask.b.erlysuspend = 1;
  56567. +
  56568. + if (core_if->en_multiple_tx_fifo == 0) {
  56569. + intr_mask.b.epmismatch = 1;
  56570. + }
  56571. +
  56572. + //intr_mask.b.incomplisoout = 1;
  56573. + intr_mask.b.incomplisoin = 1;
  56574. +
  56575. +/* Enable the ignore frame number for ISOC xfers - MAS */
  56576. +/* Disable to support high bandwith ISOC transfers - manukz */
  56577. +#if 0
  56578. +#ifdef DWC_UTE_PER_IO
  56579. + if (core_if->dma_enable) {
  56580. + if (core_if->dma_desc_enable) {
  56581. + dctl_data_t dctl1 = {.d32 = 0 };
  56582. + dctl1.b.ifrmnum = 1;
  56583. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  56584. + dctl, 0, dctl1.d32);
  56585. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  56586. + DWC_READ_REG32(&core_if->dev_if->
  56587. + dev_global_regs->dctl));
  56588. + }
  56589. + }
  56590. +#endif
  56591. +#endif
  56592. +#ifdef DWC_EN_ISOC
  56593. + if (core_if->dma_enable) {
  56594. + if (core_if->dma_desc_enable == 0) {
  56595. + if (core_if->pti_enh_enable) {
  56596. + dctl_data_t dctl = {.d32 = 0 };
  56597. + dctl.b.ifrmnum = 1;
  56598. + DWC_MODIFY_REG32(&core_if->
  56599. + dev_if->dev_global_regs->dctl,
  56600. + 0, dctl.d32);
  56601. + } else {
  56602. + intr_mask.b.incomplisoin = 1;
  56603. + intr_mask.b.incomplisoout = 1;
  56604. + }
  56605. + }
  56606. + } else {
  56607. + intr_mask.b.incomplisoin = 1;
  56608. + intr_mask.b.incomplisoout = 1;
  56609. + }
  56610. +#endif /* DWC_EN_ISOC */
  56611. +
  56612. + /** @todo NGS: Should this be a module parameter? */
  56613. +#ifdef USE_PERIODIC_EP
  56614. + intr_mask.b.isooutdrop = 1;
  56615. + intr_mask.b.eopframe = 1;
  56616. + intr_mask.b.incomplisoin = 1;
  56617. + intr_mask.b.incomplisoout = 1;
  56618. +#endif
  56619. +
  56620. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  56621. +
  56622. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  56623. + DWC_READ_REG32(&global_regs->gintmsk));
  56624. +}
  56625. +
  56626. +/**
  56627. + * This function initializes the DWC_otg controller registers for
  56628. + * device mode.
  56629. + *
  56630. + * @param core_if Programming view of DWC_otg controller
  56631. + *
  56632. + */
  56633. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  56634. +{
  56635. + int i;
  56636. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56637. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56638. + dwc_otg_core_params_t *params = core_if->core_params;
  56639. + dcfg_data_t dcfg = {.d32 = 0 };
  56640. + depctl_data_t diepctl = {.d32 = 0 };
  56641. + grstctl_t resetctl = {.d32 = 0 };
  56642. + uint32_t rx_fifo_size;
  56643. + fifosize_data_t nptxfifosize;
  56644. + fifosize_data_t txfifosize;
  56645. + dthrctl_data_t dthrctl;
  56646. + fifosize_data_t ptxfifosize;
  56647. + uint16_t rxfsiz, nptxfsiz;
  56648. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  56649. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  56650. +
  56651. + /* Restart the Phy Clock */
  56652. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  56653. +
  56654. + /* Device configuration register */
  56655. + init_devspd(core_if);
  56656. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56657. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  56658. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  56659. + /* Enable Device OUT NAK in case of DDMA mode*/
  56660. + if (core_if->core_params->dev_out_nak) {
  56661. + dcfg.b.endevoutnak = 1;
  56662. + }
  56663. +
  56664. + if (core_if->core_params->cont_on_bna) {
  56665. + dctl_data_t dctl = {.d32 = 0 };
  56666. + dctl.b.encontonbna = 1;
  56667. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56668. + }
  56669. +
  56670. +
  56671. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56672. +
  56673. + /* Configure data FIFO sizes */
  56674. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  56675. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  56676. + core_if->total_fifo_size);
  56677. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  56678. + params->dev_rx_fifo_size);
  56679. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  56680. + params->dev_nperio_tx_fifo_size);
  56681. +
  56682. + /* Rx FIFO */
  56683. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  56684. + DWC_READ_REG32(&global_regs->grxfsiz));
  56685. +
  56686. +#ifdef DWC_UTE_CFI
  56687. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  56688. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  56689. +#endif
  56690. + rx_fifo_size = params->dev_rx_fifo_size;
  56691. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  56692. +
  56693. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  56694. + DWC_READ_REG32(&global_regs->grxfsiz));
  56695. +
  56696. + /** Set Periodic Tx FIFO Mask all bits 0 */
  56697. + core_if->p_tx_msk = 0;
  56698. +
  56699. + /** Set Tx FIFO Mask all bits 0 */
  56700. + core_if->tx_msk = 0;
  56701. +
  56702. + if (core_if->en_multiple_tx_fifo == 0) {
  56703. + /* Non-periodic Tx FIFO */
  56704. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56705. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56706. +
  56707. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56708. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56709. +
  56710. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56711. + nptxfifosize.d32);
  56712. +
  56713. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56714. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56715. +
  56716. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  56717. + /*
  56718. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  56719. + * Indexes of the FIFO size module parameters in the
  56720. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  56721. + * the dptxfsiz array run from 0 to 14.
  56722. + */
  56723. + /** @todo Finish debug of this */
  56724. + ptxfifosize.b.startaddr =
  56725. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56726. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56727. + ptxfifosize.b.depth =
  56728. + params->dev_perio_tx_fifo_size[i];
  56729. + DWC_DEBUGPL(DBG_CIL,
  56730. + "initial dtxfsiz[%d]=%08x\n", i,
  56731. + DWC_READ_REG32(&global_regs->dtxfsiz
  56732. + [i]));
  56733. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56734. + ptxfifosize.d32);
  56735. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  56736. + i,
  56737. + DWC_READ_REG32(&global_regs->dtxfsiz
  56738. + [i]));
  56739. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  56740. + }
  56741. + } else {
  56742. + /*
  56743. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  56744. + * Indexes of the FIFO size module parameters in the
  56745. + * dev_tx_fifo_size array and the FIFO size registers in
  56746. + * the dtxfsiz array run from 0 to 14.
  56747. + */
  56748. +
  56749. + /* Non-periodic Tx FIFO */
  56750. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56751. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56752. +
  56753. +#ifdef DWC_UTE_CFI
  56754. + core_if->pwron_gnptxfsiz =
  56755. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56756. + core_if->init_gnptxfsiz =
  56757. + params->dev_nperio_tx_fifo_size;
  56758. +#endif
  56759. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56760. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56761. +
  56762. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56763. + nptxfifosize.d32);
  56764. +
  56765. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56766. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56767. +
  56768. + txfifosize.b.startaddr =
  56769. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56770. +
  56771. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56772. +
  56773. + txfifosize.b.depth =
  56774. + params->dev_tx_fifo_size[i];
  56775. +
  56776. + DWC_DEBUGPL(DBG_CIL,
  56777. + "initial dtxfsiz[%d]=%08x\n",
  56778. + i,
  56779. + DWC_READ_REG32(&global_regs->dtxfsiz
  56780. + [i]));
  56781. +
  56782. +#ifdef DWC_UTE_CFI
  56783. + core_if->pwron_txfsiz[i] =
  56784. + (DWC_READ_REG32
  56785. + (&global_regs->dtxfsiz[i]) >> 16);
  56786. + core_if->init_txfsiz[i] =
  56787. + params->dev_tx_fifo_size[i];
  56788. +#endif
  56789. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56790. + txfifosize.d32);
  56791. +
  56792. + DWC_DEBUGPL(DBG_CIL,
  56793. + "new dtxfsiz[%d]=%08x\n",
  56794. + i,
  56795. + DWC_READ_REG32(&global_regs->dtxfsiz
  56796. + [i]));
  56797. +
  56798. + txfifosize.b.startaddr += txfifosize.b.depth;
  56799. + }
  56800. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  56801. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  56802. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  56803. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  56804. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  56805. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56806. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  56807. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56808. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  56809. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56810. + }
  56811. + }
  56812. +
  56813. + /* Flush the FIFOs */
  56814. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  56815. + dwc_otg_flush_rx_fifo(core_if);
  56816. +
  56817. + /* Flush the Learning Queue. */
  56818. + resetctl.b.intknqflsh = 1;
  56819. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  56820. +
  56821. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  56822. + core_if->start_predict = 0;
  56823. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  56824. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  56825. + }
  56826. + core_if->nextep_seq[0] = 0;
  56827. + core_if->first_in_nextep_seq = 0;
  56828. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  56829. + diepctl.b.nextep = 0;
  56830. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  56831. +
  56832. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  56833. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56834. + dcfg.b.epmscnt = 2;
  56835. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56836. +
  56837. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  56838. + __func__, core_if->first_in_nextep_seq);
  56839. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  56840. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  56841. + }
  56842. + DWC_DEBUGPL(DBG_CILV,"\n");
  56843. + }
  56844. +
  56845. + /* Clear all pending Device Interrupts */
  56846. + /** @todo - if the condition needed to be checked
  56847. + * or in any case all pending interrutps should be cleared?
  56848. + */
  56849. + if (core_if->multiproc_int_enable) {
  56850. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56851. + DWC_WRITE_REG32(&dev_if->
  56852. + dev_global_regs->diepeachintmsk[i], 0);
  56853. + }
  56854. + }
  56855. +
  56856. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  56857. + DWC_WRITE_REG32(&dev_if->
  56858. + dev_global_regs->doepeachintmsk[i], 0);
  56859. + }
  56860. +
  56861. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  56862. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  56863. + } else {
  56864. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  56865. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  56866. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  56867. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  56868. + }
  56869. +
  56870. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  56871. + depctl_data_t depctl;
  56872. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  56873. + if (depctl.b.epena) {
  56874. + depctl.d32 = 0;
  56875. + depctl.b.epdis = 1;
  56876. + depctl.b.snak = 1;
  56877. + } else {
  56878. + depctl.d32 = 0;
  56879. + }
  56880. +
  56881. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  56882. +
  56883. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  56884. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  56885. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  56886. + }
  56887. +
  56888. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  56889. + depctl_data_t depctl;
  56890. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  56891. + if (depctl.b.epena) {
  56892. + dctl_data_t dctl = {.d32 = 0 };
  56893. + gintmsk_data_t gintsts = {.d32 = 0 };
  56894. + doepint_data_t doepint = {.d32 = 0 };
  56895. + dctl.b.sgoutnak = 1;
  56896. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56897. + do {
  56898. + dwc_udelay(10);
  56899. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56900. + } while (!gintsts.b.goutnakeff);
  56901. + gintsts.d32 = 0;
  56902. + gintsts.b.goutnakeff = 1;
  56903. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56904. +
  56905. + depctl.d32 = 0;
  56906. + depctl.b.epdis = 1;
  56907. + depctl.b.snak = 1;
  56908. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56909. + do {
  56910. + dwc_udelay(10);
  56911. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  56912. + out_ep_regs[i]->doepint);
  56913. + } while (!doepint.b.epdisabled);
  56914. +
  56915. + doepint.b.epdisabled = 1;
  56916. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  56917. +
  56918. + dctl.d32 = 0;
  56919. + dctl.b.cgoutnak = 1;
  56920. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56921. + } else {
  56922. + depctl.d32 = 0;
  56923. + }
  56924. +
  56925. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56926. +
  56927. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  56928. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  56929. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  56930. + }
  56931. +
  56932. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  56933. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  56934. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  56935. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  56936. +
  56937. + dev_if->rx_thr_length = params->rx_thr_length;
  56938. + dev_if->tx_thr_length = params->tx_thr_length;
  56939. +
  56940. + dev_if->setup_desc_index = 0;
  56941. +
  56942. + dthrctl.d32 = 0;
  56943. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  56944. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  56945. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  56946. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  56947. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  56948. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  56949. +
  56950. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  56951. + dthrctl.d32);
  56952. +
  56953. + DWC_DEBUGPL(DBG_CIL,
  56954. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  56955. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  56956. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  56957. + dthrctl.b.rx_thr_len);
  56958. +
  56959. + }
  56960. +
  56961. + dwc_otg_enable_device_interrupts(core_if);
  56962. +
  56963. + {
  56964. + diepmsk_data_t msk = {.d32 = 0 };
  56965. + msk.b.txfifoundrn = 1;
  56966. + if (core_if->multiproc_int_enable) {
  56967. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  56968. + diepeachintmsk[0], msk.d32, msk.d32);
  56969. + } else {
  56970. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  56971. + msk.d32, msk.d32);
  56972. + }
  56973. + }
  56974. +
  56975. + if (core_if->multiproc_int_enable) {
  56976. + /* Set NAK on Babble */
  56977. + dctl_data_t dctl = {.d32 = 0 };
  56978. + dctl.b.nakonbble = 1;
  56979. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56980. + }
  56981. +
  56982. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  56983. + dctl_data_t dctl = {.d32 = 0 };
  56984. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  56985. + dctl.b.sftdiscon = 0;
  56986. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  56987. + }
  56988. +}
  56989. +
  56990. +/**
  56991. + * This function enables the Host mode interrupts.
  56992. + *
  56993. + * @param core_if Programming view of DWC_otg controller
  56994. + */
  56995. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  56996. +{
  56997. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56998. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56999. +
  57000. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  57001. +
  57002. + /* Disable all interrupts. */
  57003. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57004. +
  57005. + /* Clear any pending interrupts. */
  57006. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57007. +
  57008. + /* Enable the common interrupts */
  57009. + dwc_otg_enable_common_interrupts(core_if);
  57010. +
  57011. + /*
  57012. + * Enable host mode interrupts without disturbing common
  57013. + * interrupts.
  57014. + */
  57015. +
  57016. + intr_mask.b.disconnect = 1;
  57017. + intr_mask.b.portintr = 1;
  57018. + intr_mask.b.hcintr = 1;
  57019. +
  57020. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57021. +}
  57022. +
  57023. +/**
  57024. + * This function disables the Host Mode interrupts.
  57025. + *
  57026. + * @param core_if Programming view of DWC_otg controller
  57027. + */
  57028. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  57029. +{
  57030. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57031. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57032. +
  57033. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  57034. +
  57035. + /*
  57036. + * Disable host mode interrupts without disturbing common
  57037. + * interrupts.
  57038. + */
  57039. + intr_mask.b.sofintr = 1;
  57040. + intr_mask.b.portintr = 1;
  57041. + intr_mask.b.hcintr = 1;
  57042. + intr_mask.b.ptxfempty = 1;
  57043. + intr_mask.b.nptxfempty = 1;
  57044. +
  57045. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  57046. +}
  57047. +
  57048. +/**
  57049. + * This function initializes the DWC_otg controller registers for
  57050. + * host mode.
  57051. + *
  57052. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  57053. + * request queues. Host channels are reset to ensure that they are ready for
  57054. + * performing transfers.
  57055. + *
  57056. + * @param core_if Programming view of DWC_otg controller
  57057. + *
  57058. + */
  57059. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  57060. +{
  57061. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57062. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57063. + dwc_otg_core_params_t *params = core_if->core_params;
  57064. + hprt0_data_t hprt0 = {.d32 = 0 };
  57065. + fifosize_data_t nptxfifosize;
  57066. + fifosize_data_t ptxfifosize;
  57067. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  57068. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57069. + int i;
  57070. + hcchar_data_t hcchar;
  57071. + hcfg_data_t hcfg;
  57072. + hfir_data_t hfir;
  57073. + dwc_otg_hc_regs_t *hc_regs;
  57074. + int num_channels;
  57075. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57076. +
  57077. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  57078. +
  57079. + /* Restart the Phy Clock */
  57080. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57081. +
  57082. + /* Initialize Host Configuration Register */
  57083. + init_fslspclksel(core_if);
  57084. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57085. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57086. + hcfg.b.fslssupp = 1;
  57087. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57088. +
  57089. + }
  57090. +
  57091. + /* This bit allows dynamic reloading of the HFIR register
  57092. + * during runtime. This bit needs to be programmed during
  57093. + * initial configuration and its value must not be changed
  57094. + * during runtime.*/
  57095. + if (core_if->core_params->reload_ctl == 1) {
  57096. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  57097. + hfir.b.hfirrldctrl = 1;
  57098. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  57099. + }
  57100. +
  57101. + if (core_if->core_params->dma_desc_enable) {
  57102. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  57103. + if (!
  57104. + (core_if->hwcfg4.b.desc_dma
  57105. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  57106. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  57107. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  57108. + || (op_mode ==
  57109. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  57110. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  57111. + || (op_mode ==
  57112. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  57113. +
  57114. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  57115. + "Either core version is below 2.90a or "
  57116. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  57117. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  57118. + "module parameter to 0.\n");
  57119. + return;
  57120. + }
  57121. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57122. + hcfg.b.descdma = 1;
  57123. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57124. + }
  57125. +
  57126. + /* Configure data FIFO sizes */
  57127. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57128. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57129. + core_if->total_fifo_size);
  57130. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57131. + params->host_rx_fifo_size);
  57132. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57133. + params->host_nperio_tx_fifo_size);
  57134. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  57135. + params->host_perio_tx_fifo_size);
  57136. +
  57137. + /* Rx FIFO */
  57138. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57139. + DWC_READ_REG32(&global_regs->grxfsiz));
  57140. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  57141. + params->host_rx_fifo_size);
  57142. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57143. + DWC_READ_REG32(&global_regs->grxfsiz));
  57144. +
  57145. + /* Non-periodic Tx FIFO */
  57146. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57147. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57148. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  57149. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  57150. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  57151. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57152. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57153. +
  57154. + /* Periodic Tx FIFO */
  57155. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  57156. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57157. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  57158. + ptxfifosize.b.startaddr =
  57159. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57160. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  57161. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  57162. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57163. +
  57164. + if (core_if->en_multiple_tx_fifo
  57165. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57166. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  57167. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57168. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57169. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57170. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  57171. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  57172. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57173. + }
  57174. + }
  57175. +
  57176. + /* TODO - check this */
  57177. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57178. + gotgctl.b.hstsethnpen = 1;
  57179. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57180. + /* Make sure the FIFOs are flushed. */
  57181. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  57182. + dwc_otg_flush_rx_fifo(core_if);
  57183. +
  57184. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57185. + gotgctl.b.hstsethnpen = 1;
  57186. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57187. +
  57188. + if (!core_if->core_params->dma_desc_enable) {
  57189. + /* Flush out any leftover queued requests. */
  57190. + num_channels = core_if->core_params->host_channels;
  57191. +
  57192. + for (i = 0; i < num_channels; i++) {
  57193. + hc_regs = core_if->host_if->hc_regs[i];
  57194. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57195. + hcchar.b.chen = 0;
  57196. + hcchar.b.chdis = 1;
  57197. + hcchar.b.epdir = 0;
  57198. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57199. + }
  57200. +
  57201. + /* Halt all channels to put them into a known state. */
  57202. + for (i = 0; i < num_channels; i++) {
  57203. + int count = 0;
  57204. + hc_regs = core_if->host_if->hc_regs[i];
  57205. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57206. + hcchar.b.chen = 1;
  57207. + hcchar.b.chdis = 1;
  57208. + hcchar.b.epdir = 0;
  57209. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57210. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  57211. + do {
  57212. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57213. + if (++count > 1000) {
  57214. + DWC_ERROR
  57215. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  57216. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  57217. + break;
  57218. + }
  57219. + dwc_udelay(1);
  57220. + } while (hcchar.b.chen);
  57221. + }
  57222. + }
  57223. +
  57224. + /* Turn on the vbus power. */
  57225. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  57226. + if (core_if->op_state == A_HOST) {
  57227. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  57228. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  57229. + if (hprt0.b.prtpwr == 0) {
  57230. + hprt0.b.prtpwr = 1;
  57231. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  57232. + }
  57233. + }
  57234. +
  57235. + dwc_otg_enable_host_interrupts(core_if);
  57236. +}
  57237. +
  57238. +/**
  57239. + * Prepares a host channel for transferring packets to/from a specific
  57240. + * endpoint. The HCCHARn register is set up with the characteristics specified
  57241. + * in _hc. Host channel interrupts that may need to be serviced while this
  57242. + * transfer is in progress are enabled.
  57243. + *
  57244. + * @param core_if Programming view of DWC_otg controller
  57245. + * @param hc Information needed to initialize the host channel
  57246. + */
  57247. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57248. +{
  57249. + uint32_t intr_enable;
  57250. + hcintmsk_data_t hc_intr_mask;
  57251. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57252. + hcchar_data_t hcchar;
  57253. + hcsplt_data_t hcsplt;
  57254. +
  57255. + uint8_t hc_num = hc->hc_num;
  57256. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57257. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  57258. +
  57259. + /* Clear old interrupt conditions for this host channel. */
  57260. + hc_intr_mask.d32 = 0xFFFFFFFF;
  57261. + hc_intr_mask.b.reserved14_31 = 0;
  57262. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  57263. +
  57264. + /* Enable channel interrupts required for this transfer. */
  57265. + hc_intr_mask.d32 = 0;
  57266. + hc_intr_mask.b.chhltd = 1;
  57267. + if (core_if->dma_enable) {
  57268. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  57269. + if (!core_if->dma_desc_enable)
  57270. + hc_intr_mask.b.ahberr = 1;
  57271. + else {
  57272. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57273. + hc_intr_mask.b.xfercompl = 1;
  57274. + }
  57275. +
  57276. + if (hc->error_state && !hc->do_split &&
  57277. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  57278. + hc_intr_mask.b.ack = 1;
  57279. + if (hc->ep_is_in) {
  57280. + hc_intr_mask.b.datatglerr = 1;
  57281. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57282. + hc_intr_mask.b.nak = 1;
  57283. + }
  57284. + }
  57285. + }
  57286. + } else {
  57287. + switch (hc->ep_type) {
  57288. + case DWC_OTG_EP_TYPE_CONTROL:
  57289. + case DWC_OTG_EP_TYPE_BULK:
  57290. + hc_intr_mask.b.xfercompl = 1;
  57291. + hc_intr_mask.b.stall = 1;
  57292. + hc_intr_mask.b.xacterr = 1;
  57293. + hc_intr_mask.b.datatglerr = 1;
  57294. + if (hc->ep_is_in) {
  57295. + hc_intr_mask.b.bblerr = 1;
  57296. + } else {
  57297. + hc_intr_mask.b.nak = 1;
  57298. + hc_intr_mask.b.nyet = 1;
  57299. + if (hc->do_ping) {
  57300. + hc_intr_mask.b.ack = 1;
  57301. + }
  57302. + }
  57303. +
  57304. + if (hc->do_split) {
  57305. + hc_intr_mask.b.nak = 1;
  57306. + if (hc->complete_split) {
  57307. + hc_intr_mask.b.nyet = 1;
  57308. + } else {
  57309. + hc_intr_mask.b.ack = 1;
  57310. + }
  57311. + }
  57312. +
  57313. + if (hc->error_state) {
  57314. + hc_intr_mask.b.ack = 1;
  57315. + }
  57316. + break;
  57317. + case DWC_OTG_EP_TYPE_INTR:
  57318. + hc_intr_mask.b.xfercompl = 1;
  57319. + hc_intr_mask.b.nak = 1;
  57320. + hc_intr_mask.b.stall = 1;
  57321. + hc_intr_mask.b.xacterr = 1;
  57322. + hc_intr_mask.b.datatglerr = 1;
  57323. + hc_intr_mask.b.frmovrun = 1;
  57324. +
  57325. + if (hc->ep_is_in) {
  57326. + hc_intr_mask.b.bblerr = 1;
  57327. + }
  57328. + if (hc->error_state) {
  57329. + hc_intr_mask.b.ack = 1;
  57330. + }
  57331. + if (hc->do_split) {
  57332. + if (hc->complete_split) {
  57333. + hc_intr_mask.b.nyet = 1;
  57334. + } else {
  57335. + hc_intr_mask.b.ack = 1;
  57336. + }
  57337. + }
  57338. + break;
  57339. + case DWC_OTG_EP_TYPE_ISOC:
  57340. + hc_intr_mask.b.xfercompl = 1;
  57341. + hc_intr_mask.b.frmovrun = 1;
  57342. + hc_intr_mask.b.ack = 1;
  57343. +
  57344. + if (hc->ep_is_in) {
  57345. + hc_intr_mask.b.xacterr = 1;
  57346. + hc_intr_mask.b.bblerr = 1;
  57347. + }
  57348. + break;
  57349. + }
  57350. + }
  57351. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  57352. +
  57353. + /* Enable the top level host channel interrupt. */
  57354. + intr_enable = (1 << hc_num);
  57355. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  57356. +
  57357. + /* Make sure host channel interrupts are enabled. */
  57358. + gintmsk.b.hcintr = 1;
  57359. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  57360. +
  57361. + /*
  57362. + * Program the HCCHARn register with the endpoint characteristics for
  57363. + * the current transfer.
  57364. + */
  57365. + hcchar.d32 = 0;
  57366. + hcchar.b.devaddr = hc->dev_addr;
  57367. + hcchar.b.epnum = hc->ep_num;
  57368. + hcchar.b.epdir = hc->ep_is_in;
  57369. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  57370. + hcchar.b.eptype = hc->ep_type;
  57371. + hcchar.b.mps = hc->max_packet;
  57372. +
  57373. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  57374. +
  57375. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  57376. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  57377. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  57378. + "Max Pkt %d, Multi Cnt %d\n",
  57379. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  57380. + hcchar.b.mps, hcchar.b.multicnt);
  57381. +
  57382. + /*
  57383. + * Program the HCSPLIT register for SPLITs
  57384. + */
  57385. + hcsplt.d32 = 0;
  57386. + if (hc->do_split) {
  57387. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  57388. + hc->hc_num,
  57389. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  57390. + hcsplt.b.compsplt = hc->complete_split;
  57391. + hcsplt.b.xactpos = hc->xact_pos;
  57392. + hcsplt.b.hubaddr = hc->hub_addr;
  57393. + hcsplt.b.prtaddr = hc->port_addr;
  57394. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  57395. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  57396. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  57397. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  57398. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  57399. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  57400. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  57401. + }
  57402. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  57403. +
  57404. +}
  57405. +
  57406. +/**
  57407. + * Attempts to halt a host channel. This function should only be called in
  57408. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  57409. + * normal circumstances in DMA mode, the controller halts the channel when the
  57410. + * transfer is complete or a condition occurs that requires application
  57411. + * intervention.
  57412. + *
  57413. + * In slave mode, checks for a free request queue entry, then sets the Channel
  57414. + * Enable and Channel Disable bits of the Host Channel Characteristics
  57415. + * register of the specified channel to intiate the halt. If there is no free
  57416. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  57417. + * register to flush requests for this channel. In the latter case, sets a
  57418. + * flag to indicate that the host channel needs to be halted when a request
  57419. + * queue slot is open.
  57420. + *
  57421. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  57422. + * HCCHARn register. The controller ensures there is space in the request
  57423. + * queue before submitting the halt request.
  57424. + *
  57425. + * Some time may elapse before the core flushes any posted requests for this
  57426. + * host channel and halts. The Channel Halted interrupt handler completes the
  57427. + * deactivation of the host channel.
  57428. + *
  57429. + * @param core_if Controller register interface.
  57430. + * @param hc Host channel to halt.
  57431. + * @param halt_status Reason for halting the channel.
  57432. + */
  57433. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  57434. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  57435. +{
  57436. + gnptxsts_data_t nptxsts;
  57437. + hptxsts_data_t hptxsts;
  57438. + hcchar_data_t hcchar;
  57439. + dwc_otg_hc_regs_t *hc_regs;
  57440. + dwc_otg_core_global_regs_t *global_regs;
  57441. + dwc_otg_host_global_regs_t *host_global_regs;
  57442. +
  57443. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57444. + global_regs = core_if->core_global_regs;
  57445. + host_global_regs = core_if->host_if->host_global_regs;
  57446. +
  57447. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  57448. + "halt_status = %d\n", halt_status);
  57449. +
  57450. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  57451. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  57452. + /*
  57453. + * Disable all channel interrupts except Ch Halted. The QTD
  57454. + * and QH state associated with this transfer has been cleared
  57455. + * (in the case of URB_DEQUEUE), so the channel needs to be
  57456. + * shut down carefully to prevent crashes.
  57457. + */
  57458. + hcintmsk_data_t hcintmsk;
  57459. + hcintmsk.d32 = 0;
  57460. + hcintmsk.b.chhltd = 1;
  57461. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  57462. +
  57463. + /*
  57464. + * Make sure no other interrupts besides halt are currently
  57465. + * pending. Handling another interrupt could cause a crash due
  57466. + * to the QTD and QH state.
  57467. + */
  57468. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  57469. +
  57470. + /*
  57471. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  57472. + * even if the channel was already halted for some other
  57473. + * reason.
  57474. + */
  57475. + hc->halt_status = halt_status;
  57476. +
  57477. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57478. + if (hcchar.b.chen == 0) {
  57479. + /*
  57480. + * The channel is either already halted or it hasn't
  57481. + * started yet. In DMA mode, the transfer may halt if
  57482. + * it finishes normally or a condition occurs that
  57483. + * requires driver intervention. Don't want to halt
  57484. + * the channel again. In either Slave or DMA mode,
  57485. + * it's possible that the transfer has been assigned
  57486. + * to a channel, but not started yet when an URB is
  57487. + * dequeued. Don't want to halt a channel that hasn't
  57488. + * started yet.
  57489. + */
  57490. + return;
  57491. + }
  57492. + }
  57493. + if (hc->halt_pending) {
  57494. + /*
  57495. + * A halt has already been issued for this channel. This might
  57496. + * happen when a transfer is aborted by a higher level in
  57497. + * the stack.
  57498. + */
  57499. +#ifdef DEBUG
  57500. + DWC_PRINTF
  57501. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  57502. + __func__, hc->hc_num);
  57503. +
  57504. +#endif
  57505. + return;
  57506. + }
  57507. +
  57508. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57509. +
  57510. + /* No need to set the bit in DDMA for disabling the channel */
  57511. + //TODO check it everywhere channel is disabled
  57512. + if (!core_if->core_params->dma_desc_enable)
  57513. + hcchar.b.chen = 1;
  57514. + hcchar.b.chdis = 1;
  57515. +
  57516. + if (!core_if->dma_enable) {
  57517. + /* Check for space in the request queue to issue the halt. */
  57518. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  57519. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  57520. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  57521. + if (nptxsts.b.nptxqspcavail == 0) {
  57522. + hcchar.b.chen = 0;
  57523. + }
  57524. + } else {
  57525. + hptxsts.d32 =
  57526. + DWC_READ_REG32(&host_global_regs->hptxsts);
  57527. + if ((hptxsts.b.ptxqspcavail == 0)
  57528. + || (core_if->queuing_high_bandwidth)) {
  57529. + hcchar.b.chen = 0;
  57530. + }
  57531. + }
  57532. + }
  57533. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57534. +
  57535. + hc->halt_status = halt_status;
  57536. +
  57537. + if (hcchar.b.chen) {
  57538. + hc->halt_pending = 1;
  57539. + hc->halt_on_queue = 0;
  57540. + } else {
  57541. + hc->halt_on_queue = 1;
  57542. + }
  57543. +
  57544. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57545. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  57546. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  57547. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  57548. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  57549. +
  57550. + return;
  57551. +}
  57552. +
  57553. +/**
  57554. + * Clears the transfer state for a host channel. This function is normally
  57555. + * called after a transfer is done and the host channel is being released.
  57556. + *
  57557. + * @param core_if Programming view of DWC_otg controller.
  57558. + * @param hc Identifies the host channel to clean up.
  57559. + */
  57560. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57561. +{
  57562. + dwc_otg_hc_regs_t *hc_regs;
  57563. +
  57564. + hc->xfer_started = 0;
  57565. +
  57566. + /*
  57567. + * Clear channel interrupt enables and any unhandled channel interrupt
  57568. + * conditions.
  57569. + */
  57570. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57571. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  57572. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  57573. +#ifdef DEBUG
  57574. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  57575. +#endif
  57576. +}
  57577. +
  57578. +/**
  57579. + * Sets the channel property that indicates in which frame a periodic transfer
  57580. + * should occur. This is always set to the _next_ frame. This function has no
  57581. + * effect on non-periodic transfers.
  57582. + *
  57583. + * @param core_if Programming view of DWC_otg controller.
  57584. + * @param hc Identifies the host channel to set up and its properties.
  57585. + * @param hcchar Current value of the HCCHAR register for the specified host
  57586. + * channel.
  57587. + */
  57588. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  57589. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  57590. +{
  57591. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57592. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57593. + hfnum_data_t hfnum;
  57594. + hfnum.d32 =
  57595. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  57596. +
  57597. + /* 1 if _next_ frame is odd, 0 if it's even */
  57598. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  57599. +#ifdef DEBUG
  57600. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  57601. + && !hc->complete_split) {
  57602. + switch (hfnum.b.frnum & 0x7) {
  57603. + case 7:
  57604. + core_if->hfnum_7_samples++;
  57605. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  57606. + break;
  57607. + case 0:
  57608. + core_if->hfnum_0_samples++;
  57609. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  57610. + break;
  57611. + default:
  57612. + core_if->hfnum_other_samples++;
  57613. + core_if->hfnum_other_frrem_accum +=
  57614. + hfnum.b.frrem;
  57615. + break;
  57616. + }
  57617. + }
  57618. +#endif
  57619. + }
  57620. +}
  57621. +
  57622. +#ifdef DEBUG
  57623. +void hc_xfer_timeout(void *ptr)
  57624. +{
  57625. + hc_xfer_info_t *xfer_info = NULL;
  57626. + int hc_num = 0;
  57627. +
  57628. + if (ptr)
  57629. + xfer_info = (hc_xfer_info_t *) ptr;
  57630. +
  57631. + if (!xfer_info->hc) {
  57632. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  57633. + return;
  57634. + }
  57635. +
  57636. + hc_num = xfer_info->hc->hc_num;
  57637. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  57638. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  57639. + xfer_info->core_if->start_hcchar_val[hc_num]);
  57640. +}
  57641. +#endif
  57642. +
  57643. +void ep_xfer_timeout(void *ptr)
  57644. +{
  57645. + ep_xfer_info_t *xfer_info = NULL;
  57646. + int ep_num = 0;
  57647. + dctl_data_t dctl = {.d32 = 0 };
  57648. + gintsts_data_t gintsts = {.d32 = 0 };
  57649. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57650. +
  57651. + if (ptr)
  57652. + xfer_info = (ep_xfer_info_t *) ptr;
  57653. +
  57654. + if (!xfer_info->ep) {
  57655. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  57656. + return;
  57657. + }
  57658. +
  57659. + ep_num = xfer_info->ep->num;
  57660. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  57661. + /* Put the sate to 2 as it was time outed */
  57662. + xfer_info->state = 2;
  57663. +
  57664. + dctl.d32 =
  57665. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  57666. + gintsts.d32 =
  57667. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  57668. + gintmsk.d32 =
  57669. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  57670. +
  57671. + if (!gintmsk.b.goutnakeff) {
  57672. + /* Unmask it */
  57673. + gintmsk.b.goutnakeff = 1;
  57674. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  57675. + gintmsk.d32);
  57676. +
  57677. + }
  57678. +
  57679. + if (!gintsts.b.goutnakeff) {
  57680. + dctl.b.sgoutnak = 1;
  57681. + }
  57682. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  57683. + dctl.d32);
  57684. +
  57685. +}
  57686. +
  57687. +void set_pid_isoc(dwc_hc_t * hc)
  57688. +{
  57689. + /* Set up the initial PID for the transfer. */
  57690. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  57691. + if (hc->ep_is_in) {
  57692. + if (hc->multi_count == 1) {
  57693. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57694. + } else if (hc->multi_count == 2) {
  57695. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  57696. + } else {
  57697. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  57698. + }
  57699. + } else {
  57700. + if (hc->multi_count == 1) {
  57701. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57702. + } else {
  57703. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  57704. + }
  57705. + }
  57706. + } else {
  57707. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57708. + }
  57709. +}
  57710. +
  57711. +/**
  57712. + * This function does the setup for a data transfer for a host channel and
  57713. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  57714. + * Slave mode, the caller must ensure that there is sufficient space in the
  57715. + * request queue and Tx Data FIFO.
  57716. + *
  57717. + * For an OUT transfer in Slave mode, it loads a data packet into the
  57718. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  57719. + * the Host ISR.
  57720. + *
  57721. + * For an IN transfer in Slave mode, a data packet is requested. The data
  57722. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  57723. + * additional data packets are requested in the Host ISR.
  57724. + *
  57725. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  57726. + * register along with a packet count of 1 and the channel is enabled. This
  57727. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  57728. + * simply set to 0 since no data transfer occurs in this case.
  57729. + *
  57730. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  57731. + * all the information required to perform the subsequent data transfer. In
  57732. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  57733. + * controller performs the entire PING protocol, then starts the data
  57734. + * transfer.
  57735. + *
  57736. + * @param core_if Programming view of DWC_otg controller.
  57737. + * @param hc Information needed to initialize the host channel. The xfer_len
  57738. + * value may be reduced to accommodate the max widths of the XferSize and
  57739. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  57740. + * to reflect the final xfer_len value.
  57741. + */
  57742. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57743. +{
  57744. + hcchar_data_t hcchar;
  57745. + hctsiz_data_t hctsiz;
  57746. + uint16_t num_packets;
  57747. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  57748. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  57749. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57750. +
  57751. + hctsiz.d32 = 0;
  57752. +
  57753. + if (hc->do_ping) {
  57754. + if (!core_if->dma_enable) {
  57755. + dwc_otg_hc_do_ping(core_if, hc);
  57756. + hc->xfer_started = 1;
  57757. + return;
  57758. + } else {
  57759. + hctsiz.b.dopng = 1;
  57760. + }
  57761. + }
  57762. +
  57763. + if (hc->do_split) {
  57764. + num_packets = 1;
  57765. +
  57766. + if (hc->complete_split && !hc->ep_is_in) {
  57767. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  57768. + * core doesn't expect any data written to the FIFO */
  57769. + hc->xfer_len = 0;
  57770. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  57771. + hc->xfer_len = hc->max_packet;
  57772. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  57773. + hc->xfer_len = 188;
  57774. + }
  57775. +
  57776. + hctsiz.b.xfersize = hc->xfer_len;
  57777. + } else {
  57778. + /*
  57779. + * Ensure that the transfer length and packet count will fit
  57780. + * in the widths allocated for them in the HCTSIZn register.
  57781. + */
  57782. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57783. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57784. + /*
  57785. + * Make sure the transfer size is no larger than one
  57786. + * (micro)frame's worth of data. (A check was done
  57787. + * when the periodic transfer was accepted to ensure
  57788. + * that a (micro)frame's worth of data can be
  57789. + * programmed into a channel.)
  57790. + */
  57791. + uint32_t max_periodic_len =
  57792. + hc->multi_count * hc->max_packet;
  57793. + if (hc->xfer_len > max_periodic_len) {
  57794. + hc->xfer_len = max_periodic_len;
  57795. + } else {
  57796. + }
  57797. + } else if (hc->xfer_len > max_hc_xfer_size) {
  57798. + /* Make sure that xfer_len is a multiple of max packet size. */
  57799. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  57800. + }
  57801. +
  57802. + if (hc->xfer_len > 0) {
  57803. + num_packets =
  57804. + (hc->xfer_len + hc->max_packet -
  57805. + 1) / hc->max_packet;
  57806. + if (num_packets > max_hc_pkt_count) {
  57807. + num_packets = max_hc_pkt_count;
  57808. + hc->xfer_len = num_packets * hc->max_packet;
  57809. + }
  57810. + } else {
  57811. + /* Need 1 packet for transfer length of 0. */
  57812. + num_packets = 1;
  57813. + }
  57814. +
  57815. + if (hc->ep_is_in) {
  57816. + /* Always program an integral # of max packets for IN transfers. */
  57817. + hc->xfer_len = num_packets * hc->max_packet;
  57818. + }
  57819. +
  57820. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57821. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57822. + /*
  57823. + * Make sure that the multi_count field matches the
  57824. + * actual transfer length.
  57825. + */
  57826. + hc->multi_count = num_packets;
  57827. + }
  57828. +
  57829. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57830. + set_pid_isoc(hc);
  57831. +
  57832. + hctsiz.b.xfersize = hc->xfer_len;
  57833. + }
  57834. +
  57835. + hc->start_pkt_count = num_packets;
  57836. + hctsiz.b.pktcnt = num_packets;
  57837. + hctsiz.b.pid = hc->data_pid_start;
  57838. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57839. +
  57840. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57841. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  57842. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  57843. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57844. +
  57845. + if (core_if->dma_enable) {
  57846. + dwc_dma_t dma_addr;
  57847. + if (hc->align_buff) {
  57848. + dma_addr = hc->align_buff;
  57849. + } else {
  57850. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  57851. + }
  57852. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  57853. + }
  57854. +
  57855. + /* Start the split */
  57856. + if (hc->do_split) {
  57857. + hcsplt_data_t hcsplt;
  57858. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  57859. + hcsplt.b.spltena = 1;
  57860. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  57861. + }
  57862. +
  57863. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57864. + hcchar.b.multicnt = hc->multi_count;
  57865. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57866. +#ifdef DEBUG
  57867. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57868. + if (hcchar.b.chdis) {
  57869. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57870. + __func__, hc->hc_num, hcchar.d32);
  57871. + }
  57872. +#endif
  57873. +
  57874. + /* Set host channel enable after all other setup is complete. */
  57875. + hcchar.b.chen = 1;
  57876. + hcchar.b.chdis = 0;
  57877. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57878. +
  57879. + hc->xfer_started = 1;
  57880. + hc->requests++;
  57881. +
  57882. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  57883. + /* Load OUT packet into the appropriate Tx FIFO. */
  57884. + dwc_otg_hc_write_packet(core_if, hc);
  57885. + }
  57886. +#ifdef DEBUG
  57887. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57888. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  57889. + hc->hc_num, core_if);//GRAYG
  57890. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57891. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57892. +
  57893. + /* Start a timer for this transfer. */
  57894. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57895. + }
  57896. +#endif
  57897. +}
  57898. +
  57899. +/**
  57900. + * This function does the setup for a data transfer for a host channel
  57901. + * and starts the transfer in Descriptor DMA mode.
  57902. + *
  57903. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  57904. + * Sets PID and NTD values. For periodic transfers
  57905. + * initializes SCHED_INFO field with micro-frame bitmap.
  57906. + *
  57907. + * Initializes HCDMA register with descriptor list address and CTD value
  57908. + * then starts the transfer via enabling the channel.
  57909. + *
  57910. + * @param core_if Programming view of DWC_otg controller.
  57911. + * @param hc Information needed to initialize the host channel.
  57912. + */
  57913. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57914. +{
  57915. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57916. + hcchar_data_t hcchar;
  57917. + hctsiz_data_t hctsiz;
  57918. + hcdma_data_t hcdma;
  57919. +
  57920. + hctsiz.d32 = 0;
  57921. +
  57922. + if (hc->do_ping)
  57923. + hctsiz.b_ddma.dopng = 1;
  57924. +
  57925. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57926. + set_pid_isoc(hc);
  57927. +
  57928. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  57929. + hctsiz.b_ddma.pid = hc->data_pid_start;
  57930. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  57931. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  57932. +
  57933. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57934. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57935. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  57936. +
  57937. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57938. +
  57939. + hcdma.d32 = 0;
  57940. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  57941. +
  57942. + /* Always start from first descriptor. */
  57943. + hcdma.b.ctd = 0;
  57944. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  57945. +
  57946. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57947. + hcchar.b.multicnt = hc->multi_count;
  57948. +
  57949. +#ifdef DEBUG
  57950. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57951. + if (hcchar.b.chdis) {
  57952. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57953. + __func__, hc->hc_num, hcchar.d32);
  57954. + }
  57955. +#endif
  57956. +
  57957. + /* Set host channel enable after all other setup is complete. */
  57958. + hcchar.b.chen = 1;
  57959. + hcchar.b.chdis = 0;
  57960. +
  57961. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57962. +
  57963. + hc->xfer_started = 1;
  57964. + hc->requests++;
  57965. +
  57966. +#ifdef DEBUG
  57967. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  57968. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  57969. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  57970. + hc->hc_num, core_if);//GRAYG
  57971. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57972. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57973. + /* Start a timer for this transfer. */
  57974. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57975. + }
  57976. +#endif
  57977. +
  57978. +}
  57979. +
  57980. +/**
  57981. + * This function continues a data transfer that was started by previous call
  57982. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  57983. + * sufficient space in the request queue and Tx Data FIFO. This function
  57984. + * should only be called in Slave mode. In DMA mode, the controller acts
  57985. + * autonomously to complete transfers programmed to a host channel.
  57986. + *
  57987. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  57988. + * if there is any data remaining to be queued. For an IN transfer, another
  57989. + * data packet is always requested. For the SETUP phase of a control transfer,
  57990. + * this function does nothing.
  57991. + *
  57992. + * @return 1 if a new request is queued, 0 if no more requests are required
  57993. + * for this transfer.
  57994. + */
  57995. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57996. +{
  57997. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57998. +
  57999. + if (hc->do_split) {
  58000. + /* SPLITs always queue just once per channel */
  58001. + return 0;
  58002. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  58003. + /* SETUPs are queued only once since they can't be NAKed. */
  58004. + return 0;
  58005. + } else if (hc->ep_is_in) {
  58006. + /*
  58007. + * Always queue another request for other IN transfers. If
  58008. + * back-to-back INs are issued and NAKs are received for both,
  58009. + * the driver may still be processing the first NAK when the
  58010. + * second NAK is received. When the interrupt handler clears
  58011. + * the NAK interrupt for the first NAK, the second NAK will
  58012. + * not be seen. So we can't depend on the NAK interrupt
  58013. + * handler to requeue a NAKed request. Instead, IN requests
  58014. + * are issued each time this function is called. When the
  58015. + * transfer completes, the extra requests for the channel will
  58016. + * be flushed.
  58017. + */
  58018. + hcchar_data_t hcchar;
  58019. + dwc_otg_hc_regs_t *hc_regs =
  58020. + core_if->host_if->hc_regs[hc->hc_num];
  58021. +
  58022. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58023. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58024. + hcchar.b.chen = 1;
  58025. + hcchar.b.chdis = 0;
  58026. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  58027. + hcchar.d32);
  58028. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58029. + hc->requests++;
  58030. + return 1;
  58031. + } else {
  58032. + /* OUT transfers. */
  58033. + if (hc->xfer_count < hc->xfer_len) {
  58034. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58035. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58036. + hcchar_data_t hcchar;
  58037. + dwc_otg_hc_regs_t *hc_regs;
  58038. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58039. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58040. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58041. + }
  58042. +
  58043. + /* Load OUT packet into the appropriate Tx FIFO. */
  58044. + dwc_otg_hc_write_packet(core_if, hc);
  58045. + hc->requests++;
  58046. + return 1;
  58047. + } else {
  58048. + return 0;
  58049. + }
  58050. + }
  58051. +}
  58052. +
  58053. +/**
  58054. + * Starts a PING transfer. This function should only be called in Slave mode.
  58055. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  58056. + */
  58057. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58058. +{
  58059. + hcchar_data_t hcchar;
  58060. + hctsiz_data_t hctsiz;
  58061. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58062. +
  58063. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58064. +
  58065. + hctsiz.d32 = 0;
  58066. + hctsiz.b.dopng = 1;
  58067. + hctsiz.b.pktcnt = 1;
  58068. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58069. +
  58070. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58071. + hcchar.b.chen = 1;
  58072. + hcchar.b.chdis = 0;
  58073. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58074. +}
  58075. +
  58076. +/*
  58077. + * This function writes a packet into the Tx FIFO associated with the Host
  58078. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  58079. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  58080. + * periodic Tx FIFO is written. This function should only be called in Slave
  58081. + * mode.
  58082. + *
  58083. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  58084. + * then number of bytes written to the Tx FIFO.
  58085. + */
  58086. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58087. +{
  58088. + uint32_t i;
  58089. + uint32_t remaining_count;
  58090. + uint32_t byte_count;
  58091. + uint32_t dword_count;
  58092. +
  58093. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  58094. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  58095. +
  58096. + remaining_count = hc->xfer_len - hc->xfer_count;
  58097. + if (remaining_count > hc->max_packet) {
  58098. + byte_count = hc->max_packet;
  58099. + } else {
  58100. + byte_count = remaining_count;
  58101. + }
  58102. +
  58103. + dword_count = (byte_count + 3) / 4;
  58104. +
  58105. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  58106. + /* xfer_buff is DWORD aligned. */
  58107. + for (i = 0; i < dword_count; i++, data_buff++) {
  58108. + DWC_WRITE_REG32(data_fifo, *data_buff);
  58109. + }
  58110. + } else {
  58111. + /* xfer_buff is not DWORD aligned. */
  58112. + for (i = 0; i < dword_count; i++, data_buff++) {
  58113. + uint32_t data;
  58114. + data =
  58115. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  58116. + 16 | data_buff[3] << 24);
  58117. + DWC_WRITE_REG32(data_fifo, data);
  58118. + }
  58119. + }
  58120. +
  58121. + hc->xfer_count += byte_count;
  58122. + hc->xfer_buff += byte_count;
  58123. +}
  58124. +
  58125. +/**
  58126. + * Gets the current USB frame number. This is the frame number from the last
  58127. + * SOF packet.
  58128. + */
  58129. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  58130. +{
  58131. + dsts_data_t dsts;
  58132. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  58133. +
  58134. + /* read current frame/microframe number from DSTS register */
  58135. + return dsts.b.soffn;
  58136. +}
  58137. +
  58138. +/**
  58139. + * Calculates and gets the frame Interval value of HFIR register according PHY
  58140. + * type and speed.The application can modify a value of HFIR register only after
  58141. + * the Port Enable bit of the Host Port Control and Status register
  58142. + * (HPRT.PrtEnaPort) has been set.
  58143. +*/
  58144. +
  58145. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  58146. +{
  58147. + gusbcfg_data_t usbcfg;
  58148. + hwcfg2_data_t hwcfg2;
  58149. + hprt0_data_t hprt0;
  58150. + int clock = 60; // default value
  58151. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  58152. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  58153. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  58154. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58155. + clock = 60;
  58156. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  58157. + clock = 48;
  58158. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58159. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58160. + clock = 30;
  58161. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58162. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58163. + clock = 60;
  58164. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58165. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58166. + clock = 48;
  58167. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  58168. + clock = 48;
  58169. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  58170. + clock = 48;
  58171. + if (hprt0.b.prtspd == 0)
  58172. + /* High speed case */
  58173. + return 125 * clock;
  58174. + else
  58175. + /* FS/LS case */
  58176. + return 1000 * clock;
  58177. +}
  58178. +
  58179. +/**
  58180. + * This function reads a setup packet from the Rx FIFO into the destination
  58181. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  58182. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  58183. + *
  58184. + * @param core_if Programming view of DWC_otg controller.
  58185. + * @param dest Destination buffer for packet data.
  58186. + */
  58187. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  58188. +{
  58189. + device_grxsts_data_t status;
  58190. + /* Get the 8 bytes of a setup transaction data */
  58191. +
  58192. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  58193. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  58194. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  58195. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58196. + status.d32 =
  58197. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  58198. + DWC_DEBUGPL(DBG_ANY,
  58199. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  58200. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  58201. + status.b.fn, status.b.fn);
  58202. + }
  58203. +}
  58204. +
  58205. +/**
  58206. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  58207. + * IN for transmitting packets. It is normally called when the
  58208. + * "Enumeration Done" interrupt occurs.
  58209. + *
  58210. + * @param core_if Programming view of DWC_otg controller.
  58211. + * @param ep The EP0 data.
  58212. + */
  58213. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58214. +{
  58215. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58216. + dsts_data_t dsts;
  58217. + depctl_data_t diepctl;
  58218. + depctl_data_t doepctl;
  58219. + dctl_data_t dctl = {.d32 = 0 };
  58220. +
  58221. + ep->stp_rollover = 0;
  58222. + /* Read the Device Status and Endpoint 0 Control registers */
  58223. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  58224. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  58225. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  58226. +
  58227. + /* Set the MPS of the IN EP based on the enumeration speed */
  58228. + switch (dsts.b.enumspd) {
  58229. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  58230. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  58231. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  58232. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  58233. + break;
  58234. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  58235. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  58236. + break;
  58237. + }
  58238. +
  58239. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  58240. +
  58241. + /* Enable OUT EP for receive */
  58242. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58243. + doepctl.b.epena = 1;
  58244. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  58245. + }
  58246. +#ifdef VERBOSE
  58247. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  58248. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  58249. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  58250. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  58251. +#endif
  58252. + dctl.b.cgnpinnak = 1;
  58253. +
  58254. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  58255. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  58256. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  58257. +
  58258. +}
  58259. +
  58260. +/**
  58261. + * This function activates an EP. The Device EP control register for
  58262. + * the EP is configured as defined in the ep structure. Note: This
  58263. + * function is not used for EP0.
  58264. + *
  58265. + * @param core_if Programming view of DWC_otg controller.
  58266. + * @param ep The EP to activate.
  58267. + */
  58268. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58269. +{
  58270. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58271. + depctl_data_t depctl;
  58272. + volatile uint32_t *addr;
  58273. + daint_data_t daintmsk = {.d32 = 0 };
  58274. + dcfg_data_t dcfg;
  58275. + uint8_t i;
  58276. +
  58277. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  58278. + (ep->is_in ? "IN" : "OUT"));
  58279. +
  58280. +#ifdef DWC_UTE_PER_IO
  58281. + ep->xiso_frame_num = 0xFFFFFFFF;
  58282. + ep->xiso_active_xfers = 0;
  58283. + ep->xiso_queued_xfers = 0;
  58284. +#endif
  58285. + /* Read DEPCTLn register */
  58286. + if (ep->is_in == 1) {
  58287. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  58288. + daintmsk.ep.in = 1 << ep->num;
  58289. + } else {
  58290. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  58291. + daintmsk.ep.out = 1 << ep->num;
  58292. + }
  58293. +
  58294. + /* If the EP is already active don't change the EP Control
  58295. + * register. */
  58296. + depctl.d32 = DWC_READ_REG32(addr);
  58297. + if (!depctl.b.usbactep) {
  58298. + depctl.b.mps = ep->maxpacket;
  58299. + depctl.b.eptype = ep->type;
  58300. + depctl.b.txfnum = ep->tx_fifo_num;
  58301. +
  58302. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58303. + depctl.b.setd0pid = 1; // ???
  58304. + } else {
  58305. + depctl.b.setd0pid = 1;
  58306. + }
  58307. + depctl.b.usbactep = 1;
  58308. +
  58309. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58310. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  58311. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58312. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  58313. + break;
  58314. + }
  58315. + core_if->nextep_seq[i] = ep->num;
  58316. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  58317. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58318. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58319. + dcfg.b.epmscnt++;
  58320. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58321. +
  58322. + DWC_DEBUGPL(DBG_PCDV,
  58323. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58324. + __func__, core_if->first_in_nextep_seq);
  58325. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58326. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  58327. + core_if->nextep_seq[i]);
  58328. + }
  58329. +
  58330. + }
  58331. +
  58332. +
  58333. + DWC_WRITE_REG32(addr, depctl.d32);
  58334. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  58335. + }
  58336. +
  58337. + /* Enable the Interrupt for this EP */
  58338. + if (core_if->multiproc_int_enable) {
  58339. + if (ep->is_in == 1) {
  58340. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58341. + diepmsk.b.xfercompl = 1;
  58342. + diepmsk.b.timeout = 1;
  58343. + diepmsk.b.epdisabled = 1;
  58344. + diepmsk.b.ahberr = 1;
  58345. + diepmsk.b.intknepmis = 1;
  58346. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  58347. + diepmsk.b.intknepmis = 0;
  58348. + diepmsk.b.txfifoundrn = 1; //?????
  58349. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58350. + diepmsk.b.nak = 1;
  58351. + }
  58352. +
  58353. +
  58354. +
  58355. +/*
  58356. + if (core_if->dma_desc_enable) {
  58357. + diepmsk.b.bna = 1;
  58358. + }
  58359. +*/
  58360. +/*
  58361. + if (core_if->dma_enable) {
  58362. + doepmsk.b.nak = 1;
  58363. + }
  58364. +*/
  58365. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58366. + diepeachintmsk[ep->num], diepmsk.d32);
  58367. +
  58368. + } else {
  58369. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58370. + doepmsk.b.xfercompl = 1;
  58371. + doepmsk.b.ahberr = 1;
  58372. + doepmsk.b.epdisabled = 1;
  58373. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58374. + doepmsk.b.outtknepdis = 1;
  58375. +
  58376. +/*
  58377. +
  58378. + if (core_if->dma_desc_enable) {
  58379. + doepmsk.b.bna = 1;
  58380. + }
  58381. +*/
  58382. +/*
  58383. + doepmsk.b.babble = 1;
  58384. + doepmsk.b.nyet = 1;
  58385. + doepmsk.b.nak = 1;
  58386. +*/
  58387. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58388. + doepeachintmsk[ep->num], doepmsk.d32);
  58389. + }
  58390. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  58391. + 0, daintmsk.d32);
  58392. + } else {
  58393. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58394. + if (ep->is_in) {
  58395. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58396. + diepmsk.b.nak = 1;
  58397. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  58398. + } else {
  58399. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58400. + doepmsk.b.outtknepdis = 1;
  58401. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  58402. + }
  58403. + }
  58404. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  58405. + 0, daintmsk.d32);
  58406. + }
  58407. +
  58408. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  58409. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  58410. +
  58411. + ep->stall_clear_flag = 0;
  58412. +
  58413. + return;
  58414. +}
  58415. +
  58416. +/**
  58417. + * This function deactivates an EP. This is done by clearing the USB Active
  58418. + * EP bit in the Device EP control register. Note: This function is not used
  58419. + * for EP0. EP0 cannot be deactivated.
  58420. + *
  58421. + * @param core_if Programming view of DWC_otg controller.
  58422. + * @param ep The EP to deactivate.
  58423. + */
  58424. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58425. +{
  58426. + depctl_data_t depctl = {.d32 = 0 };
  58427. + volatile uint32_t *addr;
  58428. + daint_data_t daintmsk = {.d32 = 0 };
  58429. + dcfg_data_t dcfg;
  58430. + uint8_t i = 0;
  58431. +
  58432. +#ifdef DWC_UTE_PER_IO
  58433. + ep->xiso_frame_num = 0xFFFFFFFF;
  58434. + ep->xiso_active_xfers = 0;
  58435. + ep->xiso_queued_xfers = 0;
  58436. +#endif
  58437. +
  58438. + /* Read DEPCTLn register */
  58439. + if (ep->is_in == 1) {
  58440. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  58441. + daintmsk.ep.in = 1 << ep->num;
  58442. + } else {
  58443. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  58444. + daintmsk.ep.out = 1 << ep->num;
  58445. + }
  58446. +
  58447. + depctl.d32 = DWC_READ_REG32(addr);
  58448. +
  58449. + depctl.b.usbactep = 0;
  58450. +
  58451. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58452. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  58453. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58454. + if (core_if->nextep_seq[i] == ep->num)
  58455. + break;
  58456. + }
  58457. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  58458. + if (core_if->first_in_nextep_seq == ep->num)
  58459. + core_if->first_in_nextep_seq = i;
  58460. + core_if->nextep_seq[ep->num] = 0xff;
  58461. + depctl.b.nextep = 0;
  58462. + dcfg.d32 =
  58463. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  58464. + dcfg.b.epmscnt--;
  58465. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  58466. + dcfg.d32);
  58467. +
  58468. + DWC_DEBUGPL(DBG_PCDV,
  58469. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58470. + __func__, core_if->first_in_nextep_seq);
  58471. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58472. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  58473. + }
  58474. + }
  58475. +
  58476. + if (ep->is_in == 1)
  58477. + depctl.b.txfnum = 0;
  58478. +
  58479. + if (core_if->dma_desc_enable)
  58480. + depctl.b.epdis = 1;
  58481. +
  58482. + DWC_WRITE_REG32(addr, depctl.d32);
  58483. + depctl.d32 = DWC_READ_REG32(addr);
  58484. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  58485. + && depctl.b.epena) {
  58486. + depctl_data_t depctl = {.d32 = 0};
  58487. + if (ep->is_in) {
  58488. + diepint_data_t diepint = {.d32 = 0};
  58489. +
  58490. + depctl.b.snak = 1;
  58491. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58492. + diepctl, depctl.d32);
  58493. + do {
  58494. + dwc_udelay(10);
  58495. + diepint.d32 =
  58496. + DWC_READ_REG32(&core_if->
  58497. + dev_if->in_ep_regs[ep->num]->
  58498. + diepint);
  58499. + } while (!diepint.b.inepnakeff);
  58500. + diepint.b.inepnakeff = 1;
  58501. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58502. + diepint, diepint.d32);
  58503. + depctl.d32 = 0;
  58504. + depctl.b.epdis = 1;
  58505. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58506. + diepctl, depctl.d32);
  58507. + do {
  58508. + dwc_udelay(10);
  58509. + diepint.d32 =
  58510. + DWC_READ_REG32(&core_if->
  58511. + dev_if->in_ep_regs[ep->num]->
  58512. + diepint);
  58513. + } while (!diepint.b.epdisabled);
  58514. + diepint.b.epdisabled = 1;
  58515. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58516. + diepint, diepint.d32);
  58517. + } else {
  58518. + dctl_data_t dctl = {.d32 = 0};
  58519. + gintmsk_data_t gintsts = {.d32 = 0};
  58520. + doepint_data_t doepint = {.d32 = 0};
  58521. + dctl.b.sgoutnak = 1;
  58522. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  58523. + dctl, 0, dctl.d32);
  58524. + do {
  58525. + dwc_udelay(10);
  58526. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  58527. + } while (!gintsts.b.goutnakeff);
  58528. + gintsts.d32 = 0;
  58529. + gintsts.b.goutnakeff = 1;
  58530. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  58531. +
  58532. + depctl.d32 = 0;
  58533. + depctl.b.epdis = 1;
  58534. + depctl.b.snak = 1;
  58535. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  58536. + do
  58537. + {
  58538. + dwc_udelay(10);
  58539. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  58540. + out_ep_regs[ep->num]->doepint);
  58541. + } while (!doepint.b.epdisabled);
  58542. +
  58543. + doepint.b.epdisabled = 1;
  58544. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  58545. +
  58546. + dctl.d32 = 0;
  58547. + dctl.b.cgoutnak = 1;
  58548. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58549. + }
  58550. + }
  58551. +
  58552. + /* Disable the Interrupt for this EP */
  58553. + if (core_if->multiproc_int_enable) {
  58554. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  58555. + daintmsk.d32, 0);
  58556. +
  58557. + if (ep->is_in == 1) {
  58558. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58559. + diepeachintmsk[ep->num], 0);
  58560. + } else {
  58561. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58562. + doepeachintmsk[ep->num], 0);
  58563. + }
  58564. + } else {
  58565. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  58566. + daintmsk.d32, 0);
  58567. + }
  58568. +
  58569. +}
  58570. +
  58571. +/**
  58572. + * This function initializes dma descriptor chain.
  58573. + *
  58574. + * @param core_if Programming view of DWC_otg controller.
  58575. + * @param ep The EP to start the transfer on.
  58576. + */
  58577. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58578. +{
  58579. + dwc_otg_dev_dma_desc_t *dma_desc;
  58580. + uint32_t offset;
  58581. + uint32_t xfer_est;
  58582. + int i;
  58583. + unsigned maxxfer_local, total_len;
  58584. +
  58585. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  58586. + (ep->maxpacket%4)) {
  58587. + maxxfer_local = ep->maxpacket;
  58588. + total_len = ep->xfer_len;
  58589. + } else {
  58590. + maxxfer_local = ep->maxxfer;
  58591. + total_len = ep->total_len;
  58592. + }
  58593. +
  58594. + ep->desc_cnt = (total_len / maxxfer_local) +
  58595. + ((total_len % maxxfer_local) ? 1 : 0);
  58596. +
  58597. + if (!ep->desc_cnt)
  58598. + ep->desc_cnt = 1;
  58599. +
  58600. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  58601. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  58602. +
  58603. + dma_desc = ep->desc_addr;
  58604. + if (maxxfer_local == ep->maxpacket) {
  58605. + if ((total_len % maxxfer_local) &&
  58606. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  58607. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  58608. + (total_len % maxxfer_local);
  58609. + } else
  58610. + xfer_est = ep->desc_cnt * maxxfer_local;
  58611. + } else
  58612. + xfer_est = total_len;
  58613. + offset = 0;
  58614. + for (i = 0; i < ep->desc_cnt; ++i) {
  58615. + /** DMA Descriptor Setup */
  58616. + if (xfer_est > maxxfer_local) {
  58617. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58618. + dma_desc->status.b.l = 0;
  58619. + dma_desc->status.b.ioc = 0;
  58620. + dma_desc->status.b.sp = 0;
  58621. + dma_desc->status.b.bytes = maxxfer_local;
  58622. + dma_desc->buf = ep->dma_addr + offset;
  58623. + dma_desc->status.b.sts = 0;
  58624. + dma_desc->status.b.bs = BS_HOST_READY;
  58625. +
  58626. + xfer_est -= maxxfer_local;
  58627. + offset += maxxfer_local;
  58628. + } else {
  58629. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58630. + dma_desc->status.b.l = 1;
  58631. + dma_desc->status.b.ioc = 1;
  58632. + if (ep->is_in) {
  58633. + dma_desc->status.b.sp =
  58634. + (xfer_est %
  58635. + ep->maxpacket) ? 1 : ((ep->
  58636. + sent_zlp) ? 1 : 0);
  58637. + dma_desc->status.b.bytes = xfer_est;
  58638. + } else {
  58639. + if (maxxfer_local == ep->maxpacket)
  58640. + dma_desc->status.b.bytes = xfer_est;
  58641. + else
  58642. + dma_desc->status.b.bytes =
  58643. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  58644. + }
  58645. +
  58646. + dma_desc->buf = ep->dma_addr + offset;
  58647. + dma_desc->status.b.sts = 0;
  58648. + dma_desc->status.b.bs = BS_HOST_READY;
  58649. + }
  58650. + dma_desc++;
  58651. + }
  58652. +}
  58653. +/**
  58654. + * This function is called when to write ISOC data into appropriate dedicated
  58655. + * periodic FIFO.
  58656. + */
  58657. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  58658. +{
  58659. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58660. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  58661. + dtxfsts_data_t txstatus = {.d32 = 0 };
  58662. + uint32_t len = 0;
  58663. + int epnum = dwc_ep->num;
  58664. + int dwords;
  58665. +
  58666. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  58667. +
  58668. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  58669. +
  58670. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58671. +
  58672. + if (len > dwc_ep->maxpacket) {
  58673. + len = dwc_ep->maxpacket;
  58674. + }
  58675. +
  58676. + dwords = (len + 3) / 4;
  58677. +
  58678. + /* While there is space in the queue and space in the FIFO and
  58679. + * More data to tranfer, Write packets to the Tx FIFO */
  58680. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58681. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  58682. +
  58683. + while (txstatus.b.txfspcavail > dwords &&
  58684. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  58685. + /* Write the FIFO */
  58686. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  58687. +
  58688. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58689. + if (len > dwc_ep->maxpacket) {
  58690. + len = dwc_ep->maxpacket;
  58691. + }
  58692. +
  58693. + dwords = (len + 3) / 4;
  58694. + txstatus.d32 =
  58695. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58696. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  58697. + txstatus.d32);
  58698. + }
  58699. +
  58700. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  58701. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  58702. +
  58703. + return 1;
  58704. +}
  58705. +/**
  58706. + * This function does the setup for a data transfer for an EP and
  58707. + * starts the transfer. For an IN transfer, the packets will be
  58708. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  58709. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  58710. + *
  58711. + * @param core_if Programming view of DWC_otg controller.
  58712. + * @param ep The EP to start the transfer on.
  58713. + */
  58714. +
  58715. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58716. +{
  58717. + depctl_data_t depctl;
  58718. + deptsiz_data_t deptsiz;
  58719. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58720. +
  58721. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58722. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  58723. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  58724. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  58725. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  58726. + ep->total_len);
  58727. + /* IN endpoint */
  58728. + if (ep->is_in == 1) {
  58729. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58730. + core_if->dev_if->in_ep_regs[ep->num];
  58731. +
  58732. + gnptxsts_data_t gtxstatus;
  58733. +
  58734. + gtxstatus.d32 =
  58735. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58736. +
  58737. + if (core_if->en_multiple_tx_fifo == 0
  58738. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  58739. +#ifdef DEBUG
  58740. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  58741. +#endif
  58742. + return;
  58743. + }
  58744. +
  58745. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  58746. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  58747. +
  58748. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58749. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58750. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58751. + else
  58752. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  58753. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58754. +
  58755. +
  58756. + /* Zero Length Packet? */
  58757. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58758. + deptsiz.b.xfersize = 0;
  58759. + deptsiz.b.pktcnt = 1;
  58760. + } else {
  58761. + /* Program the transfer size and packet count
  58762. + * as follows: xfersize = N * maxpacket +
  58763. + * short_packet pktcnt = N + (short_packet
  58764. + * exist ? 1 : 0)
  58765. + */
  58766. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58767. + deptsiz.b.pktcnt =
  58768. + (ep->xfer_len - ep->xfer_count - 1 +
  58769. + ep->maxpacket) / ep->maxpacket;
  58770. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58771. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58772. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  58773. + }
  58774. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58775. + deptsiz.b.mc = deptsiz.b.pktcnt;
  58776. + }
  58777. +
  58778. + /* Write the DMA register */
  58779. + if (core_if->dma_enable) {
  58780. + if (core_if->dma_desc_enable == 0) {
  58781. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  58782. + deptsiz.b.mc = 1;
  58783. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58784. + deptsiz.d32);
  58785. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58786. + (uint32_t) ep->dma_addr);
  58787. + } else {
  58788. +#ifdef DWC_UTE_CFI
  58789. + /* The descriptor chain should be already initialized by now */
  58790. + if (ep->buff_mode != BM_STANDARD) {
  58791. + DWC_WRITE_REG32(&in_regs->diepdma,
  58792. + ep->descs_dma_addr);
  58793. + } else {
  58794. +#endif
  58795. + init_dma_desc_chain(core_if, ep);
  58796. + /** DIEPDMAn Register write */
  58797. + DWC_WRITE_REG32(&in_regs->diepdma,
  58798. + ep->dma_desc_addr);
  58799. +#ifdef DWC_UTE_CFI
  58800. + }
  58801. +#endif
  58802. + }
  58803. + } else {
  58804. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58805. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  58806. + /**
  58807. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  58808. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  58809. + * the data will be written into the fifo by the ISR.
  58810. + */
  58811. + if (core_if->en_multiple_tx_fifo == 0) {
  58812. + intr_mask.b.nptxfempty = 1;
  58813. + DWC_MODIFY_REG32
  58814. + (&core_if->core_global_regs->gintmsk,
  58815. + intr_mask.d32, intr_mask.d32);
  58816. + } else {
  58817. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58818. + if (ep->xfer_len > 0) {
  58819. + uint32_t fifoemptymsk = 0;
  58820. + fifoemptymsk = 1 << ep->num;
  58821. + DWC_MODIFY_REG32
  58822. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58823. + 0, fifoemptymsk);
  58824. +
  58825. + }
  58826. + }
  58827. + } else {
  58828. + write_isoc_tx_fifo(core_if, ep);
  58829. + }
  58830. + }
  58831. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58832. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58833. +
  58834. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58835. + dsts_data_t dsts = {.d32 = 0};
  58836. + if (ep->bInterval == 1) {
  58837. + dsts.d32 =
  58838. + DWC_READ_REG32(&core_if->dev_if->
  58839. + dev_global_regs->dsts);
  58840. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58841. + if (ep->frame_num > 0x3FFF) {
  58842. + ep->frm_overrun = 1;
  58843. + ep->frame_num &= 0x3FFF;
  58844. + } else
  58845. + ep->frm_overrun = 0;
  58846. + if (ep->frame_num & 0x1) {
  58847. + depctl.b.setd1pid = 1;
  58848. + } else {
  58849. + depctl.b.setd0pid = 1;
  58850. + }
  58851. + }
  58852. + }
  58853. + /* EP enable, IN data in FIFO */
  58854. + depctl.b.cnak = 1;
  58855. + depctl.b.epena = 1;
  58856. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58857. +
  58858. + } else {
  58859. + /* OUT endpoint */
  58860. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58861. + core_if->dev_if->out_ep_regs[ep->num];
  58862. +
  58863. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  58864. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  58865. +
  58866. + if (!core_if->dma_desc_enable) {
  58867. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58868. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58869. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58870. + else
  58871. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  58872. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58873. + }
  58874. +
  58875. + /* Program the transfer size and packet count as follows:
  58876. + *
  58877. + * pktcnt = N
  58878. + * xfersize = N * maxpacket
  58879. + */
  58880. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58881. + /* Zero Length Packet */
  58882. + deptsiz.b.xfersize = ep->maxpacket;
  58883. + deptsiz.b.pktcnt = 1;
  58884. + } else {
  58885. + deptsiz.b.pktcnt =
  58886. + (ep->xfer_len - ep->xfer_count +
  58887. + (ep->maxpacket - 1)) / ep->maxpacket;
  58888. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58889. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58890. + }
  58891. + if (!core_if->dma_desc_enable) {
  58892. + ep->xfer_len =
  58893. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  58894. + }
  58895. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58896. + }
  58897. +
  58898. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  58899. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58900. +
  58901. + if (core_if->dma_enable) {
  58902. + if (!core_if->dma_desc_enable) {
  58903. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58904. + deptsiz.d32);
  58905. +
  58906. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58907. + (uint32_t) ep->dma_addr);
  58908. + } else {
  58909. +#ifdef DWC_UTE_CFI
  58910. + /* The descriptor chain should be already initialized by now */
  58911. + if (ep->buff_mode != BM_STANDARD) {
  58912. + DWC_WRITE_REG32(&out_regs->doepdma,
  58913. + ep->descs_dma_addr);
  58914. + } else {
  58915. +#endif
  58916. + /** This is used for interrupt out transfers*/
  58917. + if (!ep->xfer_len)
  58918. + ep->xfer_len = ep->total_len;
  58919. + init_dma_desc_chain(core_if, ep);
  58920. +
  58921. + if (core_if->core_params->dev_out_nak) {
  58922. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58923. + deptsiz.b.pktcnt = (ep->total_len +
  58924. + (ep->maxpacket - 1)) / ep->maxpacket;
  58925. + deptsiz.b.xfersize = ep->total_len;
  58926. + /* Remember initial value of doeptsiz */
  58927. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  58928. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58929. + deptsiz.d32);
  58930. + }
  58931. + }
  58932. + /** DOEPDMAn Register write */
  58933. + DWC_WRITE_REG32(&out_regs->doepdma,
  58934. + ep->dma_desc_addr);
  58935. +#ifdef DWC_UTE_CFI
  58936. + }
  58937. +#endif
  58938. + }
  58939. + } else {
  58940. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58941. + }
  58942. +
  58943. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58944. + dsts_data_t dsts = {.d32 = 0};
  58945. + if (ep->bInterval == 1) {
  58946. + dsts.d32 =
  58947. + DWC_READ_REG32(&core_if->dev_if->
  58948. + dev_global_regs->dsts);
  58949. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58950. + if (ep->frame_num > 0x3FFF) {
  58951. + ep->frm_overrun = 1;
  58952. + ep->frame_num &= 0x3FFF;
  58953. + } else
  58954. + ep->frm_overrun = 0;
  58955. +
  58956. + if (ep->frame_num & 0x1) {
  58957. + depctl.b.setd1pid = 1;
  58958. + } else {
  58959. + depctl.b.setd0pid = 1;
  58960. + }
  58961. + }
  58962. + }
  58963. +
  58964. + /* EP enable */
  58965. + depctl.b.cnak = 1;
  58966. + depctl.b.epena = 1;
  58967. +
  58968. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  58969. +
  58970. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  58971. + DWC_READ_REG32(&out_regs->doepctl),
  58972. + DWC_READ_REG32(&out_regs->doeptsiz));
  58973. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  58974. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  58975. + daintmsk),
  58976. + DWC_READ_REG32(&core_if->core_global_regs->
  58977. + gintmsk));
  58978. +
  58979. + /* Timer is scheduling only for out bulk transfers for
  58980. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  58981. + * about received data payload in case of timeout
  58982. + */
  58983. + if (core_if->core_params->dev_out_nak) {
  58984. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58985. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  58986. + core_if->ep_xfer_info[ep->num].ep = ep;
  58987. + core_if->ep_xfer_info[ep->num].state = 1;
  58988. +
  58989. + /* Start a timer for this transfer. */
  58990. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  58991. + }
  58992. + }
  58993. + }
  58994. +}
  58995. +
  58996. +/**
  58997. + * This function setup a zero length transfer in Buffer DMA and
  58998. + * Slave modes for usb requests with zero field set
  58999. + *
  59000. + * @param core_if Programming view of DWC_otg controller.
  59001. + * @param ep The EP to start the transfer on.
  59002. + *
  59003. + */
  59004. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59005. +{
  59006. +
  59007. + depctl_data_t depctl;
  59008. + deptsiz_data_t deptsiz;
  59009. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59010. +
  59011. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59012. + DWC_PRINTF("zero length transfer is called\n");
  59013. +
  59014. + /* IN endpoint */
  59015. + if (ep->is_in == 1) {
  59016. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59017. + core_if->dev_if->in_ep_regs[ep->num];
  59018. +
  59019. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59020. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59021. +
  59022. + deptsiz.b.xfersize = 0;
  59023. + deptsiz.b.pktcnt = 1;
  59024. +
  59025. + /* Write the DMA register */
  59026. + if (core_if->dma_enable) {
  59027. + if (core_if->dma_desc_enable == 0) {
  59028. + deptsiz.b.mc = 1;
  59029. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59030. + deptsiz.d32);
  59031. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59032. + (uint32_t) ep->dma_addr);
  59033. + }
  59034. + } else {
  59035. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59036. + /**
  59037. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59038. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59039. + * the data will be written into the fifo by the ISR.
  59040. + */
  59041. + if (core_if->en_multiple_tx_fifo == 0) {
  59042. + intr_mask.b.nptxfempty = 1;
  59043. + DWC_MODIFY_REG32(&core_if->
  59044. + core_global_regs->gintmsk,
  59045. + intr_mask.d32, intr_mask.d32);
  59046. + } else {
  59047. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59048. + if (ep->xfer_len > 0) {
  59049. + uint32_t fifoemptymsk = 0;
  59050. + fifoemptymsk = 1 << ep->num;
  59051. + DWC_MODIFY_REG32(&core_if->
  59052. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59053. + 0, fifoemptymsk);
  59054. + }
  59055. + }
  59056. + }
  59057. +
  59058. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59059. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59060. + /* EP enable, IN data in FIFO */
  59061. + depctl.b.cnak = 1;
  59062. + depctl.b.epena = 1;
  59063. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59064. +
  59065. + } else {
  59066. + /* OUT endpoint */
  59067. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59068. + core_if->dev_if->out_ep_regs[ep->num];
  59069. +
  59070. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59071. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59072. +
  59073. + /* Zero Length Packet */
  59074. + deptsiz.b.xfersize = ep->maxpacket;
  59075. + deptsiz.b.pktcnt = 1;
  59076. +
  59077. + if (core_if->dma_enable) {
  59078. + if (!core_if->dma_desc_enable) {
  59079. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59080. + deptsiz.d32);
  59081. +
  59082. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59083. + (uint32_t) ep->dma_addr);
  59084. + }
  59085. + } else {
  59086. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59087. + }
  59088. +
  59089. + /* EP enable */
  59090. + depctl.b.cnak = 1;
  59091. + depctl.b.epena = 1;
  59092. +
  59093. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59094. +
  59095. + }
  59096. +}
  59097. +
  59098. +/**
  59099. + * This function does the setup for a data transfer for EP0 and starts
  59100. + * the transfer. For an IN transfer, the packets will be loaded into
  59101. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  59102. + * unloaded from the Rx FIFO in the ISR.
  59103. + *
  59104. + * @param core_if Programming view of DWC_otg controller.
  59105. + * @param ep The EP0 data.
  59106. + */
  59107. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59108. +{
  59109. + depctl_data_t depctl;
  59110. + deptsiz0_data_t deptsiz;
  59111. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59112. + dwc_otg_dev_dma_desc_t *dma_desc;
  59113. +
  59114. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59115. + "xfer_buff=%p start_xfer_buff=%p \n",
  59116. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59117. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  59118. +
  59119. + ep->total_len = ep->xfer_len;
  59120. +
  59121. + /* IN endpoint */
  59122. + if (ep->is_in == 1) {
  59123. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59124. + core_if->dev_if->in_ep_regs[0];
  59125. +
  59126. + gnptxsts_data_t gtxstatus;
  59127. +
  59128. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59129. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59130. + if (depctl.b.epena)
  59131. + return;
  59132. + }
  59133. +
  59134. + gtxstatus.d32 =
  59135. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59136. +
  59137. + /* If dedicated FIFO every time flush fifo before enable ep*/
  59138. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  59139. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  59140. +
  59141. + if (core_if->en_multiple_tx_fifo == 0
  59142. + && gtxstatus.b.nptxqspcavail == 0
  59143. + && !core_if->dma_enable) {
  59144. +#ifdef DEBUG
  59145. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59146. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  59147. + DWC_READ_REG32(&in_regs->diepctl));
  59148. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  59149. + deptsiz.d32,
  59150. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59151. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  59152. + gtxstatus.d32);
  59153. +#endif
  59154. + return;
  59155. + }
  59156. +
  59157. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59158. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59159. +
  59160. + /* Zero Length Packet? */
  59161. + if (ep->xfer_len == 0) {
  59162. + deptsiz.b.xfersize = 0;
  59163. + deptsiz.b.pktcnt = 1;
  59164. + } else {
  59165. + /* Program the transfer size and packet count
  59166. + * as follows: xfersize = N * maxpacket +
  59167. + * short_packet pktcnt = N + (short_packet
  59168. + * exist ? 1 : 0)
  59169. + */
  59170. + if (ep->xfer_len > ep->maxpacket) {
  59171. + ep->xfer_len = ep->maxpacket;
  59172. + deptsiz.b.xfersize = ep->maxpacket;
  59173. + } else {
  59174. + deptsiz.b.xfersize = ep->xfer_len;
  59175. + }
  59176. + deptsiz.b.pktcnt = 1;
  59177. +
  59178. + }
  59179. + DWC_DEBUGPL(DBG_PCDV,
  59180. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59181. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59182. + deptsiz.d32);
  59183. +
  59184. + /* Write the DMA register */
  59185. + if (core_if->dma_enable) {
  59186. + if (core_if->dma_desc_enable == 0) {
  59187. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59188. + deptsiz.d32);
  59189. +
  59190. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59191. + (uint32_t) ep->dma_addr);
  59192. + } else {
  59193. + dma_desc = core_if->dev_if->in_desc_addr;
  59194. +
  59195. + /** DMA Descriptor Setup */
  59196. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59197. + dma_desc->status.b.l = 1;
  59198. + dma_desc->status.b.ioc = 1;
  59199. + dma_desc->status.b.sp =
  59200. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59201. + dma_desc->status.b.bytes = ep->xfer_len;
  59202. + dma_desc->buf = ep->dma_addr;
  59203. + dma_desc->status.b.sts = 0;
  59204. + dma_desc->status.b.bs = BS_HOST_READY;
  59205. +
  59206. + /** DIEPDMA0 Register write */
  59207. + DWC_WRITE_REG32(&in_regs->diepdma,
  59208. + core_if->
  59209. + dev_if->dma_in_desc_addr);
  59210. + }
  59211. + } else {
  59212. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59213. + }
  59214. +
  59215. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59216. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59217. + /* EP enable, IN data in FIFO */
  59218. + depctl.b.cnak = 1;
  59219. + depctl.b.epena = 1;
  59220. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59221. +
  59222. + /**
  59223. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59224. + * data will be written into the fifo by the ISR.
  59225. + */
  59226. + if (!core_if->dma_enable) {
  59227. + if (core_if->en_multiple_tx_fifo == 0) {
  59228. + intr_mask.b.nptxfempty = 1;
  59229. + DWC_MODIFY_REG32(&core_if->
  59230. + core_global_regs->gintmsk,
  59231. + intr_mask.d32, intr_mask.d32);
  59232. + } else {
  59233. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59234. + if (ep->xfer_len > 0) {
  59235. + uint32_t fifoemptymsk = 0;
  59236. + fifoemptymsk |= 1 << ep->num;
  59237. + DWC_MODIFY_REG32(&core_if->
  59238. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59239. + 0, fifoemptymsk);
  59240. + }
  59241. + }
  59242. + }
  59243. + } else {
  59244. + /* OUT endpoint */
  59245. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59246. + core_if->dev_if->out_ep_regs[0];
  59247. +
  59248. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59249. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59250. +
  59251. + /* Program the transfer size and packet count as follows:
  59252. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  59253. + * pktcnt = N */
  59254. + /* Zero Length Packet */
  59255. + deptsiz.b.xfersize = ep->maxpacket;
  59256. + deptsiz.b.pktcnt = 1;
  59257. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  59258. + deptsiz.b.supcnt = 3;
  59259. +
  59260. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  59261. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59262. +
  59263. + if (core_if->dma_enable) {
  59264. + if (!core_if->dma_desc_enable) {
  59265. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59266. + deptsiz.d32);
  59267. +
  59268. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59269. + (uint32_t) ep->dma_addr);
  59270. + } else {
  59271. + dma_desc = core_if->dev_if->out_desc_addr;
  59272. +
  59273. + /** DMA Descriptor Setup */
  59274. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59275. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59276. + dma_desc->status.b.mtrf = 0;
  59277. + dma_desc->status.b.sr = 0;
  59278. + }
  59279. + dma_desc->status.b.l = 1;
  59280. + dma_desc->status.b.ioc = 1;
  59281. + dma_desc->status.b.bytes = ep->maxpacket;
  59282. + dma_desc->buf = ep->dma_addr;
  59283. + dma_desc->status.b.sts = 0;
  59284. + dma_desc->status.b.bs = BS_HOST_READY;
  59285. +
  59286. + /** DOEPDMA0 Register write */
  59287. + DWC_WRITE_REG32(&out_regs->doepdma,
  59288. + core_if->dev_if->
  59289. + dma_out_desc_addr);
  59290. + }
  59291. + } else {
  59292. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59293. + }
  59294. +
  59295. + /* EP enable */
  59296. + depctl.b.cnak = 1;
  59297. + depctl.b.epena = 1;
  59298. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  59299. + }
  59300. +}
  59301. +
  59302. +/**
  59303. + * This function continues control IN transfers started by
  59304. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  59305. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  59306. + * bit for the packet count.
  59307. + *
  59308. + * @param core_if Programming view of DWC_otg controller.
  59309. + * @param ep The EP0 data.
  59310. + */
  59311. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59312. +{
  59313. + depctl_data_t depctl;
  59314. + deptsiz0_data_t deptsiz;
  59315. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59316. + dwc_otg_dev_dma_desc_t *dma_desc;
  59317. +
  59318. + if (ep->is_in == 1) {
  59319. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59320. + core_if->dev_if->in_ep_regs[0];
  59321. + gnptxsts_data_t tx_status = {.d32 = 0 };
  59322. +
  59323. + tx_status.d32 =
  59324. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59325. + /** @todo Should there be check for room in the Tx
  59326. + * Status Queue. If not remove the code above this comment. */
  59327. +
  59328. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59329. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59330. +
  59331. + /* Program the transfer size and packet count
  59332. + * as follows: xfersize = N * maxpacket +
  59333. + * short_packet pktcnt = N + (short_packet
  59334. + * exist ? 1 : 0)
  59335. + */
  59336. +
  59337. + if (core_if->dma_desc_enable == 0) {
  59338. + deptsiz.b.xfersize =
  59339. + (ep->total_len - ep->xfer_count) >
  59340. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59341. + ep->xfer_count);
  59342. + deptsiz.b.pktcnt = 1;
  59343. + if (core_if->dma_enable == 0) {
  59344. + ep->xfer_len += deptsiz.b.xfersize;
  59345. + } else {
  59346. + ep->xfer_len = deptsiz.b.xfersize;
  59347. + }
  59348. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59349. + } else {
  59350. + ep->xfer_len =
  59351. + (ep->total_len - ep->xfer_count) >
  59352. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59353. + ep->xfer_count);
  59354. +
  59355. + dma_desc = core_if->dev_if->in_desc_addr;
  59356. +
  59357. + /** DMA Descriptor Setup */
  59358. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59359. + dma_desc->status.b.l = 1;
  59360. + dma_desc->status.b.ioc = 1;
  59361. + dma_desc->status.b.sp =
  59362. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59363. + dma_desc->status.b.bytes = ep->xfer_len;
  59364. + dma_desc->buf = ep->dma_addr;
  59365. + dma_desc->status.b.sts = 0;
  59366. + dma_desc->status.b.bs = BS_HOST_READY;
  59367. +
  59368. + /** DIEPDMA0 Register write */
  59369. + DWC_WRITE_REG32(&in_regs->diepdma,
  59370. + core_if->dev_if->dma_in_desc_addr);
  59371. + }
  59372. +
  59373. + DWC_DEBUGPL(DBG_PCDV,
  59374. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59375. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59376. + deptsiz.d32);
  59377. +
  59378. + /* Write the DMA register */
  59379. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59380. + if (core_if->dma_desc_enable == 0)
  59381. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59382. + (uint32_t) ep->dma_addr);
  59383. + }
  59384. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59385. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59386. + /* EP enable, IN data in FIFO */
  59387. + depctl.b.cnak = 1;
  59388. + depctl.b.epena = 1;
  59389. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59390. +
  59391. + /**
  59392. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59393. + * data will be written into the fifo by the ISR.
  59394. + */
  59395. + if (!core_if->dma_enable) {
  59396. + if (core_if->en_multiple_tx_fifo == 0) {
  59397. + /* First clear it from GINTSTS */
  59398. + intr_mask.b.nptxfempty = 1;
  59399. + DWC_MODIFY_REG32(&core_if->
  59400. + core_global_regs->gintmsk,
  59401. + intr_mask.d32, intr_mask.d32);
  59402. +
  59403. + } else {
  59404. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59405. + if (ep->xfer_len > 0) {
  59406. + uint32_t fifoemptymsk = 0;
  59407. + fifoemptymsk |= 1 << ep->num;
  59408. + DWC_MODIFY_REG32(&core_if->
  59409. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59410. + 0, fifoemptymsk);
  59411. + }
  59412. + }
  59413. + }
  59414. + } else {
  59415. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59416. + core_if->dev_if->out_ep_regs[0];
  59417. +
  59418. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59419. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59420. +
  59421. + /* Program the transfer size and packet count
  59422. + * as follows: xfersize = N * maxpacket +
  59423. + * short_packet pktcnt = N + (short_packet
  59424. + * exist ? 1 : 0)
  59425. + */
  59426. + deptsiz.b.xfersize = ep->maxpacket;
  59427. + deptsiz.b.pktcnt = 1;
  59428. +
  59429. + if (core_if->dma_desc_enable == 0) {
  59430. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59431. + } else {
  59432. + dma_desc = core_if->dev_if->out_desc_addr;
  59433. +
  59434. + /** DMA Descriptor Setup */
  59435. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59436. + dma_desc->status.b.l = 1;
  59437. + dma_desc->status.b.ioc = 1;
  59438. + dma_desc->status.b.bytes = ep->maxpacket;
  59439. + dma_desc->buf = ep->dma_addr;
  59440. + dma_desc->status.b.sts = 0;
  59441. + dma_desc->status.b.bs = BS_HOST_READY;
  59442. +
  59443. + /** DOEPDMA0 Register write */
  59444. + DWC_WRITE_REG32(&out_regs->doepdma,
  59445. + core_if->dev_if->dma_out_desc_addr);
  59446. + }
  59447. +
  59448. + DWC_DEBUGPL(DBG_PCDV,
  59449. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59450. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59451. + deptsiz.d32);
  59452. +
  59453. + /* Write the DMA register */
  59454. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59455. + if (core_if->dma_desc_enable == 0)
  59456. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59457. + (uint32_t) ep->dma_addr);
  59458. +
  59459. + }
  59460. +
  59461. + /* EP enable, IN data in FIFO */
  59462. + depctl.b.cnak = 1;
  59463. + depctl.b.epena = 1;
  59464. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59465. +
  59466. + }
  59467. +}
  59468. +
  59469. +#ifdef DEBUG
  59470. +void dump_msg(const u8 * buf, unsigned int length)
  59471. +{
  59472. + unsigned int start, num, i;
  59473. + char line[52], *p;
  59474. +
  59475. + if (length >= 512)
  59476. + return;
  59477. + start = 0;
  59478. + while (length > 0) {
  59479. + num = length < 16u ? length : 16u;
  59480. + p = line;
  59481. + for (i = 0; i < num; ++i) {
  59482. + if (i == 8)
  59483. + *p++ = ' ';
  59484. + DWC_SPRINTF(p, " %02x", buf[i]);
  59485. + p += 3;
  59486. + }
  59487. + *p = 0;
  59488. + DWC_PRINTF("%6x: %s\n", start, line);
  59489. + buf += num;
  59490. + start += num;
  59491. + length -= num;
  59492. + }
  59493. +}
  59494. +#else
  59495. +static inline void dump_msg(const u8 * buf, unsigned int length)
  59496. +{
  59497. +}
  59498. +#endif
  59499. +
  59500. +/**
  59501. + * This function writes a packet into the Tx FIFO associated with the
  59502. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  59503. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  59504. + * with all packets for the next micro-frame.
  59505. + *
  59506. + * @param core_if Programming view of DWC_otg controller.
  59507. + * @param ep The EP to write packet for.
  59508. + * @param dma Indicates if DMA is being used.
  59509. + */
  59510. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  59511. + int dma)
  59512. +{
  59513. + /**
  59514. + * The buffer is padded to DWORD on a per packet basis in
  59515. + * slave/dma mode if the MPS is not DWORD aligned. The last
  59516. + * packet, if short, is also padded to a multiple of DWORD.
  59517. + *
  59518. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  59519. + * multiple of DWORD in length
  59520. + *
  59521. + * ep->xfer_len can be any number of bytes
  59522. + *
  59523. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  59524. + * packet
  59525. + *
  59526. + * FIFO access is DWORD */
  59527. +
  59528. + uint32_t i;
  59529. + uint32_t byte_count;
  59530. + uint32_t dword_count;
  59531. + uint32_t *fifo;
  59532. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  59533. +
  59534. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  59535. + ep);
  59536. + if (ep->xfer_count >= ep->xfer_len) {
  59537. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  59538. + return;
  59539. + }
  59540. +
  59541. + /* Find the byte length of the packet either short packet or MPS */
  59542. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  59543. + byte_count = ep->xfer_len - ep->xfer_count;
  59544. + } else {
  59545. + byte_count = ep->maxpacket;
  59546. + }
  59547. +
  59548. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  59549. + * is not a multiple of DWORD */
  59550. + dword_count = (byte_count + 3) / 4;
  59551. +
  59552. +#ifdef VERBOSE
  59553. + dump_msg(ep->xfer_buff, byte_count);
  59554. +#endif
  59555. +
  59556. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  59557. + * intialized? What should this be? */
  59558. +
  59559. + fifo = core_if->data_fifo[ep->num];
  59560. +
  59561. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  59562. + fifo, data_buff, *data_buff, byte_count);
  59563. +
  59564. + if (!dma) {
  59565. + for (i = 0; i < dword_count; i++, data_buff++) {
  59566. + DWC_WRITE_REG32(fifo, *data_buff);
  59567. + }
  59568. + }
  59569. +
  59570. + ep->xfer_count += byte_count;
  59571. + ep->xfer_buff += byte_count;
  59572. + ep->dma_addr += byte_count;
  59573. +}
  59574. +
  59575. +/**
  59576. + * Set the EP STALL.
  59577. + *
  59578. + * @param core_if Programming view of DWC_otg controller.
  59579. + * @param ep The EP to set the stall on.
  59580. + */
  59581. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59582. +{
  59583. + depctl_data_t depctl;
  59584. + volatile uint32_t *depctl_addr;
  59585. +
  59586. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59587. + (ep->is_in ? "IN" : "OUT"));
  59588. +
  59589. + if (ep->is_in == 1) {
  59590. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59591. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59592. +
  59593. + /* set the disable and stall bits */
  59594. + if (depctl.b.epena) {
  59595. + depctl.b.epdis = 1;
  59596. + }
  59597. + depctl.b.stall = 1;
  59598. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59599. + } else {
  59600. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59601. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59602. +
  59603. + /* set the stall bit */
  59604. + depctl.b.stall = 1;
  59605. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59606. + }
  59607. +
  59608. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59609. +
  59610. + return;
  59611. +}
  59612. +
  59613. +/**
  59614. + * Clear the EP STALL.
  59615. + *
  59616. + * @param core_if Programming view of DWC_otg controller.
  59617. + * @param ep The EP to clear stall from.
  59618. + */
  59619. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59620. +{
  59621. + depctl_data_t depctl;
  59622. + volatile uint32_t *depctl_addr;
  59623. +
  59624. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59625. + (ep->is_in ? "IN" : "OUT"));
  59626. +
  59627. + if (ep->is_in == 1) {
  59628. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59629. + } else {
  59630. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59631. + }
  59632. +
  59633. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59634. +
  59635. + /* clear the stall bits */
  59636. + depctl.b.stall = 0;
  59637. +
  59638. + /*
  59639. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  59640. + * of whether an endpoint has the Halt feature set, a
  59641. + * ClearFeature(ENDPOINT_HALT) request always results in the
  59642. + * data toggle being reinitialized to DATA0.
  59643. + */
  59644. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  59645. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  59646. + depctl.b.setd0pid = 1; /* DATA0 */
  59647. + }
  59648. +
  59649. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59650. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59651. + return;
  59652. +}
  59653. +
  59654. +/**
  59655. + * This function reads a packet from the Rx FIFO into the destination
  59656. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  59657. + *
  59658. + * @param core_if Programming view of DWC_otg controller.
  59659. + * @param dest Destination buffer for the packet.
  59660. + * @param bytes Number of bytes to copy to the destination.
  59661. + */
  59662. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  59663. + uint8_t * dest, uint16_t bytes)
  59664. +{
  59665. + int i;
  59666. + int word_count = (bytes + 3) / 4;
  59667. +
  59668. + volatile uint32_t *fifo = core_if->data_fifo[0];
  59669. + uint32_t *data_buff = (uint32_t *) dest;
  59670. +
  59671. + /**
  59672. + * @todo Account for the case where _dest is not dword aligned. This
  59673. + * requires reading data from the FIFO into a uint32_t temp buffer,
  59674. + * then moving it into the data buffer.
  59675. + */
  59676. +
  59677. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  59678. + core_if, dest, bytes);
  59679. +
  59680. + for (i = 0; i < word_count; i++, data_buff++) {
  59681. + *data_buff = DWC_READ_REG32(fifo);
  59682. + }
  59683. +
  59684. + return;
  59685. +}
  59686. +
  59687. +/**
  59688. + * This functions reads the device registers and prints them
  59689. + *
  59690. + * @param core_if Programming view of DWC_otg controller.
  59691. + */
  59692. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  59693. +{
  59694. + int i;
  59695. + volatile uint32_t *addr;
  59696. +
  59697. + DWC_PRINTF("Device Global Registers\n");
  59698. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  59699. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  59700. + (unsigned long)addr, DWC_READ_REG32(addr));
  59701. + addr = &core_if->dev_if->dev_global_regs->dctl;
  59702. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  59703. + (unsigned long)addr, DWC_READ_REG32(addr));
  59704. + addr = &core_if->dev_if->dev_global_regs->dsts;
  59705. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  59706. + (unsigned long)addr, DWC_READ_REG32(addr));
  59707. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  59708. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59709. + DWC_READ_REG32(addr));
  59710. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  59711. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59712. + DWC_READ_REG32(addr));
  59713. + addr = &core_if->dev_if->dev_global_regs->daint;
  59714. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59715. + DWC_READ_REG32(addr));
  59716. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  59717. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59718. + DWC_READ_REG32(addr));
  59719. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  59720. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59721. + DWC_READ_REG32(addr));
  59722. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  59723. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  59724. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  59725. + (unsigned long)addr, DWC_READ_REG32(addr));
  59726. + }
  59727. +
  59728. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  59729. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59730. + DWC_READ_REG32(addr));
  59731. +
  59732. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  59733. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  59734. + (unsigned long)addr, DWC_READ_REG32(addr));
  59735. +
  59736. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  59737. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  59738. + (unsigned long)addr, DWC_READ_REG32(addr));
  59739. +
  59740. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  59741. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59742. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  59743. + (unsigned long)addr, DWC_READ_REG32(addr));
  59744. + }
  59745. +
  59746. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59747. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59748. + DWC_READ_REG32(addr));
  59749. +
  59750. + if (core_if->hwcfg2.b.multi_proc_int) {
  59751. +
  59752. + addr = &core_if->dev_if->dev_global_regs->deachint;
  59753. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  59754. + (unsigned long)addr, DWC_READ_REG32(addr));
  59755. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  59756. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  59757. + (unsigned long)addr, DWC_READ_REG32(addr));
  59758. +
  59759. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59760. + addr =
  59761. + &core_if->dev_if->
  59762. + dev_global_regs->diepeachintmsk[i];
  59763. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59764. + i, (unsigned long)addr,
  59765. + DWC_READ_REG32(addr));
  59766. + }
  59767. +
  59768. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59769. + addr =
  59770. + &core_if->dev_if->
  59771. + dev_global_regs->doepeachintmsk[i];
  59772. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59773. + i, (unsigned long)addr,
  59774. + DWC_READ_REG32(addr));
  59775. + }
  59776. + }
  59777. +
  59778. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59779. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  59780. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  59781. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  59782. + (unsigned long)addr, DWC_READ_REG32(addr));
  59783. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  59784. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  59785. + (unsigned long)addr, DWC_READ_REG32(addr));
  59786. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  59787. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  59788. + (unsigned long)addr, DWC_READ_REG32(addr));
  59789. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  59790. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  59791. + (unsigned long)addr, DWC_READ_REG32(addr));
  59792. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  59793. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  59794. + (unsigned long)addr, DWC_READ_REG32(addr));
  59795. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  59796. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  59797. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  59798. + }
  59799. +
  59800. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59801. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  59802. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  59803. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  59804. + (unsigned long)addr, DWC_READ_REG32(addr));
  59805. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  59806. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  59807. + (unsigned long)addr, DWC_READ_REG32(addr));
  59808. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  59809. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  59810. + (unsigned long)addr, DWC_READ_REG32(addr));
  59811. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  59812. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  59813. + (unsigned long)addr, DWC_READ_REG32(addr));
  59814. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  59815. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  59816. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  59817. + (unsigned long)addr, DWC_READ_REG32(addr));
  59818. + }
  59819. +
  59820. + }
  59821. +}
  59822. +
  59823. +/**
  59824. + * This functions reads the SPRAM and prints its content
  59825. + *
  59826. + * @param core_if Programming view of DWC_otg controller.
  59827. + */
  59828. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  59829. +{
  59830. + volatile uint8_t *addr, *start_addr, *end_addr;
  59831. +
  59832. + DWC_PRINTF("SPRAM Data:\n");
  59833. + start_addr = (void *)core_if->core_global_regs;
  59834. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  59835. + start_addr += 0x00028000;
  59836. + end_addr = (void *)core_if->core_global_regs;
  59837. + end_addr += 0x000280e0;
  59838. +
  59839. + for (addr = start_addr; addr < end_addr; addr += 16) {
  59840. + DWC_PRINTF
  59841. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  59842. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  59843. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  59844. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  59845. + );
  59846. + }
  59847. +
  59848. + return;
  59849. +}
  59850. +
  59851. +/**
  59852. + * This function reads the host registers and prints them
  59853. + *
  59854. + * @param core_if Programming view of DWC_otg controller.
  59855. + */
  59856. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  59857. +{
  59858. + int i;
  59859. + volatile uint32_t *addr;
  59860. +
  59861. + DWC_PRINTF("Host Global Registers\n");
  59862. + addr = &core_if->host_if->host_global_regs->hcfg;
  59863. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  59864. + (unsigned long)addr, DWC_READ_REG32(addr));
  59865. + addr = &core_if->host_if->host_global_regs->hfir;
  59866. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  59867. + (unsigned long)addr, DWC_READ_REG32(addr));
  59868. + addr = &core_if->host_if->host_global_regs->hfnum;
  59869. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59870. + DWC_READ_REG32(addr));
  59871. + addr = &core_if->host_if->host_global_regs->hptxsts;
  59872. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59873. + DWC_READ_REG32(addr));
  59874. + addr = &core_if->host_if->host_global_regs->haint;
  59875. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59876. + DWC_READ_REG32(addr));
  59877. + addr = &core_if->host_if->host_global_regs->haintmsk;
  59878. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59879. + DWC_READ_REG32(addr));
  59880. + if (core_if->dma_desc_enable) {
  59881. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  59882. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  59883. + (unsigned long)addr, DWC_READ_REG32(addr));
  59884. + }
  59885. +
  59886. + addr = core_if->host_if->hprt0;
  59887. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59888. + DWC_READ_REG32(addr));
  59889. +
  59890. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  59891. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  59892. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  59893. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  59894. + (unsigned long)addr, DWC_READ_REG32(addr));
  59895. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  59896. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  59897. + (unsigned long)addr, DWC_READ_REG32(addr));
  59898. + addr = &core_if->host_if->hc_regs[i]->hcint;
  59899. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  59900. + (unsigned long)addr, DWC_READ_REG32(addr));
  59901. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  59902. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  59903. + (unsigned long)addr, DWC_READ_REG32(addr));
  59904. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  59905. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  59906. + (unsigned long)addr, DWC_READ_REG32(addr));
  59907. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  59908. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  59909. + (unsigned long)addr, DWC_READ_REG32(addr));
  59910. + if (core_if->dma_desc_enable) {
  59911. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  59912. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  59913. + (unsigned long)addr, DWC_READ_REG32(addr));
  59914. + }
  59915. +
  59916. + }
  59917. + return;
  59918. +}
  59919. +
  59920. +/**
  59921. + * This function reads the core global registers and prints them
  59922. + *
  59923. + * @param core_if Programming view of DWC_otg controller.
  59924. + */
  59925. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  59926. +{
  59927. + int i, ep_num;
  59928. + volatile uint32_t *addr;
  59929. + char *txfsiz;
  59930. +
  59931. + DWC_PRINTF("Core Global Registers\n");
  59932. + addr = &core_if->core_global_regs->gotgctl;
  59933. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59934. + DWC_READ_REG32(addr));
  59935. + addr = &core_if->core_global_regs->gotgint;
  59936. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59937. + DWC_READ_REG32(addr));
  59938. + addr = &core_if->core_global_regs->gahbcfg;
  59939. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59940. + DWC_READ_REG32(addr));
  59941. + addr = &core_if->core_global_regs->gusbcfg;
  59942. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59943. + DWC_READ_REG32(addr));
  59944. + addr = &core_if->core_global_regs->grstctl;
  59945. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59946. + DWC_READ_REG32(addr));
  59947. + addr = &core_if->core_global_regs->gintsts;
  59948. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59949. + DWC_READ_REG32(addr));
  59950. + addr = &core_if->core_global_regs->gintmsk;
  59951. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59952. + DWC_READ_REG32(addr));
  59953. + addr = &core_if->core_global_regs->grxstsr;
  59954. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59955. + DWC_READ_REG32(addr));
  59956. + addr = &core_if->core_global_regs->grxfsiz;
  59957. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59958. + DWC_READ_REG32(addr));
  59959. + addr = &core_if->core_global_regs->gnptxfsiz;
  59960. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59961. + DWC_READ_REG32(addr));
  59962. + addr = &core_if->core_global_regs->gnptxsts;
  59963. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59964. + DWC_READ_REG32(addr));
  59965. + addr = &core_if->core_global_regs->gi2cctl;
  59966. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59967. + DWC_READ_REG32(addr));
  59968. + addr = &core_if->core_global_regs->gpvndctl;
  59969. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59970. + DWC_READ_REG32(addr));
  59971. + addr = &core_if->core_global_regs->ggpio;
  59972. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59973. + DWC_READ_REG32(addr));
  59974. + addr = &core_if->core_global_regs->guid;
  59975. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  59976. + (unsigned long)addr, DWC_READ_REG32(addr));
  59977. + addr = &core_if->core_global_regs->gsnpsid;
  59978. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59979. + DWC_READ_REG32(addr));
  59980. + addr = &core_if->core_global_regs->ghwcfg1;
  59981. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59982. + DWC_READ_REG32(addr));
  59983. + addr = &core_if->core_global_regs->ghwcfg2;
  59984. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59985. + DWC_READ_REG32(addr));
  59986. + addr = &core_if->core_global_regs->ghwcfg3;
  59987. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59988. + DWC_READ_REG32(addr));
  59989. + addr = &core_if->core_global_regs->ghwcfg4;
  59990. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59991. + DWC_READ_REG32(addr));
  59992. + addr = &core_if->core_global_regs->glpmcfg;
  59993. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59994. + DWC_READ_REG32(addr));
  59995. + addr = &core_if->core_global_regs->gpwrdn;
  59996. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59997. + DWC_READ_REG32(addr));
  59998. + addr = &core_if->core_global_regs->gdfifocfg;
  59999. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60000. + DWC_READ_REG32(addr));
  60001. + addr = &core_if->core_global_regs->adpctl;
  60002. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60003. + dwc_otg_adp_read_reg(core_if));
  60004. + addr = &core_if->core_global_regs->hptxfsiz;
  60005. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60006. + DWC_READ_REG32(addr));
  60007. +
  60008. + if (core_if->en_multiple_tx_fifo == 0) {
  60009. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  60010. + txfsiz = "DPTXFSIZ";
  60011. + } else {
  60012. + ep_num = core_if->hwcfg4.b.num_in_eps;
  60013. + txfsiz = "DIENPTXF";
  60014. + }
  60015. + for (i = 0; i < ep_num; i++) {
  60016. + addr = &core_if->core_global_regs->dtxfsiz[i];
  60017. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  60018. + (unsigned long)addr, DWC_READ_REG32(addr));
  60019. + }
  60020. + addr = core_if->pcgcctl;
  60021. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60022. + DWC_READ_REG32(addr));
  60023. +}
  60024. +
  60025. +/**
  60026. + * Flush a Tx FIFO.
  60027. + *
  60028. + * @param core_if Programming view of DWC_otg controller.
  60029. + * @param num Tx FIFO to flush.
  60030. + */
  60031. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  60032. +{
  60033. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60034. + volatile grstctl_t greset = {.d32 = 0 };
  60035. + int count = 0;
  60036. +
  60037. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  60038. +
  60039. + greset.b.txfflsh = 1;
  60040. + greset.b.txfnum = num;
  60041. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60042. +
  60043. + do {
  60044. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60045. + if (++count > 10000) {
  60046. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  60047. + __func__, greset.d32,
  60048. + DWC_READ_REG32(&global_regs->gnptxsts));
  60049. + break;
  60050. + }
  60051. + dwc_udelay(1);
  60052. + } while (greset.b.txfflsh == 1);
  60053. +
  60054. + /* Wait for 3 PHY Clocks */
  60055. + dwc_udelay(1);
  60056. +}
  60057. +
  60058. +/**
  60059. + * Flush Rx FIFO.
  60060. + *
  60061. + * @param core_if Programming view of DWC_otg controller.
  60062. + */
  60063. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  60064. +{
  60065. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60066. + volatile grstctl_t greset = {.d32 = 0 };
  60067. + int count = 0;
  60068. +
  60069. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  60070. + /*
  60071. + *
  60072. + */
  60073. + greset.b.rxfflsh = 1;
  60074. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60075. +
  60076. + do {
  60077. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60078. + if (++count > 10000) {
  60079. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  60080. + greset.d32);
  60081. + break;
  60082. + }
  60083. + dwc_udelay(1);
  60084. + } while (greset.b.rxfflsh == 1);
  60085. +
  60086. + /* Wait for 3 PHY Clocks */
  60087. + dwc_udelay(1);
  60088. +}
  60089. +
  60090. +/**
  60091. + * Do core a soft reset of the core. Be careful with this because it
  60092. + * resets all the internal state machines of the core.
  60093. + */
  60094. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  60095. +{
  60096. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60097. + volatile grstctl_t greset = {.d32 = 0 };
  60098. + int count = 0;
  60099. +
  60100. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  60101. + /* Wait for AHB master IDLE state. */
  60102. + do {
  60103. + dwc_udelay(10);
  60104. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60105. + if (++count > 100000) {
  60106. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  60107. + greset.d32);
  60108. + return;
  60109. + }
  60110. + }
  60111. + while (greset.b.ahbidle == 0);
  60112. +
  60113. + /* Core Soft Reset */
  60114. + count = 0;
  60115. + greset.b.csftrst = 1;
  60116. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60117. + do {
  60118. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60119. + if (++count > 10000) {
  60120. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  60121. + __func__, greset.d32);
  60122. + break;
  60123. + }
  60124. + dwc_udelay(1);
  60125. + }
  60126. + while (greset.b.csftrst == 1);
  60127. +
  60128. + /* Wait for 3 PHY Clocks */
  60129. + dwc_mdelay(100);
  60130. +}
  60131. +
  60132. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  60133. +{
  60134. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  60135. +}
  60136. +
  60137. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  60138. +{
  60139. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  60140. +}
  60141. +
  60142. +/**
  60143. + * Register HCD callbacks. The callbacks are used to start and stop
  60144. + * the HCD for interrupt processing.
  60145. + *
  60146. + * @param core_if Programming view of DWC_otg controller.
  60147. + * @param cb the HCD callback structure.
  60148. + * @param p pointer to be passed to callback function (usb_hcd*).
  60149. + */
  60150. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  60151. + dwc_otg_cil_callbacks_t * cb, void *p)
  60152. +{
  60153. + core_if->hcd_cb = cb;
  60154. + cb->p = p;
  60155. +}
  60156. +
  60157. +/**
  60158. + * Register PCD callbacks. The callbacks are used to start and stop
  60159. + * the PCD for interrupt processing.
  60160. + *
  60161. + * @param core_if Programming view of DWC_otg controller.
  60162. + * @param cb the PCD callback structure.
  60163. + * @param p pointer to be passed to callback function (pcd*).
  60164. + */
  60165. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  60166. + dwc_otg_cil_callbacks_t * cb, void *p)
  60167. +{
  60168. + core_if->pcd_cb = cb;
  60169. + cb->p = p;
  60170. +}
  60171. +
  60172. +#ifdef DWC_EN_ISOC
  60173. +
  60174. +/**
  60175. + * This function writes isoc data per 1 (micro)frame into tx fifo
  60176. + *
  60177. + * @param core_if Programming view of DWC_otg controller.
  60178. + * @param ep The EP to start the transfer on.
  60179. + *
  60180. + */
  60181. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60182. +{
  60183. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  60184. + dtxfsts_data_t txstatus = {.d32 = 0 };
  60185. + uint32_t len = 0;
  60186. + uint32_t dwords;
  60187. +
  60188. + ep->xfer_len = ep->data_per_frame;
  60189. + ep->xfer_count = 0;
  60190. +
  60191. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  60192. +
  60193. + len = ep->xfer_len - ep->xfer_count;
  60194. +
  60195. + if (len > ep->maxpacket) {
  60196. + len = ep->maxpacket;
  60197. + }
  60198. +
  60199. + dwords = (len + 3) / 4;
  60200. +
  60201. + /* While there is space in the queue and space in the FIFO and
  60202. + * More data to tranfer, Write packets to the Tx FIFO */
  60203. + txstatus.d32 =
  60204. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  60205. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  60206. +
  60207. + while (txstatus.b.txfspcavail > dwords &&
  60208. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  60209. + /* Write the FIFO */
  60210. + dwc_otg_ep_write_packet(core_if, ep, 0);
  60211. +
  60212. + len = ep->xfer_len - ep->xfer_count;
  60213. + if (len > ep->maxpacket) {
  60214. + len = ep->maxpacket;
  60215. + }
  60216. +
  60217. + dwords = (len + 3) / 4;
  60218. + txstatus.d32 =
  60219. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60220. + dtxfsts);
  60221. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  60222. + txstatus.d32);
  60223. + }
  60224. +}
  60225. +
  60226. +/**
  60227. + * This function initializes a descriptor chain for Isochronous transfer
  60228. + *
  60229. + * @param core_if Programming view of DWC_otg controller.
  60230. + * @param ep The EP to start the transfer on.
  60231. + *
  60232. + */
  60233. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  60234. + dwc_ep_t * ep)
  60235. +{
  60236. + deptsiz_data_t deptsiz = {.d32 = 0 };
  60237. + depctl_data_t depctl = {.d32 = 0 };
  60238. + dsts_data_t dsts = {.d32 = 0 };
  60239. + volatile uint32_t *addr;
  60240. +
  60241. + if (ep->is_in) {
  60242. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  60243. + } else {
  60244. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  60245. + }
  60246. +
  60247. + ep->xfer_len = ep->data_per_frame;
  60248. + ep->xfer_count = 0;
  60249. + ep->xfer_buff = ep->cur_pkt_addr;
  60250. + ep->dma_addr = ep->cur_pkt_dma_addr;
  60251. +
  60252. + if (ep->is_in) {
  60253. + /* Program the transfer size and packet count
  60254. + * as follows: xfersize = N * maxpacket +
  60255. + * short_packet pktcnt = N + (short_packet
  60256. + * exist ? 1 : 0)
  60257. + */
  60258. + deptsiz.b.xfersize = ep->xfer_len;
  60259. + deptsiz.b.pktcnt =
  60260. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  60261. + deptsiz.b.mc = deptsiz.b.pktcnt;
  60262. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  60263. + deptsiz.d32);
  60264. +
  60265. + /* Write the DMA register */
  60266. + if (core_if->dma_enable) {
  60267. + DWC_WRITE_REG32(&
  60268. + (core_if->dev_if->in_ep_regs[ep->num]->
  60269. + diepdma), (uint32_t) ep->dma_addr);
  60270. + }
  60271. + } else {
  60272. + deptsiz.b.pktcnt =
  60273. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  60274. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  60275. +
  60276. + DWC_WRITE_REG32(&core_if->dev_if->
  60277. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  60278. +
  60279. + if (core_if->dma_enable) {
  60280. + DWC_WRITE_REG32(&
  60281. + (core_if->dev_if->
  60282. + out_ep_regs[ep->num]->doepdma),
  60283. + (uint32_t) ep->dma_addr);
  60284. + }
  60285. + }
  60286. +
  60287. + /** Enable endpoint, clear nak */
  60288. +
  60289. + depctl.d32 = 0;
  60290. + if (ep->bInterval == 1) {
  60291. + dsts.d32 =
  60292. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  60293. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  60294. +
  60295. + if (ep->next_frame & 0x1) {
  60296. + depctl.b.setd1pid = 1;
  60297. + } else {
  60298. + depctl.b.setd0pid = 1;
  60299. + }
  60300. + } else {
  60301. + ep->next_frame += ep->bInterval;
  60302. +
  60303. + if (ep->next_frame & 0x1) {
  60304. + depctl.b.setd1pid = 1;
  60305. + } else {
  60306. + depctl.b.setd0pid = 1;
  60307. + }
  60308. + }
  60309. + depctl.b.epena = 1;
  60310. + depctl.b.cnak = 1;
  60311. +
  60312. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  60313. + depctl.d32 = DWC_READ_REG32(addr);
  60314. +
  60315. + if (ep->is_in && core_if->dma_enable == 0) {
  60316. + write_isoc_frame_data(core_if, ep);
  60317. + }
  60318. +
  60319. +}
  60320. +#endif /* DWC_EN_ISOC */
  60321. +
  60322. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  60323. +{
  60324. + int i;
  60325. + for (i = 0; i < size; i++) {
  60326. + p[i] = -1;
  60327. + }
  60328. +}
  60329. +
  60330. +static int dwc_otg_param_initialized(int32_t val)
  60331. +{
  60332. + return val != -1;
  60333. +}
  60334. +
  60335. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  60336. +{
  60337. + int i;
  60338. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  60339. + if (!core_if->core_params) {
  60340. + return -DWC_E_NO_MEMORY;
  60341. + }
  60342. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  60343. + sizeof(*core_if->core_params) /
  60344. + sizeof(int32_t));
  60345. + DWC_PRINTF("Setting default values for core params\n");
  60346. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  60347. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  60348. + dwc_otg_set_param_dma_desc_enable(core_if,
  60349. + dwc_param_dma_desc_enable_default);
  60350. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  60351. + dwc_otg_set_param_dma_burst_size(core_if,
  60352. + dwc_param_dma_burst_size_default);
  60353. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  60354. + dwc_param_host_support_fs_ls_low_power_default);
  60355. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  60356. + dwc_param_enable_dynamic_fifo_default);
  60357. + dwc_otg_set_param_data_fifo_size(core_if,
  60358. + dwc_param_data_fifo_size_default);
  60359. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  60360. + dwc_param_dev_rx_fifo_size_default);
  60361. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  60362. + dwc_param_dev_nperio_tx_fifo_size_default);
  60363. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  60364. + dwc_param_host_rx_fifo_size_default);
  60365. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  60366. + dwc_param_host_nperio_tx_fifo_size_default);
  60367. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  60368. + dwc_param_host_perio_tx_fifo_size_default);
  60369. + dwc_otg_set_param_max_transfer_size(core_if,
  60370. + dwc_param_max_transfer_size_default);
  60371. + dwc_otg_set_param_max_packet_count(core_if,
  60372. + dwc_param_max_packet_count_default);
  60373. + dwc_otg_set_param_host_channels(core_if,
  60374. + dwc_param_host_channels_default);
  60375. + dwc_otg_set_param_dev_endpoints(core_if,
  60376. + dwc_param_dev_endpoints_default);
  60377. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  60378. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  60379. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  60380. + dwc_param_host_ls_low_power_phy_clk_default);
  60381. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  60382. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  60383. + dwc_param_phy_ulpi_ext_vbus_default);
  60384. + dwc_otg_set_param_phy_utmi_width(core_if,
  60385. + dwc_param_phy_utmi_width_default);
  60386. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  60387. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  60388. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  60389. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  60390. + dwc_param_en_multiple_tx_fifo_default);
  60391. + for (i = 0; i < 15; i++) {
  60392. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  60393. + dwc_param_dev_perio_tx_fifo_size_default,
  60394. + i);
  60395. + }
  60396. +
  60397. + for (i = 0; i < 15; i++) {
  60398. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  60399. + dwc_param_dev_tx_fifo_size_default,
  60400. + i);
  60401. + }
  60402. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  60403. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  60404. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  60405. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  60406. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  60407. + dwc_otg_set_param_tx_thr_length(core_if,
  60408. + dwc_param_tx_thr_length_default);
  60409. + dwc_otg_set_param_rx_thr_length(core_if,
  60410. + dwc_param_rx_thr_length_default);
  60411. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  60412. + dwc_param_ahb_thr_ratio_default);
  60413. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  60414. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  60415. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  60416. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  60417. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  60418. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  60419. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  60420. + DWC_PRINTF("Finished setting default values for core params\n");
  60421. +
  60422. + return 0;
  60423. +}
  60424. +
  60425. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  60426. +{
  60427. + return core_if->dma_enable;
  60428. +}
  60429. +
  60430. +/* Checks if the parameter is outside of its valid range of values */
  60431. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  60432. + (((_param_) < (_low_)) || \
  60433. + ((_param_) > (_high_)))
  60434. +
  60435. +/* Parameter access functions */
  60436. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  60437. +{
  60438. + int valid;
  60439. + int retval = 0;
  60440. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60441. + DWC_WARN("Wrong value for otg_cap parameter\n");
  60442. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  60443. + retval = -DWC_E_INVALID;
  60444. + goto out;
  60445. + }
  60446. +
  60447. + valid = 1;
  60448. + switch (val) {
  60449. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  60450. + if (core_if->hwcfg2.b.op_mode !=
  60451. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60452. + valid = 0;
  60453. + break;
  60454. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  60455. + if ((core_if->hwcfg2.b.op_mode !=
  60456. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60457. + && (core_if->hwcfg2.b.op_mode !=
  60458. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60459. + && (core_if->hwcfg2.b.op_mode !=
  60460. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60461. + && (core_if->hwcfg2.b.op_mode !=
  60462. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  60463. + valid = 0;
  60464. + }
  60465. + break;
  60466. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  60467. + /* always valid */
  60468. + break;
  60469. + }
  60470. + if (!valid) {
  60471. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  60472. + DWC_ERROR
  60473. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  60474. + val);
  60475. + }
  60476. + val =
  60477. + (((core_if->hwcfg2.b.op_mode ==
  60478. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60479. + || (core_if->hwcfg2.b.op_mode ==
  60480. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60481. + || (core_if->hwcfg2.b.op_mode ==
  60482. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60483. + || (core_if->hwcfg2.b.op_mode ==
  60484. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  60485. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  60486. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  60487. + retval = -DWC_E_INVALID;
  60488. + }
  60489. +
  60490. + core_if->core_params->otg_cap = val;
  60491. +out:
  60492. + return retval;
  60493. +}
  60494. +
  60495. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  60496. +{
  60497. + return core_if->core_params->otg_cap;
  60498. +}
  60499. +
  60500. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  60501. +{
  60502. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60503. + DWC_WARN("Wrong value for opt parameter\n");
  60504. + return -DWC_E_INVALID;
  60505. + }
  60506. + core_if->core_params->opt = val;
  60507. + return 0;
  60508. +}
  60509. +
  60510. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  60511. +{
  60512. + return core_if->core_params->opt;
  60513. +}
  60514. +
  60515. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60516. +{
  60517. + int retval = 0;
  60518. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60519. + DWC_WARN("Wrong value for dma enable\n");
  60520. + return -DWC_E_INVALID;
  60521. + }
  60522. +
  60523. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  60524. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  60525. + DWC_ERROR
  60526. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  60527. + val);
  60528. + }
  60529. + val = 0;
  60530. + retval = -DWC_E_INVALID;
  60531. + }
  60532. +
  60533. + core_if->core_params->dma_enable = val;
  60534. + if (val == 0) {
  60535. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  60536. + }
  60537. + return retval;
  60538. +}
  60539. +
  60540. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  60541. +{
  60542. + return core_if->core_params->dma_enable;
  60543. +}
  60544. +
  60545. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60546. +{
  60547. + int retval = 0;
  60548. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60549. + DWC_WARN("Wrong value for dma_enable\n");
  60550. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  60551. + return -DWC_E_INVALID;
  60552. + }
  60553. +
  60554. + if ((val == 1)
  60555. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  60556. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  60557. + if (dwc_otg_param_initialized
  60558. + (core_if->core_params->dma_desc_enable)) {
  60559. + DWC_ERROR
  60560. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  60561. + val);
  60562. + }
  60563. + val = 0;
  60564. + retval = -DWC_E_INVALID;
  60565. + }
  60566. + core_if->core_params->dma_desc_enable = val;
  60567. + return retval;
  60568. +}
  60569. +
  60570. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  60571. +{
  60572. + return core_if->core_params->dma_desc_enable;
  60573. +}
  60574. +
  60575. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  60576. + int32_t val)
  60577. +{
  60578. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60579. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  60580. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  60581. + return -DWC_E_INVALID;
  60582. + }
  60583. + core_if->core_params->host_support_fs_ls_low_power = val;
  60584. + return 0;
  60585. +}
  60586. +
  60587. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  60588. + core_if)
  60589. +{
  60590. + return core_if->core_params->host_support_fs_ls_low_power;
  60591. +}
  60592. +
  60593. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  60594. + int32_t val)
  60595. +{
  60596. + int retval = 0;
  60597. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60598. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  60599. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  60600. + return -DWC_E_INVALID;
  60601. + }
  60602. +
  60603. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  60604. + if (dwc_otg_param_initialized
  60605. + (core_if->core_params->enable_dynamic_fifo)) {
  60606. + DWC_ERROR
  60607. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  60608. + val);
  60609. + }
  60610. + val = 0;
  60611. + retval = -DWC_E_INVALID;
  60612. + }
  60613. + core_if->core_params->enable_dynamic_fifo = val;
  60614. + return retval;
  60615. +}
  60616. +
  60617. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  60618. +{
  60619. + return core_if->core_params->enable_dynamic_fifo;
  60620. +}
  60621. +
  60622. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60623. +{
  60624. + int retval = 0;
  60625. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  60626. + DWC_WARN("Wrong value for data_fifo_size\n");
  60627. + DWC_WARN("data_fifo_size must be 32-32768\n");
  60628. + return -DWC_E_INVALID;
  60629. + }
  60630. +
  60631. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  60632. + if (dwc_otg_param_initialized
  60633. + (core_if->core_params->data_fifo_size)) {
  60634. + DWC_ERROR
  60635. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  60636. + val);
  60637. + }
  60638. + val = core_if->hwcfg3.b.dfifo_depth;
  60639. + retval = -DWC_E_INVALID;
  60640. + }
  60641. +
  60642. + core_if->core_params->data_fifo_size = val;
  60643. + return retval;
  60644. +}
  60645. +
  60646. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  60647. +{
  60648. + return core_if->core_params->data_fifo_size;
  60649. +}
  60650. +
  60651. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60652. +{
  60653. + int retval = 0;
  60654. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60655. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  60656. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  60657. + return -DWC_E_INVALID;
  60658. + }
  60659. +
  60660. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60661. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  60662. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  60663. + }
  60664. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60665. + retval = -DWC_E_INVALID;
  60666. + }
  60667. +
  60668. + core_if->core_params->dev_rx_fifo_size = val;
  60669. + return retval;
  60670. +}
  60671. +
  60672. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60673. +{
  60674. + return core_if->core_params->dev_rx_fifo_size;
  60675. +}
  60676. +
  60677. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60678. + int32_t val)
  60679. +{
  60680. + int retval = 0;
  60681. +
  60682. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60683. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  60684. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  60685. + return -DWC_E_INVALID;
  60686. + }
  60687. +
  60688. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60689. + if (dwc_otg_param_initialized
  60690. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  60691. + DWC_ERROR
  60692. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  60693. + val);
  60694. + }
  60695. + val =
  60696. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60697. + 16);
  60698. + retval = -DWC_E_INVALID;
  60699. + }
  60700. +
  60701. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  60702. + return retval;
  60703. +}
  60704. +
  60705. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60706. +{
  60707. + return core_if->core_params->dev_nperio_tx_fifo_size;
  60708. +}
  60709. +
  60710. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  60711. + int32_t val)
  60712. +{
  60713. + int retval = 0;
  60714. +
  60715. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60716. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  60717. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  60718. + return -DWC_E_INVALID;
  60719. + }
  60720. +
  60721. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60722. + if (dwc_otg_param_initialized
  60723. + (core_if->core_params->host_rx_fifo_size)) {
  60724. + DWC_ERROR
  60725. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  60726. + val);
  60727. + }
  60728. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60729. + retval = -DWC_E_INVALID;
  60730. + }
  60731. +
  60732. + core_if->core_params->host_rx_fifo_size = val;
  60733. + return retval;
  60734. +
  60735. +}
  60736. +
  60737. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60738. +{
  60739. + return core_if->core_params->host_rx_fifo_size;
  60740. +}
  60741. +
  60742. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60743. + int32_t val)
  60744. +{
  60745. + int retval = 0;
  60746. +
  60747. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60748. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  60749. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  60750. + return -DWC_E_INVALID;
  60751. + }
  60752. +
  60753. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60754. + if (dwc_otg_param_initialized
  60755. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  60756. + DWC_ERROR
  60757. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  60758. + val);
  60759. + }
  60760. + val =
  60761. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60762. + 16);
  60763. + retval = -DWC_E_INVALID;
  60764. + }
  60765. +
  60766. + core_if->core_params->host_nperio_tx_fifo_size = val;
  60767. + return retval;
  60768. +}
  60769. +
  60770. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60771. +{
  60772. + return core_if->core_params->host_nperio_tx_fifo_size;
  60773. +}
  60774. +
  60775. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60776. + int32_t val)
  60777. +{
  60778. + int retval = 0;
  60779. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60780. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  60781. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  60782. + return -DWC_E_INVALID;
  60783. + }
  60784. +
  60785. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  60786. + if (dwc_otg_param_initialized
  60787. + (core_if->core_params->host_perio_tx_fifo_size)) {
  60788. + DWC_ERROR
  60789. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  60790. + val);
  60791. + }
  60792. + val = (core_if->hptxfsiz.d32) >> 16;
  60793. + retval = -DWC_E_INVALID;
  60794. + }
  60795. +
  60796. + core_if->core_params->host_perio_tx_fifo_size = val;
  60797. + return retval;
  60798. +}
  60799. +
  60800. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60801. +{
  60802. + return core_if->core_params->host_perio_tx_fifo_size;
  60803. +}
  60804. +
  60805. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  60806. + int32_t val)
  60807. +{
  60808. + int retval = 0;
  60809. +
  60810. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  60811. + DWC_WARN("Wrong value for max_transfer_size\n");
  60812. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  60813. + return -DWC_E_INVALID;
  60814. + }
  60815. +
  60816. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  60817. + if (dwc_otg_param_initialized
  60818. + (core_if->core_params->max_transfer_size)) {
  60819. + DWC_ERROR
  60820. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  60821. + val);
  60822. + }
  60823. + val =
  60824. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  60825. + 1);
  60826. + retval = -DWC_E_INVALID;
  60827. + }
  60828. +
  60829. + core_if->core_params->max_transfer_size = val;
  60830. + return retval;
  60831. +}
  60832. +
  60833. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  60834. +{
  60835. + return core_if->core_params->max_transfer_size;
  60836. +}
  60837. +
  60838. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  60839. +{
  60840. + int retval = 0;
  60841. +
  60842. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  60843. + DWC_WARN("Wrong value for max_packet_count\n");
  60844. + DWC_WARN("max_packet_count must be 15-511\n");
  60845. + return -DWC_E_INVALID;
  60846. + }
  60847. +
  60848. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  60849. + if (dwc_otg_param_initialized
  60850. + (core_if->core_params->max_packet_count)) {
  60851. + DWC_ERROR
  60852. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  60853. + val);
  60854. + }
  60855. + val =
  60856. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  60857. + retval = -DWC_E_INVALID;
  60858. + }
  60859. +
  60860. + core_if->core_params->max_packet_count = val;
  60861. + return retval;
  60862. +}
  60863. +
  60864. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  60865. +{
  60866. + return core_if->core_params->max_packet_count;
  60867. +}
  60868. +
  60869. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  60870. +{
  60871. + int retval = 0;
  60872. +
  60873. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  60874. + DWC_WARN("Wrong value for host_channels\n");
  60875. + DWC_WARN("host_channels must be 1-16\n");
  60876. + return -DWC_E_INVALID;
  60877. + }
  60878. +
  60879. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  60880. + if (dwc_otg_param_initialized
  60881. + (core_if->core_params->host_channels)) {
  60882. + DWC_ERROR
  60883. + ("%d invalid for host_channels. Check HW configurations.\n",
  60884. + val);
  60885. + }
  60886. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  60887. + retval = -DWC_E_INVALID;
  60888. + }
  60889. +
  60890. + core_if->core_params->host_channels = val;
  60891. + return retval;
  60892. +}
  60893. +
  60894. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  60895. +{
  60896. + return core_if->core_params->host_channels;
  60897. +}
  60898. +
  60899. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  60900. +{
  60901. + int retval = 0;
  60902. +
  60903. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  60904. + DWC_WARN("Wrong value for dev_endpoints\n");
  60905. + DWC_WARN("dev_endpoints must be 1-15\n");
  60906. + return -DWC_E_INVALID;
  60907. + }
  60908. +
  60909. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  60910. + if (dwc_otg_param_initialized
  60911. + (core_if->core_params->dev_endpoints)) {
  60912. + DWC_ERROR
  60913. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  60914. + val);
  60915. + }
  60916. + val = core_if->hwcfg2.b.num_dev_ep;
  60917. + retval = -DWC_E_INVALID;
  60918. + }
  60919. +
  60920. + core_if->core_params->dev_endpoints = val;
  60921. + return retval;
  60922. +}
  60923. +
  60924. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  60925. +{
  60926. + return core_if->core_params->dev_endpoints;
  60927. +}
  60928. +
  60929. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  60930. +{
  60931. + int retval = 0;
  60932. + int valid = 0;
  60933. +
  60934. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60935. + DWC_WARN("Wrong value for phy_type\n");
  60936. + DWC_WARN("phy_type must be 0,1 or 2\n");
  60937. + return -DWC_E_INVALID;
  60938. + }
  60939. +#ifndef NO_FS_PHY_HW_CHECKS
  60940. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  60941. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  60942. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60943. + valid = 1;
  60944. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  60945. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  60946. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60947. + valid = 1;
  60948. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  60949. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  60950. + valid = 1;
  60951. + }
  60952. + if (!valid) {
  60953. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  60954. + DWC_ERROR
  60955. + ("%d invalid for phy_type. Check HW configurations.\n",
  60956. + val);
  60957. + }
  60958. + if (core_if->hwcfg2.b.hs_phy_type) {
  60959. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  60960. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  60961. + val = DWC_PHY_TYPE_PARAM_UTMI;
  60962. + } else {
  60963. + val = DWC_PHY_TYPE_PARAM_ULPI;
  60964. + }
  60965. + }
  60966. + retval = -DWC_E_INVALID;
  60967. + }
  60968. +#endif
  60969. + core_if->core_params->phy_type = val;
  60970. + return retval;
  60971. +}
  60972. +
  60973. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  60974. +{
  60975. + return core_if->core_params->phy_type;
  60976. +}
  60977. +
  60978. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  60979. +{
  60980. + int retval = 0;
  60981. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60982. + DWC_WARN("Wrong value for speed parameter\n");
  60983. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  60984. + return -DWC_E_INVALID;
  60985. + }
  60986. + if ((val == 0)
  60987. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  60988. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  60989. + DWC_ERROR
  60990. + ("%d invalid for speed paremter. Check HW configuration.\n",
  60991. + val);
  60992. + }
  60993. + val =
  60994. + (dwc_otg_get_param_phy_type(core_if) ==
  60995. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  60996. + retval = -DWC_E_INVALID;
  60997. + }
  60998. + core_if->core_params->speed = val;
  60999. + return retval;
  61000. +}
  61001. +
  61002. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  61003. +{
  61004. + return core_if->core_params->speed;
  61005. +}
  61006. +
  61007. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  61008. + int32_t val)
  61009. +{
  61010. + int retval = 0;
  61011. +
  61012. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61013. + DWC_WARN
  61014. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  61015. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  61016. + return -DWC_E_INVALID;
  61017. + }
  61018. +
  61019. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  61020. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  61021. + if (dwc_otg_param_initialized
  61022. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  61023. + DWC_ERROR
  61024. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  61025. + val);
  61026. + }
  61027. + val =
  61028. + (dwc_otg_get_param_phy_type(core_if) ==
  61029. + DWC_PHY_TYPE_PARAM_FS) ?
  61030. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  61031. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  61032. + retval = -DWC_E_INVALID;
  61033. + }
  61034. +
  61035. + core_if->core_params->host_ls_low_power_phy_clk = val;
  61036. + return retval;
  61037. +}
  61038. +
  61039. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  61040. +{
  61041. + return core_if->core_params->host_ls_low_power_phy_clk;
  61042. +}
  61043. +
  61044. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  61045. +{
  61046. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61047. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  61048. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  61049. + return -DWC_E_INVALID;
  61050. + }
  61051. +
  61052. + core_if->core_params->phy_ulpi_ddr = val;
  61053. + return 0;
  61054. +}
  61055. +
  61056. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  61057. +{
  61058. + return core_if->core_params->phy_ulpi_ddr;
  61059. +}
  61060. +
  61061. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  61062. + int32_t val)
  61063. +{
  61064. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61065. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  61066. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  61067. + return -DWC_E_INVALID;
  61068. + }
  61069. +
  61070. + core_if->core_params->phy_ulpi_ext_vbus = val;
  61071. + return 0;
  61072. +}
  61073. +
  61074. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  61075. +{
  61076. + return core_if->core_params->phy_ulpi_ext_vbus;
  61077. +}
  61078. +
  61079. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  61080. +{
  61081. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  61082. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  61083. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  61084. + return -DWC_E_INVALID;
  61085. + }
  61086. +
  61087. + core_if->core_params->phy_utmi_width = val;
  61088. + return 0;
  61089. +}
  61090. +
  61091. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  61092. +{
  61093. + return core_if->core_params->phy_utmi_width;
  61094. +}
  61095. +
  61096. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  61097. +{
  61098. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61099. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  61100. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  61101. + return -DWC_E_INVALID;
  61102. + }
  61103. +
  61104. + core_if->core_params->ulpi_fs_ls = val;
  61105. + return 0;
  61106. +}
  61107. +
  61108. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  61109. +{
  61110. + return core_if->core_params->ulpi_fs_ls;
  61111. +}
  61112. +
  61113. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  61114. +{
  61115. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61116. + DWC_WARN("Wrong valaue for ts_dline\n");
  61117. + DWC_WARN("ts_dline must be 0 or 1\n");
  61118. + return -DWC_E_INVALID;
  61119. + }
  61120. +
  61121. + core_if->core_params->ts_dline = val;
  61122. + return 0;
  61123. +}
  61124. +
  61125. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  61126. +{
  61127. + return core_if->core_params->ts_dline;
  61128. +}
  61129. +
  61130. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61131. +{
  61132. + int retval = 0;
  61133. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61134. + DWC_WARN("Wrong valaue for i2c_enable\n");
  61135. + DWC_WARN("i2c_enable must be 0 or 1\n");
  61136. + return -DWC_E_INVALID;
  61137. + }
  61138. +#ifndef NO_FS_PHY_HW_CHECK
  61139. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  61140. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  61141. + DWC_ERROR
  61142. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  61143. + val);
  61144. + }
  61145. + val = 0;
  61146. + retval = -DWC_E_INVALID;
  61147. + }
  61148. +#endif
  61149. +
  61150. + core_if->core_params->i2c_enable = val;
  61151. + return retval;
  61152. +}
  61153. +
  61154. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  61155. +{
  61156. + return core_if->core_params->i2c_enable;
  61157. +}
  61158. +
  61159. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61160. + int32_t val, int fifo_num)
  61161. +{
  61162. + int retval = 0;
  61163. +
  61164. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61165. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  61166. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  61167. + return -DWC_E_INVALID;
  61168. + }
  61169. +
  61170. + if (val >
  61171. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61172. + if (dwc_otg_param_initialized
  61173. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  61174. + DWC_ERROR
  61175. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  61176. + val, fifo_num);
  61177. + }
  61178. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61179. + retval = -DWC_E_INVALID;
  61180. + }
  61181. +
  61182. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  61183. + return retval;
  61184. +}
  61185. +
  61186. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61187. + int fifo_num)
  61188. +{
  61189. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  61190. +}
  61191. +
  61192. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  61193. + int32_t val)
  61194. +{
  61195. + int retval = 0;
  61196. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61197. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  61198. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  61199. + return -DWC_E_INVALID;
  61200. + }
  61201. +
  61202. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  61203. + if (dwc_otg_param_initialized
  61204. + (core_if->core_params->en_multiple_tx_fifo)) {
  61205. + DWC_ERROR
  61206. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  61207. + val);
  61208. + }
  61209. + val = 0;
  61210. + retval = -DWC_E_INVALID;
  61211. + }
  61212. +
  61213. + core_if->core_params->en_multiple_tx_fifo = val;
  61214. + return retval;
  61215. +}
  61216. +
  61217. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  61218. +{
  61219. + return core_if->core_params->en_multiple_tx_fifo;
  61220. +}
  61221. +
  61222. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  61223. + int fifo_num)
  61224. +{
  61225. + int retval = 0;
  61226. +
  61227. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61228. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  61229. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  61230. + return -DWC_E_INVALID;
  61231. + }
  61232. +
  61233. + if (val >
  61234. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61235. + if (dwc_otg_param_initialized
  61236. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  61237. + DWC_ERROR
  61238. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  61239. + val, fifo_num);
  61240. + }
  61241. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61242. + retval = -DWC_E_INVALID;
  61243. + }
  61244. +
  61245. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  61246. + return retval;
  61247. +}
  61248. +
  61249. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61250. + int fifo_num)
  61251. +{
  61252. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  61253. +}
  61254. +
  61255. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61256. +{
  61257. + int retval = 0;
  61258. +
  61259. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  61260. + DWC_WARN("Wrong value for thr_ctl\n");
  61261. + DWC_WARN("thr_ctl must be 0-7\n");
  61262. + return -DWC_E_INVALID;
  61263. + }
  61264. +
  61265. + if ((val != 0) &&
  61266. + (!dwc_otg_get_param_dma_enable(core_if) ||
  61267. + !core_if->hwcfg4.b.ded_fifo_en)) {
  61268. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  61269. + DWC_ERROR
  61270. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  61271. + val);
  61272. + }
  61273. + val = 0;
  61274. + retval = -DWC_E_INVALID;
  61275. + }
  61276. +
  61277. + core_if->core_params->thr_ctl = val;
  61278. + return retval;
  61279. +}
  61280. +
  61281. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  61282. +{
  61283. + return core_if->core_params->thr_ctl;
  61284. +}
  61285. +
  61286. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61287. +{
  61288. + int retval = 0;
  61289. +
  61290. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61291. + DWC_WARN("Wrong value for lpm_enable\n");
  61292. + DWC_WARN("lpm_enable must be 0 or 1\n");
  61293. + return -DWC_E_INVALID;
  61294. + }
  61295. +
  61296. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  61297. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  61298. + DWC_ERROR
  61299. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  61300. + val);
  61301. + }
  61302. + val = 0;
  61303. + retval = -DWC_E_INVALID;
  61304. + }
  61305. +
  61306. + core_if->core_params->lpm_enable = val;
  61307. + return retval;
  61308. +}
  61309. +
  61310. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  61311. +{
  61312. + return core_if->core_params->lpm_enable;
  61313. +}
  61314. +
  61315. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61316. +{
  61317. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61318. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  61319. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  61320. + return -DWC_E_INVALID;
  61321. + }
  61322. +
  61323. + core_if->core_params->tx_thr_length = val;
  61324. + return 0;
  61325. +}
  61326. +
  61327. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  61328. +{
  61329. + return core_if->core_params->tx_thr_length;
  61330. +}
  61331. +
  61332. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61333. +{
  61334. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61335. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  61336. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  61337. + return -DWC_E_INVALID;
  61338. + }
  61339. +
  61340. + core_if->core_params->rx_thr_length = val;
  61341. + return 0;
  61342. +}
  61343. +
  61344. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  61345. +{
  61346. + return core_if->core_params->rx_thr_length;
  61347. +}
  61348. +
  61349. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  61350. +{
  61351. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  61352. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  61353. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  61354. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  61355. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  61356. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  61357. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  61358. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  61359. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  61360. + return -DWC_E_INVALID;
  61361. + }
  61362. + core_if->core_params->dma_burst_size = val;
  61363. + return 0;
  61364. +}
  61365. +
  61366. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  61367. +{
  61368. + return core_if->core_params->dma_burst_size;
  61369. +}
  61370. +
  61371. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61372. +{
  61373. + int retval = 0;
  61374. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61375. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  61376. + return -DWC_E_INVALID;
  61377. + }
  61378. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  61379. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  61380. + DWC_ERROR
  61381. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  61382. + val);
  61383. + }
  61384. + retval = -DWC_E_INVALID;
  61385. + val = 0;
  61386. + }
  61387. + core_if->core_params->pti_enable = val;
  61388. + return retval;
  61389. +}
  61390. +
  61391. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  61392. +{
  61393. + return core_if->core_params->pti_enable;
  61394. +}
  61395. +
  61396. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61397. +{
  61398. + int retval = 0;
  61399. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61400. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  61401. + return -DWC_E_INVALID;
  61402. + }
  61403. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  61404. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  61405. + DWC_ERROR
  61406. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  61407. + val);
  61408. + }
  61409. + retval = -DWC_E_INVALID;
  61410. + val = 0;
  61411. + }
  61412. + core_if->core_params->mpi_enable = val;
  61413. + return retval;
  61414. +}
  61415. +
  61416. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  61417. +{
  61418. + return core_if->core_params->mpi_enable;
  61419. +}
  61420. +
  61421. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61422. +{
  61423. + int retval = 0;
  61424. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61425. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  61426. + return -DWC_E_INVALID;
  61427. + }
  61428. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  61429. + if (dwc_otg_param_initialized
  61430. + (core_if->core_params->adp_supp_enable)) {
  61431. + DWC_ERROR
  61432. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  61433. + val);
  61434. + }
  61435. + retval = -DWC_E_INVALID;
  61436. + val = 0;
  61437. + }
  61438. + core_if->core_params->adp_supp_enable = val;
  61439. + /*Set OTG version 2.0 in case of enabling ADP*/
  61440. + if (val)
  61441. + dwc_otg_set_param_otg_ver(core_if, 1);
  61442. +
  61443. + return retval;
  61444. +}
  61445. +
  61446. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  61447. +{
  61448. + return core_if->core_params->adp_supp_enable;
  61449. +}
  61450. +
  61451. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61452. +{
  61453. + int retval = 0;
  61454. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61455. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  61456. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  61457. + return -DWC_E_INVALID;
  61458. + }
  61459. +
  61460. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  61461. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  61462. + DWC_ERROR
  61463. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  61464. + val);
  61465. + }
  61466. + retval = -DWC_E_INVALID;
  61467. + val = 0;
  61468. + }
  61469. + core_if->core_params->ic_usb_cap = val;
  61470. + return retval;
  61471. +}
  61472. +
  61473. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  61474. +{
  61475. + return core_if->core_params->ic_usb_cap;
  61476. +}
  61477. +
  61478. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  61479. +{
  61480. + int retval = 0;
  61481. + int valid = 1;
  61482. +
  61483. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61484. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  61485. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  61486. + return -DWC_E_INVALID;
  61487. + }
  61488. +
  61489. + if (val
  61490. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  61491. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  61492. + valid = 0;
  61493. + } else if (val
  61494. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  61495. + 4)) {
  61496. + valid = 0;
  61497. + }
  61498. + if (valid == 0) {
  61499. + if (dwc_otg_param_initialized
  61500. + (core_if->core_params->ahb_thr_ratio)) {
  61501. + DWC_ERROR
  61502. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  61503. + val);
  61504. + }
  61505. + retval = -DWC_E_INVALID;
  61506. + val = 0;
  61507. + }
  61508. +
  61509. + core_if->core_params->ahb_thr_ratio = val;
  61510. + return retval;
  61511. +}
  61512. +
  61513. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  61514. +{
  61515. + return core_if->core_params->ahb_thr_ratio;
  61516. +}
  61517. +
  61518. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  61519. +{
  61520. + int retval = 0;
  61521. + int valid = 1;
  61522. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  61523. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  61524. +
  61525. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61526. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  61527. + DWC_WARN("power_down must be 0 - 2\n");
  61528. + return -DWC_E_INVALID;
  61529. + }
  61530. +
  61531. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  61532. + valid = 0;
  61533. + }
  61534. + if ((val == 3)
  61535. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  61536. + || (hwcfg4.b.xhiber == 0))) {
  61537. + valid = 0;
  61538. + }
  61539. + if (valid == 0) {
  61540. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  61541. + DWC_ERROR
  61542. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  61543. + val);
  61544. + }
  61545. + retval = -DWC_E_INVALID;
  61546. + val = 0;
  61547. + }
  61548. + core_if->core_params->power_down = val;
  61549. + return retval;
  61550. +}
  61551. +
  61552. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  61553. +{
  61554. + return core_if->core_params->power_down;
  61555. +}
  61556. +
  61557. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61558. +{
  61559. + int retval = 0;
  61560. + int valid = 1;
  61561. +
  61562. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61563. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  61564. + DWC_WARN("reload_ctl must be 0 or 1\n");
  61565. + return -DWC_E_INVALID;
  61566. + }
  61567. +
  61568. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  61569. + valid = 0;
  61570. + }
  61571. + if (valid == 0) {
  61572. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  61573. + DWC_ERROR("%d invalid for parameter reload_ctl."
  61574. + "Check HW configuration.\n", val);
  61575. + }
  61576. + retval = -DWC_E_INVALID;
  61577. + val = 0;
  61578. + }
  61579. + core_if->core_params->reload_ctl = val;
  61580. + return retval;
  61581. +}
  61582. +
  61583. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  61584. +{
  61585. + return core_if->core_params->reload_ctl;
  61586. +}
  61587. +
  61588. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  61589. +{
  61590. + int retval = 0;
  61591. + int valid = 1;
  61592. +
  61593. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61594. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  61595. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  61596. + return -DWC_E_INVALID;
  61597. + }
  61598. +
  61599. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  61600. + !(core_if->core_params->dma_desc_enable))) {
  61601. + valid = 0;
  61602. + }
  61603. + if (valid == 0) {
  61604. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  61605. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  61606. + "Check HW configuration.\n", val);
  61607. + }
  61608. + retval = -DWC_E_INVALID;
  61609. + val = 0;
  61610. + }
  61611. + core_if->core_params->dev_out_nak = val;
  61612. + return retval;
  61613. +}
  61614. +
  61615. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  61616. +{
  61617. + return core_if->core_params->dev_out_nak;
  61618. +}
  61619. +
  61620. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  61621. +{
  61622. + int retval = 0;
  61623. + int valid = 1;
  61624. +
  61625. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61626. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  61627. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  61628. + return -DWC_E_INVALID;
  61629. + }
  61630. +
  61631. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  61632. + !(core_if->core_params->dma_desc_enable))) {
  61633. + valid = 0;
  61634. + }
  61635. + if (valid == 0) {
  61636. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  61637. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  61638. + "Check HW configuration.\n", val);
  61639. + }
  61640. + retval = -DWC_E_INVALID;
  61641. + val = 0;
  61642. + }
  61643. + core_if->core_params->cont_on_bna = val;
  61644. + return retval;
  61645. +}
  61646. +
  61647. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  61648. +{
  61649. + return core_if->core_params->cont_on_bna;
  61650. +}
  61651. +
  61652. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  61653. +{
  61654. + int retval = 0;
  61655. + int valid = 1;
  61656. +
  61657. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61658. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  61659. + DWC_WARN("ahb_single must be 0 or 1\n");
  61660. + return -DWC_E_INVALID;
  61661. + }
  61662. +
  61663. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  61664. + valid = 0;
  61665. + }
  61666. + if (valid == 0) {
  61667. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  61668. + DWC_ERROR("%d invalid for parameter ahb_single."
  61669. + "Check HW configuration.\n", val);
  61670. + }
  61671. + retval = -DWC_E_INVALID;
  61672. + val = 0;
  61673. + }
  61674. + core_if->core_params->ahb_single = val;
  61675. + return retval;
  61676. +}
  61677. +
  61678. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  61679. +{
  61680. + return core_if->core_params->ahb_single;
  61681. +}
  61682. +
  61683. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  61684. +{
  61685. + int retval = 0;
  61686. +
  61687. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61688. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  61689. + DWC_WARN
  61690. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  61691. + return -DWC_E_INVALID;
  61692. + }
  61693. +
  61694. + core_if->core_params->otg_ver = val;
  61695. + return retval;
  61696. +}
  61697. +
  61698. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  61699. +{
  61700. + return core_if->core_params->otg_ver;
  61701. +}
  61702. +
  61703. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  61704. +{
  61705. + gotgctl_data_t otgctl;
  61706. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61707. + return otgctl.b.hstnegscs;
  61708. +}
  61709. +
  61710. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  61711. +{
  61712. + gotgctl_data_t otgctl;
  61713. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61714. + return otgctl.b.sesreqscs;
  61715. +}
  61716. +
  61717. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  61718. +{
  61719. + if(core_if->otg_ver == 0) {
  61720. + gotgctl_data_t otgctl;
  61721. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61722. + otgctl.b.hnpreq = val;
  61723. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  61724. + } else {
  61725. + core_if->otg_sts = val;
  61726. + }
  61727. +}
  61728. +
  61729. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  61730. +{
  61731. + return core_if->snpsid;
  61732. +}
  61733. +
  61734. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  61735. +{
  61736. + gintsts_data_t gintsts;
  61737. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  61738. + return gintsts.b.curmode;
  61739. +}
  61740. +
  61741. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  61742. +{
  61743. + gusbcfg_data_t usbcfg;
  61744. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61745. + return usbcfg.b.hnpcap;
  61746. +}
  61747. +
  61748. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61749. +{
  61750. + gusbcfg_data_t usbcfg;
  61751. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61752. + usbcfg.b.hnpcap = val;
  61753. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61754. +}
  61755. +
  61756. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  61757. +{
  61758. + gusbcfg_data_t usbcfg;
  61759. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61760. + return usbcfg.b.srpcap;
  61761. +}
  61762. +
  61763. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61764. +{
  61765. + gusbcfg_data_t usbcfg;
  61766. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61767. + usbcfg.b.srpcap = val;
  61768. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61769. +}
  61770. +
  61771. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  61772. +{
  61773. + dcfg_data_t dcfg;
  61774. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  61775. +
  61776. + dcfg.d32 = -1; //GRAYG
  61777. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  61778. + if (NULL == core_if)
  61779. + DWC_ERROR("reg request with NULL core_if\n");
  61780. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  61781. + core_if, core_if->dev_if);
  61782. + if (NULL == core_if->dev_if)
  61783. + DWC_ERROR("reg request with NULL dev_if\n");
  61784. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  61785. + "dev_global_regs(%p)\n", __func__,
  61786. + core_if, core_if->dev_if,
  61787. + core_if->dev_if->dev_global_regs);
  61788. + if (NULL == core_if->dev_if->dev_global_regs)
  61789. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  61790. + else {
  61791. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  61792. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  61793. + core_if, core_if->dev_if,
  61794. + core_if->dev_if->dev_global_regs,
  61795. + &core_if->dev_if->dev_global_regs->dcfg);
  61796. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61797. + }
  61798. + return dcfg.b.devspd;
  61799. +}
  61800. +
  61801. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  61802. +{
  61803. + dcfg_data_t dcfg;
  61804. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61805. + dcfg.b.devspd = val;
  61806. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  61807. +}
  61808. +
  61809. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  61810. +{
  61811. + hprt0_data_t hprt0;
  61812. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61813. + return hprt0.b.prtconnsts;
  61814. +}
  61815. +
  61816. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  61817. +{
  61818. + dsts_data_t dsts;
  61819. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61820. + return dsts.b.enumspd;
  61821. +}
  61822. +
  61823. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  61824. +{
  61825. + hprt0_data_t hprt0;
  61826. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61827. + return hprt0.b.prtpwr;
  61828. +
  61829. +}
  61830. +
  61831. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  61832. +{
  61833. + return core_if->hibernation_suspend;
  61834. +}
  61835. +
  61836. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  61837. +{
  61838. + hprt0_data_t hprt0;
  61839. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61840. + hprt0.b.prtpwr = val;
  61841. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61842. +}
  61843. +
  61844. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  61845. +{
  61846. + hprt0_data_t hprt0;
  61847. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61848. + return hprt0.b.prtsusp;
  61849. +
  61850. +}
  61851. +
  61852. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  61853. +{
  61854. + hprt0_data_t hprt0;
  61855. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61856. + hprt0.b.prtsusp = val;
  61857. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61858. +}
  61859. +
  61860. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  61861. +{
  61862. + hfir_data_t hfir;
  61863. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61864. + return hfir.b.frint;
  61865. +
  61866. +}
  61867. +
  61868. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  61869. +{
  61870. + hfir_data_t hfir;
  61871. + uint32_t fram_int;
  61872. + fram_int = calc_frame_interval(core_if);
  61873. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61874. + if (!core_if->core_params->reload_ctl) {
  61875. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  61876. + "not set to 1.\nShould load driver with reload_ctl=1"
  61877. + " module parameter\n");
  61878. + return;
  61879. + }
  61880. + switch (fram_int) {
  61881. + case 3750:
  61882. + if ((val < 3350) || (val > 4150)) {
  61883. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  61884. + "clock freq should be from 3350 to 4150\n");
  61885. + return;
  61886. + }
  61887. + break;
  61888. + case 30000:
  61889. + if ((val < 26820) || (val > 33180)) {
  61890. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  61891. + "clock freq should be from 26820 to 33180\n");
  61892. + return;
  61893. + }
  61894. + break;
  61895. + case 6000:
  61896. + if ((val < 5360) || (val > 6640)) {
  61897. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  61898. + "clock freq should be from 5360 to 6640\n");
  61899. + return;
  61900. + }
  61901. + break;
  61902. + case 48000:
  61903. + if ((val < 42912) || (val > 53088)) {
  61904. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  61905. + "clock freq should be from 42912 to 53088\n");
  61906. + return;
  61907. + }
  61908. + break;
  61909. + case 7500:
  61910. + if ((val < 6700) || (val > 8300)) {
  61911. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  61912. + "clock freq should be from 6700 to 8300\n");
  61913. + return;
  61914. + }
  61915. + break;
  61916. + case 60000:
  61917. + if ((val < 53640) || (val > 65536)) {
  61918. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  61919. + "clock freq should be from 53640 to 65536\n");
  61920. + return;
  61921. + }
  61922. + break;
  61923. + default:
  61924. + DWC_WARN("Unknown frame interval\n");
  61925. + return;
  61926. + break;
  61927. +
  61928. + }
  61929. + hfir.b.frint = val;
  61930. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  61931. +}
  61932. +
  61933. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  61934. +{
  61935. + hcfg_data_t hcfg;
  61936. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61937. + return hcfg.b.modechtimen;
  61938. +
  61939. +}
  61940. +
  61941. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  61942. +{
  61943. + hcfg_data_t hcfg;
  61944. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61945. + hcfg.b.modechtimen = val;
  61946. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  61947. +}
  61948. +
  61949. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  61950. +{
  61951. + hprt0_data_t hprt0;
  61952. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61953. + hprt0.b.prtres = val;
  61954. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61955. +}
  61956. +
  61957. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  61958. +{
  61959. + dctl_data_t dctl;
  61960. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  61961. + return dctl.b.rmtwkupsig;
  61962. +}
  61963. +
  61964. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  61965. +{
  61966. + glpmcfg_data_t lpmcfg;
  61967. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61968. +
  61969. + DWC_ASSERT(!
  61970. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  61971. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  61972. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  61973. +
  61974. + return lpmcfg.b.prt_sleep_sts;
  61975. +}
  61976. +
  61977. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  61978. +{
  61979. + glpmcfg_data_t lpmcfg;
  61980. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61981. + return lpmcfg.b.rem_wkup_en;
  61982. +}
  61983. +
  61984. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  61985. +{
  61986. + glpmcfg_data_t lpmcfg;
  61987. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61988. + return lpmcfg.b.appl_resp;
  61989. +}
  61990. +
  61991. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  61992. +{
  61993. + glpmcfg_data_t lpmcfg;
  61994. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61995. + lpmcfg.b.appl_resp = val;
  61996. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61997. +}
  61998. +
  61999. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  62000. +{
  62001. + glpmcfg_data_t lpmcfg;
  62002. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62003. + return lpmcfg.b.hsic_connect;
  62004. +}
  62005. +
  62006. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  62007. +{
  62008. + glpmcfg_data_t lpmcfg;
  62009. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62010. + lpmcfg.b.hsic_connect = val;
  62011. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62012. +}
  62013. +
  62014. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  62015. +{
  62016. + glpmcfg_data_t lpmcfg;
  62017. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62018. + return lpmcfg.b.inv_sel_hsic;
  62019. +
  62020. +}
  62021. +
  62022. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  62023. +{
  62024. + glpmcfg_data_t lpmcfg;
  62025. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62026. + lpmcfg.b.inv_sel_hsic = val;
  62027. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62028. +}
  62029. +
  62030. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  62031. +{
  62032. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62033. +}
  62034. +
  62035. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62036. +{
  62037. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  62038. +}
  62039. +
  62040. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  62041. +{
  62042. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62043. +}
  62044. +
  62045. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  62046. +{
  62047. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  62048. +}
  62049. +
  62050. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  62051. +{
  62052. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62053. +}
  62054. +
  62055. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62056. +{
  62057. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  62058. +}
  62059. +
  62060. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  62061. +{
  62062. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  62063. +}
  62064. +
  62065. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62066. +{
  62067. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  62068. +}
  62069. +
  62070. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  62071. +{
  62072. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  62073. +}
  62074. +
  62075. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62076. +{
  62077. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  62078. +}
  62079. +
  62080. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  62081. +{
  62082. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  62083. +}
  62084. +
  62085. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  62086. +{
  62087. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  62088. +}
  62089. +
  62090. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  62091. +{
  62092. + return DWC_READ_REG32(core_if->host_if->hprt0);
  62093. +
  62094. +}
  62095. +
  62096. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  62097. +{
  62098. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  62099. +}
  62100. +
  62101. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  62102. +{
  62103. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  62104. +}
  62105. +
  62106. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  62107. +{
  62108. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  62109. +}
  62110. +
  62111. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  62112. +{
  62113. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  62114. +}
  62115. +
  62116. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  62117. +{
  62118. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  62119. +}
  62120. +
  62121. +/**
  62122. + * Start the SRP timer to detect when the SRP does not complete within
  62123. + * 6 seconds.
  62124. + *
  62125. + * @param core_if the pointer to core_if strucure.
  62126. + */
  62127. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  62128. +{
  62129. + core_if->srp_timer_started = 1;
  62130. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  62131. +}
  62132. +
  62133. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  62134. +{
  62135. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  62136. + gotgctl_data_t mem;
  62137. + gotgctl_data_t val;
  62138. +
  62139. + val.d32 = DWC_READ_REG32(addr);
  62140. + if (val.b.sesreq) {
  62141. + DWC_ERROR("Session Request Already active!\n");
  62142. + return;
  62143. + }
  62144. +
  62145. + DWC_INFO("Session Request Initated\n"); //NOTICE
  62146. + mem.d32 = DWC_READ_REG32(addr);
  62147. + mem.b.sesreq = 1;
  62148. + DWC_WRITE_REG32(addr, mem.d32);
  62149. +
  62150. + /* Start the SRP timer */
  62151. + dwc_otg_pcd_start_srp_timer(core_if);
  62152. + return;
  62153. +}
  62154. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  62155. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  62156. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-02-07 19:57:30.000000000 +0100
  62157. @@ -0,0 +1,1464 @@
  62158. +/* ==========================================================================
  62159. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  62160. + * $Revision: #123 $
  62161. + * $Date: 2012/08/10 $
  62162. + * $Change: 2047372 $
  62163. + *
  62164. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  62165. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  62166. + * otherwise expressly agreed to in writing between Synopsys and you.
  62167. + *
  62168. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  62169. + * any End User Software License Agreement or Agreement for Licensed Product
  62170. + * with Synopsys or any supplement thereto. You are permitted to use and
  62171. + * redistribute this Software in source and binary forms, with or without
  62172. + * modification, provided that redistributions of source code must retain this
  62173. + * notice. You may not view, use, disclose, copy or distribute this file or
  62174. + * any information contained herein except pursuant to this license grant from
  62175. + * Synopsys. If you do not agree with this notice, including the disclaimer
  62176. + * below, then you are not authorized to use the Software.
  62177. + *
  62178. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  62179. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62180. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62181. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  62182. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62183. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62184. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  62185. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62186. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62187. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62188. + * DAMAGE.
  62189. + * ========================================================================== */
  62190. +
  62191. +#if !defined(__DWC_CIL_H__)
  62192. +#define __DWC_CIL_H__
  62193. +
  62194. +#include "dwc_list.h"
  62195. +#include "dwc_otg_dbg.h"
  62196. +#include "dwc_otg_regs.h"
  62197. +
  62198. +#include "dwc_otg_core_if.h"
  62199. +#include "dwc_otg_adp.h"
  62200. +
  62201. +/**
  62202. + * @file
  62203. + * This file contains the interface to the Core Interface Layer.
  62204. + */
  62205. +
  62206. +#ifdef DWC_UTE_CFI
  62207. +
  62208. +#define MAX_DMA_DESCS_PER_EP 256
  62209. +
  62210. +/**
  62211. + * Enumeration for the data buffer mode
  62212. + */
  62213. +typedef enum _data_buffer_mode {
  62214. + BM_STANDARD = 0, /* data buffer is in normal mode */
  62215. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  62216. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  62217. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  62218. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  62219. +} data_buffer_mode_e;
  62220. +#endif //DWC_UTE_CFI
  62221. +
  62222. +/** Macros defined for DWC OTG HW Release version */
  62223. +
  62224. +#define OTG_CORE_REV_2_60a 0x4F54260A
  62225. +#define OTG_CORE_REV_2_71a 0x4F54271A
  62226. +#define OTG_CORE_REV_2_72a 0x4F54272A
  62227. +#define OTG_CORE_REV_2_80a 0x4F54280A
  62228. +#define OTG_CORE_REV_2_81a 0x4F54281A
  62229. +#define OTG_CORE_REV_2_90a 0x4F54290A
  62230. +#define OTG_CORE_REV_2_91a 0x4F54291A
  62231. +#define OTG_CORE_REV_2_92a 0x4F54292A
  62232. +#define OTG_CORE_REV_2_93a 0x4F54293A
  62233. +#define OTG_CORE_REV_2_94a 0x4F54294A
  62234. +#define OTG_CORE_REV_3_00a 0x4F54300A
  62235. +
  62236. +/**
  62237. + * Information for each ISOC packet.
  62238. + */
  62239. +typedef struct iso_pkt_info {
  62240. + uint32_t offset;
  62241. + uint32_t length;
  62242. + int32_t status;
  62243. +} iso_pkt_info_t;
  62244. +
  62245. +/**
  62246. + * The <code>dwc_ep</code> structure represents the state of a single
  62247. + * endpoint when acting in device mode. It contains the data items
  62248. + * needed for an endpoint to be activated and transfer packets.
  62249. + */
  62250. +typedef struct dwc_ep {
  62251. + /** EP number used for register address lookup */
  62252. + uint8_t num;
  62253. + /** EP direction 0 = OUT */
  62254. + unsigned is_in:1;
  62255. + /** EP active. */
  62256. + unsigned active:1;
  62257. +
  62258. + /**
  62259. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  62260. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  62261. + unsigned tx_fifo_num:4;
  62262. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  62263. + unsigned type:2;
  62264. +#define DWC_OTG_EP_TYPE_CONTROL 0
  62265. +#define DWC_OTG_EP_TYPE_ISOC 1
  62266. +#define DWC_OTG_EP_TYPE_BULK 2
  62267. +#define DWC_OTG_EP_TYPE_INTR 3
  62268. +
  62269. + /** DATA start PID for INTR and BULK EP */
  62270. + unsigned data_pid_start:1;
  62271. + /** Frame (even/odd) for ISOC EP */
  62272. + unsigned even_odd_frame:1;
  62273. + /** Max Packet bytes */
  62274. + unsigned maxpacket:11;
  62275. +
  62276. + /** Max Transfer size */
  62277. + uint32_t maxxfer;
  62278. +
  62279. + /** @name Transfer state */
  62280. + /** @{ */
  62281. +
  62282. + /**
  62283. + * Pointer to the beginning of the transfer buffer -- do not modify
  62284. + * during transfer.
  62285. + */
  62286. +
  62287. + dwc_dma_t dma_addr;
  62288. +
  62289. + dwc_dma_t dma_desc_addr;
  62290. + dwc_otg_dev_dma_desc_t *desc_addr;
  62291. +
  62292. + uint8_t *start_xfer_buff;
  62293. + /** pointer to the transfer buffer */
  62294. + uint8_t *xfer_buff;
  62295. + /** Number of bytes to transfer */
  62296. + unsigned xfer_len:19;
  62297. + /** Number of bytes transferred. */
  62298. + unsigned xfer_count:19;
  62299. + /** Sent ZLP */
  62300. + unsigned sent_zlp:1;
  62301. + /** Total len for control transfer */
  62302. + unsigned total_len:19;
  62303. +
  62304. + /** stall clear flag */
  62305. + unsigned stall_clear_flag:1;
  62306. +
  62307. + /** SETUP pkt cnt rollover flag for EP0 out*/
  62308. + unsigned stp_rollover;
  62309. +
  62310. +#ifdef DWC_UTE_CFI
  62311. + /* The buffer mode */
  62312. + data_buffer_mode_e buff_mode;
  62313. +
  62314. + /* The chain of DMA descriptors.
  62315. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  62316. + */
  62317. + dwc_otg_dma_desc_t *descs;
  62318. +
  62319. + /* The DMA address of the descriptors chain start */
  62320. + dma_addr_t descs_dma_addr;
  62321. + /** This variable stores the length of the last enqueued request */
  62322. + uint32_t cfi_req_len;
  62323. +#endif //DWC_UTE_CFI
  62324. +
  62325. +/** Max DMA Descriptor count for any EP */
  62326. +#define MAX_DMA_DESC_CNT 256
  62327. + /** Allocated DMA Desc count */
  62328. + uint32_t desc_cnt;
  62329. +
  62330. + /** bInterval */
  62331. + uint32_t bInterval;
  62332. + /** Next frame num to setup next ISOC transfer */
  62333. + uint32_t frame_num;
  62334. + /** Indicates SOF number overrun in DSTS */
  62335. + uint8_t frm_overrun;
  62336. +
  62337. +#ifdef DWC_UTE_PER_IO
  62338. + /** Next frame num for which will be setup DMA Desc */
  62339. + uint32_t xiso_frame_num;
  62340. + /** bInterval */
  62341. + uint32_t xiso_bInterval;
  62342. + /** Count of currently active transfers - shall be either 0 or 1 */
  62343. + int xiso_active_xfers;
  62344. + int xiso_queued_xfers;
  62345. +#endif
  62346. +#ifdef DWC_EN_ISOC
  62347. + /**
  62348. + * Variables specific for ISOC EPs
  62349. + *
  62350. + */
  62351. + /** DMA addresses of ISOC buffers */
  62352. + dwc_dma_t dma_addr0;
  62353. + dwc_dma_t dma_addr1;
  62354. +
  62355. + dwc_dma_t iso_dma_desc_addr;
  62356. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  62357. +
  62358. + /** pointer to the transfer buffers */
  62359. + uint8_t *xfer_buff0;
  62360. + uint8_t *xfer_buff1;
  62361. +
  62362. + /** number of ISOC Buffer is processing */
  62363. + uint32_t proc_buf_num;
  62364. + /** Interval of ISOC Buffer processing */
  62365. + uint32_t buf_proc_intrvl;
  62366. + /** Data size for regular frame */
  62367. + uint32_t data_per_frame;
  62368. +
  62369. + /* todo - pattern data support is to be implemented in the future */
  62370. + /** Data size for pattern frame */
  62371. + uint32_t data_pattern_frame;
  62372. + /** Frame number of pattern data */
  62373. + uint32_t sync_frame;
  62374. +
  62375. + /** bInterval */
  62376. + uint32_t bInterval;
  62377. + /** ISO Packet number per frame */
  62378. + uint32_t pkt_per_frm;
  62379. + /** Next frame num for which will be setup DMA Desc */
  62380. + uint32_t next_frame;
  62381. + /** Number of packets per buffer processing */
  62382. + uint32_t pkt_cnt;
  62383. + /** Info for all isoc packets */
  62384. + iso_pkt_info_t *pkt_info;
  62385. + /** current pkt number */
  62386. + uint32_t cur_pkt;
  62387. + /** current pkt number */
  62388. + uint8_t *cur_pkt_addr;
  62389. + /** current pkt number */
  62390. + uint32_t cur_pkt_dma_addr;
  62391. +#endif /* DWC_EN_ISOC */
  62392. +
  62393. +/** @} */
  62394. +} dwc_ep_t;
  62395. +
  62396. +/*
  62397. + * Reasons for halting a host channel.
  62398. + */
  62399. +typedef enum dwc_otg_halt_status {
  62400. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  62401. + DWC_OTG_HC_XFER_COMPLETE,
  62402. + DWC_OTG_HC_XFER_URB_COMPLETE,
  62403. + DWC_OTG_HC_XFER_ACK,
  62404. + DWC_OTG_HC_XFER_NAK,
  62405. + DWC_OTG_HC_XFER_NYET,
  62406. + DWC_OTG_HC_XFER_STALL,
  62407. + DWC_OTG_HC_XFER_XACT_ERR,
  62408. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  62409. + DWC_OTG_HC_XFER_BABBLE_ERR,
  62410. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  62411. + DWC_OTG_HC_XFER_AHB_ERR,
  62412. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  62413. + DWC_OTG_HC_XFER_URB_DEQUEUE
  62414. +} dwc_otg_halt_status_e;
  62415. +
  62416. +/**
  62417. + * Host channel descriptor. This structure represents the state of a single
  62418. + * host channel when acting in host mode. It contains the data items needed to
  62419. + * transfer packets to an endpoint via a host channel.
  62420. + */
  62421. +typedef struct dwc_hc {
  62422. + /** Host channel number used for register address lookup */
  62423. + uint8_t hc_num;
  62424. +
  62425. + /** Device to access */
  62426. + unsigned dev_addr:7;
  62427. +
  62428. + /** EP to access */
  62429. + unsigned ep_num:4;
  62430. +
  62431. + /** EP direction. 0: OUT, 1: IN */
  62432. + unsigned ep_is_in:1;
  62433. +
  62434. + /**
  62435. + * EP speed.
  62436. + * One of the following values:
  62437. + * - DWC_OTG_EP_SPEED_LOW
  62438. + * - DWC_OTG_EP_SPEED_FULL
  62439. + * - DWC_OTG_EP_SPEED_HIGH
  62440. + */
  62441. + unsigned speed:2;
  62442. +#define DWC_OTG_EP_SPEED_LOW 0
  62443. +#define DWC_OTG_EP_SPEED_FULL 1
  62444. +#define DWC_OTG_EP_SPEED_HIGH 2
  62445. +
  62446. + /**
  62447. + * Endpoint type.
  62448. + * One of the following values:
  62449. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  62450. + * - DWC_OTG_EP_TYPE_ISOC: 1
  62451. + * - DWC_OTG_EP_TYPE_BULK: 2
  62452. + * - DWC_OTG_EP_TYPE_INTR: 3
  62453. + */
  62454. + unsigned ep_type:2;
  62455. +
  62456. + /** Max packet size in bytes */
  62457. + unsigned max_packet:11;
  62458. +
  62459. + /**
  62460. + * PID for initial transaction.
  62461. + * 0: DATA0,<br>
  62462. + * 1: DATA2,<br>
  62463. + * 2: DATA1,<br>
  62464. + * 3: MDATA (non-Control EP),
  62465. + * SETUP (Control EP)
  62466. + */
  62467. + unsigned data_pid_start:2;
  62468. +#define DWC_OTG_HC_PID_DATA0 0
  62469. +#define DWC_OTG_HC_PID_DATA2 1
  62470. +#define DWC_OTG_HC_PID_DATA1 2
  62471. +#define DWC_OTG_HC_PID_MDATA 3
  62472. +#define DWC_OTG_HC_PID_SETUP 3
  62473. +
  62474. + /** Number of periodic transactions per (micro)frame */
  62475. + unsigned multi_count:2;
  62476. +
  62477. + /** @name Transfer State */
  62478. + /** @{ */
  62479. +
  62480. + /** Pointer to the current transfer buffer position. */
  62481. + uint8_t *xfer_buff;
  62482. + /**
  62483. + * In Buffer DMA mode this buffer will be used
  62484. + * if xfer_buff is not DWORD aligned.
  62485. + */
  62486. + dwc_dma_t align_buff;
  62487. + /** Total number of bytes to transfer. */
  62488. + uint32_t xfer_len;
  62489. + /** Number of bytes transferred so far. */
  62490. + uint32_t xfer_count;
  62491. + /** Packet count at start of transfer.*/
  62492. + uint16_t start_pkt_count;
  62493. +
  62494. + /**
  62495. + * Flag to indicate whether the transfer has been started. Set to 1 if
  62496. + * it has been started, 0 otherwise.
  62497. + */
  62498. + uint8_t xfer_started;
  62499. +
  62500. + /**
  62501. + * Set to 1 to indicate that a PING request should be issued on this
  62502. + * channel. If 0, process normally.
  62503. + */
  62504. + uint8_t do_ping;
  62505. +
  62506. + /**
  62507. + * Set to 1 to indicate that the error count for this transaction is
  62508. + * non-zero. Set to 0 if the error count is 0.
  62509. + */
  62510. + uint8_t error_state;
  62511. +
  62512. + /**
  62513. + * Set to 1 to indicate that this channel should be halted the next
  62514. + * time a request is queued for the channel. This is necessary in
  62515. + * slave mode if no request queue space is available when an attempt
  62516. + * is made to halt the channel.
  62517. + */
  62518. + uint8_t halt_on_queue;
  62519. +
  62520. + /**
  62521. + * Set to 1 if the host channel has been halted, but the core is not
  62522. + * finished flushing queued requests. Otherwise 0.
  62523. + */
  62524. + uint8_t halt_pending;
  62525. +
  62526. + /**
  62527. + * Reason for halting the host channel.
  62528. + */
  62529. + dwc_otg_halt_status_e halt_status;
  62530. +
  62531. + /*
  62532. + * Split settings for the host channel
  62533. + */
  62534. + uint8_t do_split; /**< Enable split for the channel */
  62535. + uint8_t complete_split; /**< Enable complete split */
  62536. + uint8_t hub_addr; /**< Address of high speed hub */
  62537. +
  62538. + uint8_t port_addr; /**< Port of the low/full speed device */
  62539. + /** Split transaction position
  62540. + * One of the following values:
  62541. + * - DWC_HCSPLIT_XACTPOS_MID
  62542. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  62543. + * - DWC_HCSPLIT_XACTPOS_END
  62544. + * - DWC_HCSPLIT_XACTPOS_ALL */
  62545. + uint8_t xact_pos;
  62546. +
  62547. + /** Set when the host channel does a short read. */
  62548. + uint8_t short_read;
  62549. +
  62550. + /**
  62551. + * Number of requests issued for this channel since it was assigned to
  62552. + * the current transfer (not counting PINGs).
  62553. + */
  62554. + uint8_t requests;
  62555. +
  62556. + /**
  62557. + * Queue Head for the transfer being processed by this channel.
  62558. + */
  62559. + struct dwc_otg_qh *qh;
  62560. +
  62561. + /** @} */
  62562. +
  62563. + /** Entry in list of host channels. */
  62564. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  62565. +
  62566. + /** @name Descriptor DMA support */
  62567. + /** @{ */
  62568. +
  62569. + /** Number of Transfer Descriptors */
  62570. + uint16_t ntd;
  62571. +
  62572. + /** Descriptor List DMA address */
  62573. + dwc_dma_t desc_list_addr;
  62574. +
  62575. + /** Scheduling micro-frame bitmap. */
  62576. + uint8_t schinfo;
  62577. +
  62578. + /** @} */
  62579. +} dwc_hc_t;
  62580. +
  62581. +/**
  62582. + * The following parameters may be specified when starting the module. These
  62583. + * parameters define how the DWC_otg controller should be configured.
  62584. + */
  62585. +typedef struct dwc_otg_core_params {
  62586. + int32_t opt;
  62587. +
  62588. + /**
  62589. + * Specifies the OTG capabilities. The driver will automatically
  62590. + * detect the value for this parameter if none is specified.
  62591. + * 0 - HNP and SRP capable (default)
  62592. + * 1 - SRP Only capable
  62593. + * 2 - No HNP/SRP capable
  62594. + */
  62595. + int32_t otg_cap;
  62596. +
  62597. + /**
  62598. + * Specifies whether to use slave or DMA mode for accessing the data
  62599. + * FIFOs. The driver will automatically detect the value for this
  62600. + * parameter if none is specified.
  62601. + * 0 - Slave
  62602. + * 1 - DMA (default, if available)
  62603. + */
  62604. + int32_t dma_enable;
  62605. +
  62606. + /**
  62607. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  62608. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  62609. + * will automatically detect the value for this if none is specified.
  62610. + * 0 - address DMA
  62611. + * 1 - DMA Descriptor(default, if available)
  62612. + */
  62613. + int32_t dma_desc_enable;
  62614. + /** The DMA Burst size (applicable only for External DMA
  62615. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  62616. + */
  62617. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  62618. +
  62619. + /**
  62620. + * Specifies the maximum speed of operation in host and device mode.
  62621. + * The actual speed depends on the speed of the attached device and
  62622. + * the value of phy_type. The actual speed depends on the speed of the
  62623. + * attached device.
  62624. + * 0 - High Speed (default)
  62625. + * 1 - Full Speed
  62626. + */
  62627. + int32_t speed;
  62628. + /** Specifies whether low power mode is supported when attached
  62629. + * to a Full Speed or Low Speed device in host mode.
  62630. + * 0 - Don't support low power mode (default)
  62631. + * 1 - Support low power mode
  62632. + */
  62633. + int32_t host_support_fs_ls_low_power;
  62634. +
  62635. + /** Specifies the PHY clock rate in low power mode when connected to a
  62636. + * Low Speed device in host mode. This parameter is applicable only if
  62637. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  62638. + * then defaults to 6 MHZ otherwise 48 MHZ.
  62639. + *
  62640. + * 0 - 48 MHz
  62641. + * 1 - 6 MHz
  62642. + */
  62643. + int32_t host_ls_low_power_phy_clk;
  62644. +
  62645. + /**
  62646. + * 0 - Use cC FIFO size parameters
  62647. + * 1 - Allow dynamic FIFO sizing (default)
  62648. + */
  62649. + int32_t enable_dynamic_fifo;
  62650. +
  62651. + /** Total number of 4-byte words in the data FIFO memory. This
  62652. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  62653. + * Tx FIFOs.
  62654. + * 32 to 32768 (default 8192)
  62655. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  62656. + */
  62657. + int32_t data_fifo_size;
  62658. +
  62659. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  62660. + * FIFO sizing is enabled.
  62661. + * 16 to 32768 (default 1064)
  62662. + */
  62663. + int32_t dev_rx_fifo_size;
  62664. +
  62665. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  62666. + * when dynamic FIFO sizing is enabled.
  62667. + * 16 to 32768 (default 1024)
  62668. + */
  62669. + int32_t dev_nperio_tx_fifo_size;
  62670. +
  62671. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  62672. + * mode when dynamic FIFO sizing is enabled.
  62673. + * 4 to 768 (default 256)
  62674. + */
  62675. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  62676. +
  62677. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  62678. + * FIFO sizing is enabled.
  62679. + * 16 to 32768 (default 1024)
  62680. + */
  62681. + int32_t host_rx_fifo_size;
  62682. +
  62683. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  62684. + * when Dynamic FIFO sizing is enabled in the core.
  62685. + * 16 to 32768 (default 1024)
  62686. + */
  62687. + int32_t host_nperio_tx_fifo_size;
  62688. +
  62689. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  62690. + * FIFO sizing is enabled.
  62691. + * 16 to 32768 (default 1024)
  62692. + */
  62693. + int32_t host_perio_tx_fifo_size;
  62694. +
  62695. + /** The maximum transfer size supported in bytes.
  62696. + * 2047 to 65,535 (default 65,535)
  62697. + */
  62698. + int32_t max_transfer_size;
  62699. +
  62700. + /** The maximum number of packets in a transfer.
  62701. + * 15 to 511 (default 511)
  62702. + */
  62703. + int32_t max_packet_count;
  62704. +
  62705. + /** The number of host channel registers to use.
  62706. + * 1 to 16 (default 12)
  62707. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  62708. + */
  62709. + int32_t host_channels;
  62710. +
  62711. + /** The number of endpoints in addition to EP0 available for device
  62712. + * mode operations.
  62713. + * 1 to 15 (default 6 IN and OUT)
  62714. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  62715. + * endpoints in addition to EP0.
  62716. + */
  62717. + int32_t dev_endpoints;
  62718. +
  62719. + /**
  62720. + * Specifies the type of PHY interface to use. By default, the driver
  62721. + * will automatically detect the phy_type.
  62722. + *
  62723. + * 0 - Full Speed PHY
  62724. + * 1 - UTMI+ (default)
  62725. + * 2 - ULPI
  62726. + */
  62727. + int32_t phy_type;
  62728. +
  62729. + /**
  62730. + * Specifies the UTMI+ Data Width. This parameter is
  62731. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  62732. + * PHY_TYPE, this parameter indicates the data width between
  62733. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  62734. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  62735. + * to "8 and 16 bits", meaning that the core has been
  62736. + * configured to work at either data path width.
  62737. + *
  62738. + * 8 or 16 bits (default 16)
  62739. + */
  62740. + int32_t phy_utmi_width;
  62741. +
  62742. + /**
  62743. + * Specifies whether the ULPI operates at double or single
  62744. + * data rate. This parameter is only applicable if PHY_TYPE is
  62745. + * ULPI.
  62746. + *
  62747. + * 0 - single data rate ULPI interface with 8 bit wide data
  62748. + * bus (default)
  62749. + * 1 - double data rate ULPI interface with 4 bit wide data
  62750. + * bus
  62751. + */
  62752. + int32_t phy_ulpi_ddr;
  62753. +
  62754. + /**
  62755. + * Specifies whether to use the internal or external supply to
  62756. + * drive the vbus with a ULPI phy.
  62757. + */
  62758. + int32_t phy_ulpi_ext_vbus;
  62759. +
  62760. + /**
  62761. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  62762. + * parameter is only applicable if PHY_TYPE is FS.
  62763. + * 0 - No (default)
  62764. + * 1 - Yes
  62765. + */
  62766. + int32_t i2c_enable;
  62767. +
  62768. + int32_t ulpi_fs_ls;
  62769. +
  62770. + int32_t ts_dline;
  62771. +
  62772. + /**
  62773. + * Specifies whether dedicated transmit FIFOs are
  62774. + * enabled for non periodic IN endpoints in device mode
  62775. + * 0 - No
  62776. + * 1 - Yes
  62777. + */
  62778. + int32_t en_multiple_tx_fifo;
  62779. +
  62780. + /** Number of 4-byte words in each of the Tx FIFOs in device
  62781. + * mode when dynamic FIFO sizing is enabled.
  62782. + * 4 to 768 (default 256)
  62783. + */
  62784. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  62785. +
  62786. + /** Thresholding enable flag-
  62787. + * bit 0 - enable non-ISO Tx thresholding
  62788. + * bit 1 - enable ISO Tx thresholding
  62789. + * bit 2 - enable Rx thresholding
  62790. + */
  62791. + uint32_t thr_ctl;
  62792. +
  62793. + /** Thresholding length for Tx
  62794. + * FIFOs in 32 bit DWORDs
  62795. + */
  62796. + uint32_t tx_thr_length;
  62797. +
  62798. + /** Thresholding length for Rx
  62799. + * FIFOs in 32 bit DWORDs
  62800. + */
  62801. + uint32_t rx_thr_length;
  62802. +
  62803. + /**
  62804. + * Specifies whether LPM (Link Power Management) support is enabled
  62805. + */
  62806. + int32_t lpm_enable;
  62807. +
  62808. + /** Per Transfer Interrupt
  62809. + * mode enable flag
  62810. + * 1 - Enabled
  62811. + * 0 - Disabled
  62812. + */
  62813. + int32_t pti_enable;
  62814. +
  62815. + /** Multi Processor Interrupt
  62816. + * mode enable flag
  62817. + * 1 - Enabled
  62818. + * 0 - Disabled
  62819. + */
  62820. + int32_t mpi_enable;
  62821. +
  62822. + /** IS_USB Capability
  62823. + * 1 - Enabled
  62824. + * 0 - Disabled
  62825. + */
  62826. + int32_t ic_usb_cap;
  62827. +
  62828. + /** AHB Threshold Ratio
  62829. + * 2'b00 AHB Threshold = MAC Threshold
  62830. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  62831. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  62832. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  62833. + */
  62834. + int32_t ahb_thr_ratio;
  62835. +
  62836. + /** ADP Support
  62837. + * 1 - Enabled
  62838. + * 0 - Disabled
  62839. + */
  62840. + int32_t adp_supp_enable;
  62841. +
  62842. + /** HFIR Reload Control
  62843. + * 0 - The HFIR cannot be reloaded dynamically.
  62844. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  62845. + */
  62846. + int32_t reload_ctl;
  62847. +
  62848. + /** DCFG: Enable device Out NAK
  62849. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  62850. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  62851. + */
  62852. + int32_t dev_out_nak;
  62853. +
  62854. + /** DCFG: Enable Continue on BNA
  62855. + * After receiving BNA interrupt the core disables the endpoint,when the
  62856. + * endpoint is re-enabled by the application the core starts processing
  62857. + * 0 - from the DOEPDMA descriptor
  62858. + * 1 - from the descriptor which received the BNA.
  62859. + */
  62860. + int32_t cont_on_bna;
  62861. +
  62862. + /** GAHBCFG: AHB Single Support
  62863. + * This bit when programmed supports SINGLE transfers for remainder
  62864. + * data in a transfer for DMA mode of operation.
  62865. + * 0 - in this case the remainder data will be sent using INCR burst size.
  62866. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  62867. + */
  62868. + int32_t ahb_single;
  62869. +
  62870. + /** Core Power down mode
  62871. + * 0 - No Power Down is enabled
  62872. + * 1 - Reserved
  62873. + * 2 - Complete Power Down (Hibernation)
  62874. + */
  62875. + int32_t power_down;
  62876. +
  62877. + /** OTG revision supported
  62878. + * 0 - OTG 1.3 revision
  62879. + * 1 - OTG 2.0 revision
  62880. + */
  62881. + int32_t otg_ver;
  62882. +
  62883. +} dwc_otg_core_params_t;
  62884. +
  62885. +#ifdef DEBUG
  62886. +struct dwc_otg_core_if;
  62887. +typedef struct hc_xfer_info {
  62888. + struct dwc_otg_core_if *core_if;
  62889. + dwc_hc_t *hc;
  62890. +} hc_xfer_info_t;
  62891. +#endif
  62892. +
  62893. +typedef struct ep_xfer_info {
  62894. + struct dwc_otg_core_if *core_if;
  62895. + dwc_ep_t *ep;
  62896. + uint8_t state;
  62897. +} ep_xfer_info_t;
  62898. +/*
  62899. + * Device States
  62900. + */
  62901. +typedef enum dwc_otg_lx_state {
  62902. + /** On state */
  62903. + DWC_OTG_L0,
  62904. + /** LPM sleep state*/
  62905. + DWC_OTG_L1,
  62906. + /** USB suspend state*/
  62907. + DWC_OTG_L2,
  62908. + /** Off state*/
  62909. + DWC_OTG_L3
  62910. +} dwc_otg_lx_state_e;
  62911. +
  62912. +struct dwc_otg_global_regs_backup {
  62913. + uint32_t gotgctl_local;
  62914. + uint32_t gintmsk_local;
  62915. + uint32_t gahbcfg_local;
  62916. + uint32_t gusbcfg_local;
  62917. + uint32_t grxfsiz_local;
  62918. + uint32_t gnptxfsiz_local;
  62919. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62920. + uint32_t glpmcfg_local;
  62921. +#endif
  62922. + uint32_t gi2cctl_local;
  62923. + uint32_t hptxfsiz_local;
  62924. + uint32_t pcgcctl_local;
  62925. + uint32_t gdfifocfg_local;
  62926. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  62927. + uint32_t gpwrdn_local;
  62928. + uint32_t xhib_pcgcctl;
  62929. + uint32_t xhib_gpwrdn;
  62930. +};
  62931. +
  62932. +struct dwc_otg_host_regs_backup {
  62933. + uint32_t hcfg_local;
  62934. + uint32_t haintmsk_local;
  62935. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  62936. + uint32_t hprt0_local;
  62937. + uint32_t hfir_local;
  62938. +};
  62939. +
  62940. +struct dwc_otg_dev_regs_backup {
  62941. + uint32_t dcfg;
  62942. + uint32_t dctl;
  62943. + uint32_t daintmsk;
  62944. + uint32_t diepmsk;
  62945. + uint32_t doepmsk;
  62946. + uint32_t diepctl[MAX_EPS_CHANNELS];
  62947. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  62948. + uint32_t diepdma[MAX_EPS_CHANNELS];
  62949. +};
  62950. +/**
  62951. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  62952. + * the DWC_otg controller acting in either host or device mode. It
  62953. + * represents the programming view of the controller as a whole.
  62954. + */
  62955. +struct dwc_otg_core_if {
  62956. + /** Parameters that define how the core should be configured.*/
  62957. + dwc_otg_core_params_t *core_params;
  62958. +
  62959. + /** Core Global registers starting at offset 000h. */
  62960. + dwc_otg_core_global_regs_t *core_global_regs;
  62961. +
  62962. + /** Device-specific information */
  62963. + dwc_otg_dev_if_t *dev_if;
  62964. + /** Host-specific information */
  62965. + dwc_otg_host_if_t *host_if;
  62966. +
  62967. + /** Value from SNPSID register */
  62968. + uint32_t snpsid;
  62969. +
  62970. + /*
  62971. + * Set to 1 if the core PHY interface bits in USBCFG have been
  62972. + * initialized.
  62973. + */
  62974. + uint8_t phy_init_done;
  62975. +
  62976. + /*
  62977. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  62978. + */
  62979. + uint8_t srp_success;
  62980. + uint8_t srp_timer_started;
  62981. + /** Timer for SRP. If it expires before SRP is successful
  62982. + * clear the SRP. */
  62983. + dwc_timer_t *srp_timer;
  62984. +
  62985. +#ifdef DWC_DEV_SRPCAP
  62986. + /* This timer is needed to power on the hibernated host core if SRP is not
  62987. + * initiated on connected SRP capable device for limited period of time
  62988. + */
  62989. + uint8_t pwron_timer_started;
  62990. + dwc_timer_t *pwron_timer;
  62991. +#endif
  62992. + /* Common configuration information */
  62993. + /** Power and Clock Gating Control Register */
  62994. + volatile uint32_t *pcgcctl;
  62995. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  62996. +
  62997. + /** Push/pop addresses for endpoints or host channels.*/
  62998. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  62999. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  63000. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  63001. +
  63002. + /** Total RAM for FIFOs (Bytes) */
  63003. + uint16_t total_fifo_size;
  63004. + /** Size of Rx FIFO (Bytes) */
  63005. + uint16_t rx_fifo_size;
  63006. + /** Size of Non-periodic Tx FIFO (Bytes) */
  63007. + uint16_t nperio_tx_fifo_size;
  63008. +
  63009. + /** 1 if DMA is enabled, 0 otherwise. */
  63010. + uint8_t dma_enable;
  63011. +
  63012. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  63013. + uint8_t dma_desc_enable;
  63014. +
  63015. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  63016. + uint8_t pti_enh_enable;
  63017. +
  63018. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  63019. + uint8_t multiproc_int_enable;
  63020. +
  63021. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  63022. + uint8_t en_multiple_tx_fifo;
  63023. +
  63024. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  63025. + * process of being queued */
  63026. + uint8_t queuing_high_bandwidth;
  63027. +
  63028. + /** Hardware Configuration -- stored here for convenience.*/
  63029. + hwcfg1_data_t hwcfg1;
  63030. + hwcfg2_data_t hwcfg2;
  63031. + hwcfg3_data_t hwcfg3;
  63032. + hwcfg4_data_t hwcfg4;
  63033. + fifosize_data_t hptxfsiz;
  63034. +
  63035. + /** Host and Device Configuration -- stored here for convenience.*/
  63036. + hcfg_data_t hcfg;
  63037. + dcfg_data_t dcfg;
  63038. +
  63039. + /** The operational State, during transations
  63040. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  63041. + * match the core but allows the software to determine
  63042. + * transitions.
  63043. + */
  63044. + uint8_t op_state;
  63045. +
  63046. + /**
  63047. + * Set to 1 if the HCD needs to be restarted on a session request
  63048. + * interrupt. This is required if no connector ID status change has
  63049. + * occurred since the HCD was last disconnected.
  63050. + */
  63051. + uint8_t restart_hcd_on_session_req;
  63052. +
  63053. + /** HCD callbacks */
  63054. + /** A-Device is a_host */
  63055. +#define A_HOST (1)
  63056. + /** A-Device is a_suspend */
  63057. +#define A_SUSPEND (2)
  63058. + /** A-Device is a_peripherial */
  63059. +#define A_PERIPHERAL (3)
  63060. + /** B-Device is operating as a Peripheral. */
  63061. +#define B_PERIPHERAL (4)
  63062. + /** B-Device is operating as a Host. */
  63063. +#define B_HOST (5)
  63064. +
  63065. + /** HCD callbacks */
  63066. + struct dwc_otg_cil_callbacks *hcd_cb;
  63067. + /** PCD callbacks */
  63068. + struct dwc_otg_cil_callbacks *pcd_cb;
  63069. +
  63070. + /** Device mode Periodic Tx FIFO Mask */
  63071. + uint32_t p_tx_msk;
  63072. + /** Device mode Periodic Tx FIFO Mask */
  63073. + uint32_t tx_msk;
  63074. +
  63075. + /** Workqueue object used for handling several interrupts */
  63076. + dwc_workq_t *wq_otg;
  63077. +
  63078. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  63079. + dwc_timer_t *wkp_timer;
  63080. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  63081. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  63082. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  63083. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  63084. +#ifdef DEBUG
  63085. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  63086. +
  63087. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  63088. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  63089. +
  63090. + uint32_t hfnum_7_samples;
  63091. + uint64_t hfnum_7_frrem_accum;
  63092. + uint32_t hfnum_0_samples;
  63093. + uint64_t hfnum_0_frrem_accum;
  63094. + uint32_t hfnum_other_samples;
  63095. + uint64_t hfnum_other_frrem_accum;
  63096. +#endif
  63097. +
  63098. +#ifdef DWC_UTE_CFI
  63099. + uint16_t pwron_rxfsiz;
  63100. + uint16_t pwron_gnptxfsiz;
  63101. + uint16_t pwron_txfsiz[15];
  63102. +
  63103. + uint16_t init_rxfsiz;
  63104. + uint16_t init_gnptxfsiz;
  63105. + uint16_t init_txfsiz[15];
  63106. +#endif
  63107. +
  63108. + /** Lx state of device */
  63109. + dwc_otg_lx_state_e lx_state;
  63110. +
  63111. + /** Saved Core Global registers */
  63112. + struct dwc_otg_global_regs_backup *gr_backup;
  63113. + /** Saved Host registers */
  63114. + struct dwc_otg_host_regs_backup *hr_backup;
  63115. + /** Saved Device registers */
  63116. + struct dwc_otg_dev_regs_backup *dr_backup;
  63117. +
  63118. + /** Power Down Enable */
  63119. + uint32_t power_down;
  63120. +
  63121. + /** ADP support Enable */
  63122. + uint32_t adp_enable;
  63123. +
  63124. + /** ADP structure object */
  63125. + dwc_otg_adp_t adp;
  63126. +
  63127. + /** hibernation/suspend flag */
  63128. + int hibernation_suspend;
  63129. +
  63130. + /** Device mode extended hibernation flag */
  63131. + int xhib;
  63132. +
  63133. + /** OTG revision supported */
  63134. + uint32_t otg_ver;
  63135. +
  63136. + /** OTG status flag used for HNP polling */
  63137. + uint8_t otg_sts;
  63138. +
  63139. + /** Pointer to either hcd->lock or pcd->lock */
  63140. + dwc_spinlock_t *lock;
  63141. +
  63142. + /** Start predict NextEP based on Learning Queue if equal 1,
  63143. + * also used as counter of disabled NP IN EP's */
  63144. + uint8_t start_predict;
  63145. +
  63146. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  63147. + * active, 0xff otherwise */
  63148. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  63149. +
  63150. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  63151. + uint8_t first_in_nextep_seq;
  63152. +
  63153. + /** Frame number while entering to ISR - needed for ISOCs **/
  63154. + uint32_t frame_num;
  63155. +
  63156. +};
  63157. +
  63158. +#ifdef DEBUG
  63159. +/*
  63160. + * This function is called when transfer is timed out.
  63161. + */
  63162. +extern void hc_xfer_timeout(void *ptr);
  63163. +#endif
  63164. +
  63165. +/*
  63166. + * This function is called when transfer is timed out on endpoint.
  63167. + */
  63168. +extern void ep_xfer_timeout(void *ptr);
  63169. +
  63170. +/*
  63171. + * The following functions are functions for works
  63172. + * using during handling some interrupts
  63173. + */
  63174. +extern void w_conn_id_status_change(void *p);
  63175. +
  63176. +extern void w_wakeup_detected(void *p);
  63177. +
  63178. +/** Saves global register values into system memory. */
  63179. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  63180. +/** Saves device register values into system memory. */
  63181. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  63182. +/** Saves host register values into system memory. */
  63183. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  63184. +/** Restore global register values. */
  63185. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  63186. +/** Restore host register values. */
  63187. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  63188. +/** Restore device register values. */
  63189. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  63190. + int rem_wakeup);
  63191. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  63192. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  63193. + int is_host);
  63194. +
  63195. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  63196. + int restore_mode, int reset);
  63197. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  63198. + int rem_wakeup, int reset);
  63199. +
  63200. +/*
  63201. + * The following functions support initialization of the CIL driver component
  63202. + * and the DWC_otg controller.
  63203. + */
  63204. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  63205. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  63206. +
  63207. +/** @name Device CIL Functions
  63208. + * The following functions support managing the DWC_otg controller in device
  63209. + * mode.
  63210. + */
  63211. +/**@{*/
  63212. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  63213. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  63214. + uint32_t * _dest);
  63215. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  63216. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63217. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63218. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63219. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  63220. + dwc_ep_t * _ep);
  63221. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  63222. + dwc_ep_t * _ep);
  63223. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  63224. + dwc_ep_t * _ep);
  63225. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  63226. + dwc_ep_t * _ep);
  63227. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  63228. + dwc_ep_t * _ep, int _dma);
  63229. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63230. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  63231. + dwc_ep_t * _ep);
  63232. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  63233. +
  63234. +#ifdef DWC_EN_ISOC
  63235. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  63236. + dwc_ep_t * ep);
  63237. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  63238. + dwc_ep_t * ep);
  63239. +#endif /* DWC_EN_ISOC */
  63240. +/**@}*/
  63241. +
  63242. +/** @name Host CIL Functions
  63243. + * The following functions support managing the DWC_otg controller in host
  63244. + * mode.
  63245. + */
  63246. +/**@{*/
  63247. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63248. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  63249. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  63250. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63251. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  63252. + dwc_hc_t * _hc);
  63253. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  63254. + dwc_hc_t * _hc);
  63255. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63256. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  63257. + dwc_hc_t * _hc);
  63258. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63259. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63260. +
  63261. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  63262. + dwc_hc_t * hc);
  63263. +
  63264. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  63265. +
  63266. +/* Macro used to clear one channel interrupt */
  63267. +#define clear_hc_int(_hc_regs_, _intr_) \
  63268. +do { \
  63269. + hcint_data_t hcint_clear = {.d32 = 0}; \
  63270. + hcint_clear.b._intr_ = 1; \
  63271. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  63272. +} while (0)
  63273. +
  63274. +/*
  63275. + * Macro used to disable one channel interrupt. Channel interrupts are
  63276. + * disabled when the channel is halted or released by the interrupt handler.
  63277. + * There is no need to handle further interrupts of that type until the
  63278. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  63279. + * because the channel structures are cleaned up when the channel is released.
  63280. + */
  63281. +#define disable_hc_int(_hc_regs_, _intr_) \
  63282. +do { \
  63283. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  63284. + hcintmsk.b._intr_ = 1; \
  63285. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  63286. +} while (0)
  63287. +
  63288. +/**
  63289. + * This function Reads HPRT0 in preparation to modify. It keeps the
  63290. + * WC bits 0 so that if they are read as 1, they won't clear when you
  63291. + * write it back
  63292. + */
  63293. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  63294. +{
  63295. + hprt0_data_t hprt0;
  63296. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  63297. + hprt0.b.prtena = 0;
  63298. + hprt0.b.prtconndet = 0;
  63299. + hprt0.b.prtenchng = 0;
  63300. + hprt0.b.prtovrcurrchng = 0;
  63301. + return hprt0.d32;
  63302. +}
  63303. +
  63304. +/**@}*/
  63305. +
  63306. +/** @name Common CIL Functions
  63307. + * The following functions support managing the DWC_otg controller in either
  63308. + * device or host mode.
  63309. + */
  63310. +/**@{*/
  63311. +
  63312. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  63313. + uint8_t * dest, uint16_t bytes);
  63314. +
  63315. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  63316. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  63317. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  63318. +
  63319. +/**
  63320. + * This function returns the Core Interrupt register.
  63321. + */
  63322. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  63323. +{
  63324. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  63325. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  63326. +}
  63327. +
  63328. +/**
  63329. + * This function returns the OTG Interrupt register.
  63330. + */
  63331. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  63332. +{
  63333. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  63334. +}
  63335. +
  63336. +/**
  63337. + * This function reads the Device All Endpoints Interrupt register and
  63338. + * returns the IN endpoint interrupt bits.
  63339. + */
  63340. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  63341. + core_if)
  63342. +{
  63343. +
  63344. + uint32_t v;
  63345. +
  63346. + if (core_if->multiproc_int_enable) {
  63347. + v = DWC_READ_REG32(&core_if->dev_if->
  63348. + dev_global_regs->deachint) &
  63349. + DWC_READ_REG32(&core_if->
  63350. + dev_if->dev_global_regs->deachintmsk);
  63351. + } else {
  63352. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63353. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63354. + }
  63355. + return (v & 0xffff);
  63356. +}
  63357. +
  63358. +/**
  63359. + * This function reads the Device All Endpoints Interrupt register and
  63360. + * returns the OUT endpoint interrupt bits.
  63361. + */
  63362. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  63363. + core_if)
  63364. +{
  63365. + uint32_t v;
  63366. +
  63367. + if (core_if->multiproc_int_enable) {
  63368. + v = DWC_READ_REG32(&core_if->dev_if->
  63369. + dev_global_regs->deachint) &
  63370. + DWC_READ_REG32(&core_if->
  63371. + dev_if->dev_global_regs->deachintmsk);
  63372. + } else {
  63373. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63374. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63375. + }
  63376. +
  63377. + return ((v & 0xffff0000) >> 16);
  63378. +}
  63379. +
  63380. +/**
  63381. + * This function returns the Device IN EP Interrupt register
  63382. + */
  63383. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  63384. + dwc_ep_t * ep)
  63385. +{
  63386. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  63387. + uint32_t v, msk, emp;
  63388. +
  63389. + if (core_if->multiproc_int_enable) {
  63390. + msk =
  63391. + DWC_READ_REG32(&dev_if->
  63392. + dev_global_regs->diepeachintmsk[ep->num]);
  63393. + emp =
  63394. + DWC_READ_REG32(&dev_if->
  63395. + dev_global_regs->dtknqr4_fifoemptymsk);
  63396. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63397. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63398. + } else {
  63399. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  63400. + emp =
  63401. + DWC_READ_REG32(&dev_if->
  63402. + dev_global_regs->dtknqr4_fifoemptymsk);
  63403. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63404. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63405. + }
  63406. +
  63407. + return v;
  63408. +}
  63409. +
  63410. +/**
  63411. + * This function returns the Device OUT EP Interrupt register
  63412. + */
  63413. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  63414. + _core_if, dwc_ep_t * _ep)
  63415. +{
  63416. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  63417. + uint32_t v;
  63418. + doepmsk_data_t msk = {.d32 = 0 };
  63419. +
  63420. + if (_core_if->multiproc_int_enable) {
  63421. + msk.d32 =
  63422. + DWC_READ_REG32(&dev_if->
  63423. + dev_global_regs->doepeachintmsk[_ep->num]);
  63424. + if (_core_if->pti_enh_enable) {
  63425. + msk.b.pktdrpsts = 1;
  63426. + }
  63427. + v = DWC_READ_REG32(&dev_if->
  63428. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63429. + } else {
  63430. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  63431. + if (_core_if->pti_enh_enable) {
  63432. + msk.b.pktdrpsts = 1;
  63433. + }
  63434. + v = DWC_READ_REG32(&dev_if->
  63435. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63436. + }
  63437. + return v;
  63438. +}
  63439. +
  63440. +/**
  63441. + * This function returns the Host All Channel Interrupt register
  63442. + */
  63443. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  63444. + _core_if)
  63445. +{
  63446. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  63447. +}
  63448. +
  63449. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  63450. + _core_if, dwc_hc_t * _hc)
  63451. +{
  63452. + return (DWC_READ_REG32
  63453. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  63454. +}
  63455. +
  63456. +/**
  63457. + * This function returns the mode of the operation, host or device.
  63458. + *
  63459. + * @return 0 - Device Mode, 1 - Host Mode
  63460. + */
  63461. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  63462. +{
  63463. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  63464. +}
  63465. +
  63466. +/**@}*/
  63467. +
  63468. +/**
  63469. + * DWC_otg CIL callback structure. This structure allows the HCD and
  63470. + * PCD to register functions used for starting and stopping the PCD
  63471. + * and HCD for role change on for a DRD.
  63472. + */
  63473. +typedef struct dwc_otg_cil_callbacks {
  63474. + /** Start function for role change */
  63475. + int (*start) (void *_p);
  63476. + /** Stop Function for role change */
  63477. + int (*stop) (void *_p);
  63478. + /** Disconnect Function for role change */
  63479. + int (*disconnect) (void *_p);
  63480. + /** Resume/Remote wakeup Function */
  63481. + int (*resume_wakeup) (void *_p);
  63482. + /** Suspend function */
  63483. + int (*suspend) (void *_p);
  63484. + /** Session Start (SRP) */
  63485. + int (*session_start) (void *_p);
  63486. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63487. + /** Sleep (switch to L0 state) */
  63488. + int (*sleep) (void *_p);
  63489. +#endif
  63490. + /** Pointer passed to start() and stop() */
  63491. + void *p;
  63492. +} dwc_otg_cil_callbacks_t;
  63493. +
  63494. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  63495. + dwc_otg_cil_callbacks_t * _cb,
  63496. + void *_p);
  63497. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  63498. + dwc_otg_cil_callbacks_t * _cb,
  63499. + void *_p);
  63500. +
  63501. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  63502. +
  63503. +//////////////////////////////////////////////////////////////////////
  63504. +/** Start the HCD. Helper function for using the HCD callbacks.
  63505. + *
  63506. + * @param core_if Programming view of DWC_otg controller.
  63507. + */
  63508. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  63509. +{
  63510. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  63511. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  63512. + }
  63513. +}
  63514. +
  63515. +/** Stop the HCD. Helper function for using the HCD callbacks.
  63516. + *
  63517. + * @param core_if Programming view of DWC_otg controller.
  63518. + */
  63519. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  63520. +{
  63521. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  63522. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  63523. + }
  63524. +}
  63525. +
  63526. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  63527. + *
  63528. + * @param core_if Programming view of DWC_otg controller.
  63529. + */
  63530. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  63531. +{
  63532. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  63533. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  63534. + }
  63535. +}
  63536. +
  63537. +/** Inform the HCD the a New Session has begun. Helper function for
  63538. + * using the HCD callbacks.
  63539. + *
  63540. + * @param core_if Programming view of DWC_otg controller.
  63541. + */
  63542. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  63543. +{
  63544. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  63545. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  63546. + }
  63547. +}
  63548. +
  63549. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63550. +/**
  63551. + * Inform the HCD about LPM sleep.
  63552. + * Helper function for using the HCD callbacks.
  63553. + *
  63554. + * @param core_if Programming view of DWC_otg controller.
  63555. + */
  63556. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  63557. +{
  63558. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  63559. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  63560. + }
  63561. +}
  63562. +#endif
  63563. +
  63564. +/** Resume the HCD. Helper function for using the HCD callbacks.
  63565. + *
  63566. + * @param core_if Programming view of DWC_otg controller.
  63567. + */
  63568. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  63569. +{
  63570. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  63571. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  63572. + }
  63573. +}
  63574. +
  63575. +/** Start the PCD. Helper function for using the PCD callbacks.
  63576. + *
  63577. + * @param core_if Programming view of DWC_otg controller.
  63578. + */
  63579. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  63580. +{
  63581. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  63582. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  63583. + }
  63584. +}
  63585. +
  63586. +/** Stop the PCD. Helper function for using the PCD callbacks.
  63587. + *
  63588. + * @param core_if Programming view of DWC_otg controller.
  63589. + */
  63590. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  63591. +{
  63592. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  63593. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  63594. + }
  63595. +}
  63596. +
  63597. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  63598. + *
  63599. + * @param core_if Programming view of DWC_otg controller.
  63600. + */
  63601. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  63602. +{
  63603. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  63604. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  63605. + }
  63606. +}
  63607. +
  63608. +/** Resume the PCD. Helper function for using the PCD callbacks.
  63609. + *
  63610. + * @param core_if Programming view of DWC_otg controller.
  63611. + */
  63612. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  63613. +{
  63614. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  63615. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  63616. + }
  63617. +}
  63618. +
  63619. +//////////////////////////////////////////////////////////////////////
  63620. +
  63621. +#endif
  63622. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  63623. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  63624. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-02-07 19:57:30.000000000 +0100
  63625. @@ -0,0 +1,1588 @@
  63626. +/* ==========================================================================
  63627. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  63628. + * $Revision: #32 $
  63629. + * $Date: 2012/08/10 $
  63630. + * $Change: 2047372 $
  63631. + *
  63632. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63633. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63634. + * otherwise expressly agreed to in writing between Synopsys and you.
  63635. + *
  63636. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63637. + * any End User Software License Agreement or Agreement for Licensed Product
  63638. + * with Synopsys or any supplement thereto. You are permitted to use and
  63639. + * redistribute this Software in source and binary forms, with or without
  63640. + * modification, provided that redistributions of source code must retain this
  63641. + * notice. You may not view, use, disclose, copy or distribute this file or
  63642. + * any information contained herein except pursuant to this license grant from
  63643. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63644. + * below, then you are not authorized to use the Software.
  63645. + *
  63646. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63647. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63648. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63649. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63650. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63651. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63652. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63653. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63654. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63655. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63656. + * DAMAGE.
  63657. + * ========================================================================== */
  63658. +
  63659. +/** @file
  63660. + *
  63661. + * The Core Interface Layer provides basic services for accessing and
  63662. + * managing the DWC_otg hardware. These services are used by both the
  63663. + * Host Controller Driver and the Peripheral Controller Driver.
  63664. + *
  63665. + * This file contains the Common Interrupt handlers.
  63666. + */
  63667. +#include "dwc_os.h"
  63668. +#include "dwc_otg_regs.h"
  63669. +#include "dwc_otg_cil.h"
  63670. +#include "dwc_otg_driver.h"
  63671. +#include "dwc_otg_pcd.h"
  63672. +#include "dwc_otg_hcd.h"
  63673. +#include "dwc_otg_mphi_fix.h"
  63674. +
  63675. +#ifdef DEBUG
  63676. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  63677. +{
  63678. + return (core_if->op_state == A_HOST ? "a_host" :
  63679. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  63680. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  63681. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  63682. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  63683. +}
  63684. +#endif
  63685. +
  63686. +/** This function will log a debug message
  63687. + *
  63688. + * @param core_if Programming view of DWC_otg controller.
  63689. + */
  63690. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  63691. +{
  63692. + gintsts_data_t gintsts;
  63693. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  63694. + dwc_otg_mode(core_if) ? "Host" : "Device");
  63695. +
  63696. + /* Clear interrupt */
  63697. + gintsts.d32 = 0;
  63698. + gintsts.b.modemismatch = 1;
  63699. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63700. + return 1;
  63701. +}
  63702. +
  63703. +/**
  63704. + * This function handles the OTG Interrupts. It reads the OTG
  63705. + * Interrupt Register (GOTGINT) to determine what interrupt has
  63706. + * occurred.
  63707. + *
  63708. + * @param core_if Programming view of DWC_otg controller.
  63709. + */
  63710. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  63711. +{
  63712. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  63713. + gotgint_data_t gotgint;
  63714. + gotgctl_data_t gotgctl;
  63715. + gintmsk_data_t gintmsk;
  63716. + gpwrdn_data_t gpwrdn;
  63717. +
  63718. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  63719. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63720. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  63721. + op_state_str(core_if));
  63722. +
  63723. + if (gotgint.b.sesenddet) {
  63724. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63725. + "Session End Detected++ (%s)\n",
  63726. + op_state_str(core_if));
  63727. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63728. +
  63729. + if (core_if->op_state == B_HOST) {
  63730. + cil_pcd_start(core_if);
  63731. + core_if->op_state = B_PERIPHERAL;
  63732. + } else {
  63733. + /* If not B_HOST and Device HNP still set. HNP
  63734. + * Did not succeed!*/
  63735. + if (gotgctl.b.devhnpen) {
  63736. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  63737. + __DWC_ERROR("Device Not Connected/Responding!\n");
  63738. + }
  63739. +
  63740. + /* If Session End Detected the B-Cable has
  63741. + * been disconnected. */
  63742. + /* Reset PCD and Gadget driver to a
  63743. + * clean state. */
  63744. + core_if->lx_state = DWC_OTG_L0;
  63745. + DWC_SPINUNLOCK(core_if->lock);
  63746. + cil_pcd_stop(core_if);
  63747. + DWC_SPINLOCK(core_if->lock);
  63748. +
  63749. + if (core_if->adp_enable) {
  63750. + if (core_if->power_down == 2) {
  63751. + gpwrdn.d32 = 0;
  63752. + gpwrdn.b.pwrdnswtch = 1;
  63753. + DWC_MODIFY_REG32(&core_if->
  63754. + core_global_regs->
  63755. + gpwrdn, gpwrdn.d32, 0);
  63756. + }
  63757. +
  63758. + gpwrdn.d32 = 0;
  63759. + gpwrdn.b.pmuintsel = 1;
  63760. + gpwrdn.b.pmuactv = 1;
  63761. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  63762. + gpwrdn, 0, gpwrdn.d32);
  63763. +
  63764. + dwc_otg_adp_sense_start(core_if);
  63765. + }
  63766. + }
  63767. +
  63768. + gotgctl.d32 = 0;
  63769. + gotgctl.b.devhnpen = 1;
  63770. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63771. + }
  63772. + if (gotgint.b.sesreqsucstschng) {
  63773. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63774. + "Session Reqeust Success Status Change++\n");
  63775. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63776. + if (gotgctl.b.sesreqscs) {
  63777. +
  63778. + if ((core_if->core_params->phy_type ==
  63779. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  63780. + core_if->srp_success = 1;
  63781. + } else {
  63782. + DWC_SPINUNLOCK(core_if->lock);
  63783. + cil_pcd_resume(core_if);
  63784. + DWC_SPINLOCK(core_if->lock);
  63785. + /* Clear Session Request */
  63786. + gotgctl.d32 = 0;
  63787. + gotgctl.b.sesreq = 1;
  63788. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  63789. + gotgctl.d32, 0);
  63790. + }
  63791. + }
  63792. + }
  63793. + if (gotgint.b.hstnegsucstschng) {
  63794. + /* Print statements during the HNP interrupt handling
  63795. + * can cause it to fail.*/
  63796. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63797. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  63798. + * this does not help*/
  63799. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  63800. + dwc_udelay(100);
  63801. + if (gotgctl.b.hstnegscs) {
  63802. + if (dwc_otg_is_host_mode(core_if)) {
  63803. + core_if->op_state = B_HOST;
  63804. + /*
  63805. + * Need to disable SOF interrupt immediately.
  63806. + * When switching from device to host, the PCD
  63807. + * interrupt handler won't handle the
  63808. + * interrupt if host mode is already set. The
  63809. + * HCD interrupt handler won't get called if
  63810. + * the HCD state is HALT. This means that the
  63811. + * interrupt does not get handled and Linux
  63812. + * complains loudly.
  63813. + */
  63814. + gintmsk.d32 = 0;
  63815. + gintmsk.b.sofintr = 1;
  63816. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  63817. + gintmsk.d32, 0);
  63818. + /* Call callback function with spin lock released */
  63819. + DWC_SPINUNLOCK(core_if->lock);
  63820. + cil_pcd_stop(core_if);
  63821. + /*
  63822. + * Initialize the Core for Host mode.
  63823. + */
  63824. + cil_hcd_start(core_if);
  63825. + DWC_SPINLOCK(core_if->lock);
  63826. + core_if->op_state = B_HOST;
  63827. + }
  63828. + } else {
  63829. + gotgctl.d32 = 0;
  63830. + gotgctl.b.hnpreq = 1;
  63831. + gotgctl.b.devhnpen = 1;
  63832. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63833. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  63834. + __DWC_ERROR("Device Not Connected/Responding\n");
  63835. + }
  63836. + }
  63837. + if (gotgint.b.hstnegdet) {
  63838. + /* The disconnect interrupt is set at the same time as
  63839. + * Host Negotiation Detected. During the mode
  63840. + * switch all interrupts are cleared so the disconnect
  63841. + * interrupt handler will not get executed.
  63842. + */
  63843. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63844. + "Host Negotiation Detected++ (%s)\n",
  63845. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63846. + "Device"));
  63847. + if (dwc_otg_is_device_mode(core_if)) {
  63848. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  63849. + core_if->op_state);
  63850. + DWC_SPINUNLOCK(core_if->lock);
  63851. + cil_hcd_disconnect(core_if);
  63852. + cil_pcd_start(core_if);
  63853. + DWC_SPINLOCK(core_if->lock);
  63854. + core_if->op_state = A_PERIPHERAL;
  63855. + } else {
  63856. + /*
  63857. + * Need to disable SOF interrupt immediately. When
  63858. + * switching from device to host, the PCD interrupt
  63859. + * handler won't handle the interrupt if host mode is
  63860. + * already set. The HCD interrupt handler won't get
  63861. + * called if the HCD state is HALT. This means that
  63862. + * the interrupt does not get handled and Linux
  63863. + * complains loudly.
  63864. + */
  63865. + gintmsk.d32 = 0;
  63866. + gintmsk.b.sofintr = 1;
  63867. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  63868. + DWC_SPINUNLOCK(core_if->lock);
  63869. + cil_pcd_stop(core_if);
  63870. + cil_hcd_start(core_if);
  63871. + DWC_SPINLOCK(core_if->lock);
  63872. + core_if->op_state = A_HOST;
  63873. + }
  63874. + }
  63875. + if (gotgint.b.adevtoutchng) {
  63876. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63877. + "A-Device Timeout Change++\n");
  63878. + }
  63879. + if (gotgint.b.debdone) {
  63880. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  63881. + }
  63882. +
  63883. + /* Clear GOTGINT */
  63884. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  63885. +
  63886. + return 1;
  63887. +}
  63888. +
  63889. +void w_conn_id_status_change(void *p)
  63890. +{
  63891. + dwc_otg_core_if_t *core_if = p;
  63892. + uint32_t count = 0;
  63893. + gotgctl_data_t gotgctl = {.d32 = 0 };
  63894. +
  63895. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63896. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  63897. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  63898. +
  63899. + /* B-Device connector (Device Mode) */
  63900. + if (gotgctl.b.conidsts) {
  63901. + /* Wait for switch to device mode. */
  63902. + while (!dwc_otg_is_device_mode(core_if)) {
  63903. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  63904. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63905. + "Peripheral"));
  63906. + dwc_mdelay(100);
  63907. + if (++count > 10000)
  63908. + break;
  63909. + }
  63910. + DWC_ASSERT(++count < 10000,
  63911. + "Connection id status change timed out");
  63912. + core_if->op_state = B_PERIPHERAL;
  63913. + dwc_otg_core_init(core_if);
  63914. + dwc_otg_enable_global_interrupts(core_if);
  63915. + cil_pcd_start(core_if);
  63916. + } else {
  63917. + /* A-Device connector (Host Mode) */
  63918. + while (!dwc_otg_is_host_mode(core_if)) {
  63919. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  63920. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63921. + "Peripheral"));
  63922. + dwc_mdelay(100);
  63923. + if (++count > 10000)
  63924. + break;
  63925. + }
  63926. + DWC_ASSERT(++count < 10000,
  63927. + "Connection id status change timed out");
  63928. + core_if->op_state = A_HOST;
  63929. + /*
  63930. + * Initialize the Core for Host mode.
  63931. + */
  63932. + dwc_otg_core_init(core_if);
  63933. + dwc_otg_enable_global_interrupts(core_if);
  63934. + cil_hcd_start(core_if);
  63935. + }
  63936. +}
  63937. +
  63938. +/**
  63939. + * This function handles the Connector ID Status Change Interrupt. It
  63940. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  63941. + * is a Device to Host Mode transition or a Host Mode to Device
  63942. + * Transition.
  63943. + *
  63944. + * This only occurs when the cable is connected/removed from the PHY
  63945. + * connector.
  63946. + *
  63947. + * @param core_if Programming view of DWC_otg controller.
  63948. + */
  63949. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  63950. +{
  63951. +
  63952. + /*
  63953. + * Need to disable SOF interrupt immediately. If switching from device
  63954. + * to host, the PCD interrupt handler won't handle the interrupt if
  63955. + * host mode is already set. The HCD interrupt handler won't get
  63956. + * called if the HCD state is HALT. This means that the interrupt does
  63957. + * not get handled and Linux complains loudly.
  63958. + */
  63959. + gintmsk_data_t gintmsk = {.d32 = 0 };
  63960. + gintsts_data_t gintsts = {.d32 = 0 };
  63961. +
  63962. + gintmsk.b.sofintr = 1;
  63963. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  63964. +
  63965. + DWC_DEBUGPL(DBG_CIL,
  63966. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  63967. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  63968. +
  63969. + DWC_SPINUNLOCK(core_if->lock);
  63970. +
  63971. + /*
  63972. + * Need to schedule a work, as there are possible DELAY function calls
  63973. + * Release lock before scheduling workq as it holds spinlock during scheduling
  63974. + */
  63975. +
  63976. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  63977. + core_if, "connection id status change");
  63978. + DWC_SPINLOCK(core_if->lock);
  63979. +
  63980. + /* Set flag and clear interrupt */
  63981. + gintsts.b.conidstschng = 1;
  63982. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63983. +
  63984. + return 1;
  63985. +}
  63986. +
  63987. +/**
  63988. + * This interrupt indicates that a device is initiating the Session
  63989. + * Request Protocol to request the host to turn on bus power so a new
  63990. + * session can begin. The handler responds by turning on bus power. If
  63991. + * the DWC_otg controller is in low power mode, the handler brings the
  63992. + * controller out of low power mode before turning on bus power.
  63993. + *
  63994. + * @param core_if Programming view of DWC_otg controller.
  63995. + */
  63996. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  63997. +{
  63998. + gintsts_data_t gintsts;
  63999. +
  64000. +#ifndef DWC_HOST_ONLY
  64001. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  64002. +
  64003. + if (dwc_otg_is_device_mode(core_if)) {
  64004. + DWC_PRINTF("SRP: Device mode\n");
  64005. + } else {
  64006. + hprt0_data_t hprt0;
  64007. + DWC_PRINTF("SRP: Host mode\n");
  64008. +
  64009. + /* Turn on the port power bit. */
  64010. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64011. + hprt0.b.prtpwr = 1;
  64012. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64013. +
  64014. + /* Start the Connection timer. So a message can be displayed
  64015. + * if connect does not occur within 10 seconds. */
  64016. + cil_hcd_session_start(core_if);
  64017. + }
  64018. +#endif
  64019. +
  64020. + /* Clear interrupt */
  64021. + gintsts.d32 = 0;
  64022. + gintsts.b.sessreqintr = 1;
  64023. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64024. +
  64025. + return 1;
  64026. +}
  64027. +
  64028. +void w_wakeup_detected(void *p)
  64029. +{
  64030. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  64031. + /*
  64032. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  64033. + * so that OPT tests pass with all PHYs).
  64034. + */
  64035. + hprt0_data_t hprt0 = {.d32 = 0 };
  64036. +#if 0
  64037. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64038. + /* Restart the Phy Clock */
  64039. + pcgcctl.b.stoppclk = 1;
  64040. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64041. + dwc_udelay(10);
  64042. +#endif //0
  64043. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64044. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  64045. +// dwc_mdelay(70);
  64046. + hprt0.b.prtres = 0; /* Resume */
  64047. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64048. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  64049. + DWC_READ_REG32(core_if->host_if->hprt0));
  64050. +
  64051. + cil_hcd_resume(core_if);
  64052. +
  64053. + /** Change to L0 state*/
  64054. + core_if->lx_state = DWC_OTG_L0;
  64055. +}
  64056. +
  64057. +/**
  64058. + * This interrupt indicates that the DWC_otg controller has detected a
  64059. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  64060. + * low power mode, the handler must brings the controller out of low
  64061. + * power mode. The controller automatically begins resume
  64062. + * signaling. The handler schedules a time to stop resume signaling.
  64063. + */
  64064. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64065. +{
  64066. + gintsts_data_t gintsts;
  64067. +
  64068. + DWC_DEBUGPL(DBG_ANY,
  64069. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  64070. +
  64071. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  64072. +
  64073. + if (dwc_otg_is_device_mode(core_if)) {
  64074. + dctl_data_t dctl = {.d32 = 0 };
  64075. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  64076. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  64077. + dsts));
  64078. + if (core_if->lx_state == DWC_OTG_L2) {
  64079. +#ifdef PARTIAL_POWER_DOWN
  64080. + if (core_if->hwcfg4.b.power_optimiz) {
  64081. + pcgcctl_data_t power = {.d32 = 0 };
  64082. +
  64083. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64084. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  64085. + power.d32);
  64086. +
  64087. + power.b.stoppclk = 0;
  64088. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64089. +
  64090. + power.b.pwrclmp = 0;
  64091. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64092. +
  64093. + power.b.rstpdwnmodule = 0;
  64094. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64095. + }
  64096. +#endif
  64097. + /* Clear the Remote Wakeup Signaling */
  64098. + dctl.b.rmtwkupsig = 1;
  64099. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  64100. + dctl, dctl.d32, 0);
  64101. +
  64102. + DWC_SPINUNLOCK(core_if->lock);
  64103. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64104. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64105. + }
  64106. + DWC_SPINLOCK(core_if->lock);
  64107. + } else {
  64108. + glpmcfg_data_t lpmcfg;
  64109. + lpmcfg.d32 =
  64110. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64111. + lpmcfg.b.hird_thres &= (~(1 << 4));
  64112. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64113. + lpmcfg.d32);
  64114. + }
  64115. + /** Change to L0 state*/
  64116. + core_if->lx_state = DWC_OTG_L0;
  64117. + } else {
  64118. + if (core_if->lx_state != DWC_OTG_L1) {
  64119. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64120. +
  64121. + /* Restart the Phy Clock */
  64122. + pcgcctl.b.stoppclk = 1;
  64123. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64124. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  64125. + } else {
  64126. + /** Change to L0 state*/
  64127. + core_if->lx_state = DWC_OTG_L0;
  64128. + }
  64129. + }
  64130. +
  64131. + /* Clear interrupt */
  64132. + gintsts.d32 = 0;
  64133. + gintsts.b.wkupintr = 1;
  64134. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64135. +
  64136. + return 1;
  64137. +}
  64138. +
  64139. +/**
  64140. + * This interrupt indicates that the Wakeup Logic has detected a
  64141. + * Device disconnect.
  64142. + */
  64143. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  64144. +{
  64145. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64146. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  64147. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64148. +
  64149. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64150. +
  64151. + if (!core_if->hibernation_suspend) {
  64152. + DWC_PRINTF("Already exited from Hibernation\n");
  64153. + return 1;
  64154. + }
  64155. +
  64156. + /* Switch on the voltage to the core */
  64157. + gpwrdn.b.pwrdnswtch = 1;
  64158. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64159. + dwc_udelay(10);
  64160. +
  64161. + /* Reset the core */
  64162. + gpwrdn.d32 = 0;
  64163. + gpwrdn.b.pwrdnrstn = 1;
  64164. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64165. + dwc_udelay(10);
  64166. +
  64167. + /* Disable power clamps*/
  64168. + gpwrdn.d32 = 0;
  64169. + gpwrdn.b.pwrdnclmp = 1;
  64170. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64171. +
  64172. + /* Remove reset the core signal */
  64173. + gpwrdn.d32 = 0;
  64174. + gpwrdn.b.pwrdnrstn = 1;
  64175. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64176. + dwc_udelay(10);
  64177. +
  64178. + /* Disable PMU interrupt */
  64179. + gpwrdn.d32 = 0;
  64180. + gpwrdn.b.pmuintsel = 1;
  64181. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64182. +
  64183. + core_if->hibernation_suspend = 0;
  64184. +
  64185. + /* Disable PMU */
  64186. + gpwrdn.d32 = 0;
  64187. + gpwrdn.b.pmuactv = 1;
  64188. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64189. + dwc_udelay(10);
  64190. +
  64191. + if (gpwrdn_temp.b.idsts) {
  64192. + core_if->op_state = B_PERIPHERAL;
  64193. + dwc_otg_core_init(core_if);
  64194. + dwc_otg_enable_global_interrupts(core_if);
  64195. + cil_pcd_start(core_if);
  64196. + } else {
  64197. + core_if->op_state = A_HOST;
  64198. + dwc_otg_core_init(core_if);
  64199. + dwc_otg_enable_global_interrupts(core_if);
  64200. + cil_hcd_start(core_if);
  64201. + }
  64202. +
  64203. + return 1;
  64204. +}
  64205. +
  64206. +/**
  64207. + * This interrupt indicates that the Wakeup Logic has detected a
  64208. + * remote wakeup sequence.
  64209. + */
  64210. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64211. +{
  64212. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64213. + DWC_DEBUGPL(DBG_ANY,
  64214. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  64215. +
  64216. + if (!core_if->hibernation_suspend) {
  64217. + DWC_PRINTF("Already exited from Hibernation\n");
  64218. + return 1;
  64219. + }
  64220. +
  64221. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64222. + if (gpwrdn.b.idsts) { // Device Mode
  64223. + if ((core_if->power_down == 2)
  64224. + && (core_if->hibernation_suspend == 1)) {
  64225. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  64226. + }
  64227. + } else {
  64228. + if ((core_if->power_down == 2)
  64229. + && (core_if->hibernation_suspend == 1)) {
  64230. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  64231. + }
  64232. + }
  64233. + return 1;
  64234. +}
  64235. +
  64236. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  64237. +{
  64238. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64239. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64240. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64241. +
  64242. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64243. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64244. + if (core_if->power_down == 2) {
  64245. + if (!core_if->hibernation_suspend) {
  64246. + DWC_PRINTF("Already exited from Hibernation\n");
  64247. + return 1;
  64248. + }
  64249. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  64250. + /* Switch on the voltage to the core */
  64251. + gpwrdn.b.pwrdnswtch = 1;
  64252. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64253. + dwc_udelay(10);
  64254. +
  64255. + /* Reset the core */
  64256. + gpwrdn.d32 = 0;
  64257. + gpwrdn.b.pwrdnrstn = 1;
  64258. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64259. + dwc_udelay(10);
  64260. +
  64261. + /* Disable power clamps */
  64262. + gpwrdn.d32 = 0;
  64263. + gpwrdn.b.pwrdnclmp = 1;
  64264. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64265. +
  64266. + /* Remove reset the core signal */
  64267. + gpwrdn.d32 = 0;
  64268. + gpwrdn.b.pwrdnrstn = 1;
  64269. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64270. + dwc_udelay(10);
  64271. +
  64272. + /* Disable PMU interrupt */
  64273. + gpwrdn.d32 = 0;
  64274. + gpwrdn.b.pmuintsel = 1;
  64275. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64276. +
  64277. + /*Indicates that we are exiting from hibernation */
  64278. + core_if->hibernation_suspend = 0;
  64279. +
  64280. + /* Disable PMU */
  64281. + gpwrdn.d32 = 0;
  64282. + gpwrdn.b.pmuactv = 1;
  64283. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64284. + dwc_udelay(10);
  64285. +
  64286. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  64287. + if (gpwrdn.b.dis_vbus == 1) {
  64288. + gpwrdn.d32 = 0;
  64289. + gpwrdn.b.dis_vbus = 1;
  64290. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64291. + }
  64292. +
  64293. + if (gpwrdn_temp.b.idsts) {
  64294. + core_if->op_state = B_PERIPHERAL;
  64295. + dwc_otg_core_init(core_if);
  64296. + dwc_otg_enable_global_interrupts(core_if);
  64297. + cil_pcd_start(core_if);
  64298. + } else {
  64299. + core_if->op_state = A_HOST;
  64300. + dwc_otg_core_init(core_if);
  64301. + dwc_otg_enable_global_interrupts(core_if);
  64302. + cil_hcd_start(core_if);
  64303. + }
  64304. + }
  64305. +
  64306. + if (core_if->adp_enable) {
  64307. + uint8_t is_host = 0;
  64308. + DWC_SPINUNLOCK(core_if->lock);
  64309. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  64310. +#ifndef DWC_HOST_ONLY
  64311. + if (gpwrdn_temp.b.idsts)
  64312. + core_if->lock = otg_dev->pcd->lock;
  64313. +#endif
  64314. +#ifndef DWC_DEVICE_ONLY
  64315. + if (!gpwrdn_temp.b.idsts) {
  64316. + core_if->lock = otg_dev->hcd->lock;
  64317. + is_host = 1;
  64318. + }
  64319. +#endif
  64320. + DWC_PRINTF("RESTART ADP\n");
  64321. + if (core_if->adp.probe_enabled)
  64322. + dwc_otg_adp_probe_stop(core_if);
  64323. + if (core_if->adp.sense_enabled)
  64324. + dwc_otg_adp_sense_stop(core_if);
  64325. + if (core_if->adp.sense_timer_started)
  64326. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  64327. + if (core_if->adp.vbuson_timer_started)
  64328. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  64329. + core_if->adp.probe_timer_values[0] = -1;
  64330. + core_if->adp.probe_timer_values[1] = -1;
  64331. + core_if->adp.sense_timer_started = 0;
  64332. + core_if->adp.vbuson_timer_started = 0;
  64333. + core_if->adp.probe_counter = 0;
  64334. + core_if->adp.gpwrdn = 0;
  64335. +
  64336. + /* Disable PMU and restart ADP */
  64337. + gpwrdn_temp.d32 = 0;
  64338. + gpwrdn_temp.b.pmuactv = 1;
  64339. + gpwrdn_temp.b.pmuintsel = 1;
  64340. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64341. + DWC_PRINTF("Check point 1\n");
  64342. + dwc_mdelay(110);
  64343. + dwc_otg_adp_start(core_if, is_host);
  64344. + DWC_SPINLOCK(core_if->lock);
  64345. + }
  64346. +
  64347. +
  64348. + return 1;
  64349. +}
  64350. +
  64351. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  64352. +{
  64353. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64354. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  64355. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64356. +
  64357. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64358. + if (core_if->power_down == 2) {
  64359. + if (!core_if->hibernation_suspend) {
  64360. + DWC_PRINTF("Already exited from Hibernation\n");
  64361. + return 1;
  64362. + }
  64363. +
  64364. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64365. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  64366. + gpwrdn.b.bsessvld == 0) {
  64367. + /* Save gpwrdn register for further usage if stschng interrupt */
  64368. + core_if->gr_backup->gpwrdn_local =
  64369. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64370. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  64371. + return 1;
  64372. + }
  64373. +
  64374. + /* Switch on the voltage to the core */
  64375. + gpwrdn.d32 = 0;
  64376. + gpwrdn.b.pwrdnswtch = 1;
  64377. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64378. + dwc_udelay(10);
  64379. +
  64380. + /* Reset the core */
  64381. + gpwrdn.d32 = 0;
  64382. + gpwrdn.b.pwrdnrstn = 1;
  64383. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64384. + dwc_udelay(10);
  64385. +
  64386. + /* Disable power clamps */
  64387. + gpwrdn.d32 = 0;
  64388. + gpwrdn.b.pwrdnclmp = 1;
  64389. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64390. +
  64391. + /* Remove reset the core signal */
  64392. + gpwrdn.d32 = 0;
  64393. + gpwrdn.b.pwrdnrstn = 1;
  64394. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64395. + dwc_udelay(10);
  64396. +
  64397. + /* Disable PMU interrupt */
  64398. + gpwrdn.d32 = 0;
  64399. + gpwrdn.b.pmuintsel = 1;
  64400. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64401. + dwc_udelay(10);
  64402. +
  64403. + /*Indicates that we are exiting from hibernation */
  64404. + core_if->hibernation_suspend = 0;
  64405. +
  64406. + /* Disable PMU */
  64407. + gpwrdn.d32 = 0;
  64408. + gpwrdn.b.pmuactv = 1;
  64409. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64410. + dwc_udelay(10);
  64411. +
  64412. + core_if->op_state = B_PERIPHERAL;
  64413. + dwc_otg_core_init(core_if);
  64414. + dwc_otg_enable_global_interrupts(core_if);
  64415. + cil_pcd_start(core_if);
  64416. +
  64417. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64418. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  64419. + /*
  64420. + * Initiate SRP after initial ADP probe.
  64421. + */
  64422. + dwc_otg_initiate_srp(core_if);
  64423. + }
  64424. + }
  64425. +
  64426. + return 1;
  64427. +}
  64428. +/**
  64429. + * This interrupt indicates that the Wakeup Logic has detected a
  64430. + * status change either on IDDIG or BSessVld.
  64431. + */
  64432. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  64433. +{
  64434. + int retval;
  64435. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64436. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64437. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64438. +
  64439. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64440. +
  64441. + if (core_if->power_down == 2) {
  64442. + if (core_if->hibernation_suspend <= 0) {
  64443. + DWC_PRINTF("Already exited from Hibernation\n");
  64444. + return 1;
  64445. + } else
  64446. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  64447. +
  64448. + } else {
  64449. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  64450. + }
  64451. +
  64452. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64453. +
  64454. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  64455. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  64456. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  64457. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  64458. + }
  64459. +
  64460. + return retval;
  64461. +}
  64462. +
  64463. +/**
  64464. + * This interrupt indicates that the Wakeup Logic has detected a
  64465. + * SRP.
  64466. + */
  64467. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  64468. +{
  64469. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64470. +
  64471. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64472. +
  64473. + if (!core_if->hibernation_suspend) {
  64474. + DWC_PRINTF("Already exited from Hibernation\n");
  64475. + return 1;
  64476. + }
  64477. +#ifdef DWC_DEV_SRPCAP
  64478. + if (core_if->pwron_timer_started) {
  64479. + core_if->pwron_timer_started = 0;
  64480. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  64481. + }
  64482. +#endif
  64483. +
  64484. + /* Switch on the voltage to the core */
  64485. + gpwrdn.b.pwrdnswtch = 1;
  64486. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64487. + dwc_udelay(10);
  64488. +
  64489. + /* Reset the core */
  64490. + gpwrdn.d32 = 0;
  64491. + gpwrdn.b.pwrdnrstn = 1;
  64492. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64493. + dwc_udelay(10);
  64494. +
  64495. + /* Disable power clamps */
  64496. + gpwrdn.d32 = 0;
  64497. + gpwrdn.b.pwrdnclmp = 1;
  64498. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64499. +
  64500. + /* Remove reset the core signal */
  64501. + gpwrdn.d32 = 0;
  64502. + gpwrdn.b.pwrdnrstn = 1;
  64503. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64504. + dwc_udelay(10);
  64505. +
  64506. + /* Disable PMU interrupt */
  64507. + gpwrdn.d32 = 0;
  64508. + gpwrdn.b.pmuintsel = 1;
  64509. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64510. +
  64511. + /* Indicates that we are exiting from hibernation */
  64512. + core_if->hibernation_suspend = 0;
  64513. +
  64514. + /* Disable PMU */
  64515. + gpwrdn.d32 = 0;
  64516. + gpwrdn.b.pmuactv = 1;
  64517. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64518. + dwc_udelay(10);
  64519. +
  64520. + /* Programm Disable VBUS to 0 */
  64521. + gpwrdn.d32 = 0;
  64522. + gpwrdn.b.dis_vbus = 1;
  64523. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64524. +
  64525. + /*Initialize the core as Host */
  64526. + core_if->op_state = A_HOST;
  64527. + dwc_otg_core_init(core_if);
  64528. + dwc_otg_enable_global_interrupts(core_if);
  64529. + cil_hcd_start(core_if);
  64530. +
  64531. + return 1;
  64532. +}
  64533. +
  64534. +/** This interrupt indicates that restore command after Hibernation
  64535. + * was completed by the core. */
  64536. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  64537. +{
  64538. + pcgcctl_data_t pcgcctl;
  64539. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  64540. +
  64541. + //TODO De-assert restore signal. 8.a
  64542. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64543. + if (pcgcctl.b.restoremode == 1) {
  64544. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64545. + /*
  64546. + * If restore mode is Remote Wakeup,
  64547. + * unmask Remote Wakeup interrupt.
  64548. + */
  64549. + gintmsk.b.wkupintr = 1;
  64550. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  64551. + 0, gintmsk.d32);
  64552. + }
  64553. +
  64554. + return 1;
  64555. +}
  64556. +
  64557. +/**
  64558. + * This interrupt indicates that a device has been disconnected from
  64559. + * the root port.
  64560. + */
  64561. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  64562. +{
  64563. + gintsts_data_t gintsts;
  64564. +
  64565. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  64566. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  64567. + op_state_str(core_if));
  64568. +
  64569. +/** @todo Consolidate this if statement. */
  64570. +#ifndef DWC_HOST_ONLY
  64571. + if (core_if->op_state == B_HOST) {
  64572. + /* If in device mode Disconnect and stop the HCD, then
  64573. + * start the PCD. */
  64574. + DWC_SPINUNLOCK(core_if->lock);
  64575. + cil_hcd_disconnect(core_if);
  64576. + cil_pcd_start(core_if);
  64577. + DWC_SPINLOCK(core_if->lock);
  64578. + core_if->op_state = B_PERIPHERAL;
  64579. + } else if (dwc_otg_is_device_mode(core_if)) {
  64580. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64581. + gotgctl.d32 =
  64582. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64583. + if (gotgctl.b.hstsethnpen == 1) {
  64584. + /* Do nothing, if HNP in process the OTG
  64585. + * interrupt "Host Negotiation Detected"
  64586. + * interrupt will do the mode switch.
  64587. + */
  64588. + } else if (gotgctl.b.devhnpen == 0) {
  64589. + /* If in device mode Disconnect and stop the HCD, then
  64590. + * start the PCD. */
  64591. + DWC_SPINUNLOCK(core_if->lock);
  64592. + cil_hcd_disconnect(core_if);
  64593. + cil_pcd_start(core_if);
  64594. + DWC_SPINLOCK(core_if->lock);
  64595. + core_if->op_state = B_PERIPHERAL;
  64596. + } else {
  64597. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  64598. + }
  64599. + } else {
  64600. + if (core_if->op_state == A_HOST) {
  64601. + /* A-Cable still connected but device disconnected. */
  64602. + cil_hcd_disconnect(core_if);
  64603. + if (core_if->adp_enable) {
  64604. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64605. + cil_hcd_stop(core_if);
  64606. + /* Enable Power Down Logic */
  64607. + gpwrdn.b.pmuintsel = 1;
  64608. + gpwrdn.b.pmuactv = 1;
  64609. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64610. + gpwrdn, 0, gpwrdn.d32);
  64611. + dwc_otg_adp_probe_start(core_if);
  64612. +
  64613. + /* Power off the core */
  64614. + if (core_if->power_down == 2) {
  64615. + gpwrdn.d32 = 0;
  64616. + gpwrdn.b.pwrdnswtch = 1;
  64617. + DWC_MODIFY_REG32
  64618. + (&core_if->core_global_regs->gpwrdn,
  64619. + gpwrdn.d32, 0);
  64620. + }
  64621. + }
  64622. + }
  64623. + }
  64624. +#endif
  64625. + /* Change to L3(OFF) state */
  64626. + core_if->lx_state = DWC_OTG_L3;
  64627. +
  64628. + gintsts.d32 = 0;
  64629. + gintsts.b.disconnect = 1;
  64630. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64631. + return 1;
  64632. +}
  64633. +
  64634. +/**
  64635. + * This interrupt indicates that SUSPEND state has been detected on
  64636. + * the USB.
  64637. + *
  64638. + * For HNP the USB Suspend interrupt signals the change from
  64639. + * "a_peripheral" to "a_host".
  64640. + *
  64641. + * When power management is enabled the core will be put in low power
  64642. + * mode.
  64643. + */
  64644. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  64645. +{
  64646. + dsts_data_t dsts;
  64647. + gintsts_data_t gintsts;
  64648. + dcfg_data_t dcfg;
  64649. +
  64650. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  64651. +
  64652. + if (dwc_otg_is_device_mode(core_if)) {
  64653. + /* Check the Device status register to determine if the Suspend
  64654. + * state is active. */
  64655. + dsts.d32 =
  64656. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  64657. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  64658. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  64659. + "HWCFG4.power Optimize=%d\n",
  64660. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  64661. +
  64662. +#ifdef PARTIAL_POWER_DOWN
  64663. +/** @todo Add a module parameter for power management. */
  64664. +
  64665. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  64666. + pcgcctl_data_t power = {.d32 = 0 };
  64667. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  64668. +
  64669. + power.b.pwrclmp = 1;
  64670. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64671. +
  64672. + power.b.rstpdwnmodule = 1;
  64673. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64674. +
  64675. + power.b.stoppclk = 1;
  64676. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64677. +
  64678. + } else {
  64679. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  64680. + }
  64681. +#endif
  64682. + /* PCD callback for suspend. Release the lock inside of callback function */
  64683. + cil_pcd_suspend(core_if);
  64684. + if (core_if->power_down == 2)
  64685. + {
  64686. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64687. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  64688. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  64689. +
  64690. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64691. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64692. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64693. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  64694. +
  64695. + /* Change to L2(suspend) state */
  64696. + core_if->lx_state = DWC_OTG_L2;
  64697. +
  64698. + /* Clear interrupt in gintsts */
  64699. + gintsts.d32 = 0;
  64700. + gintsts.b.usbsuspend = 1;
  64701. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64702. + gintsts, gintsts.d32);
  64703. + DWC_PRINTF("Start of hibernation completed\n");
  64704. + dwc_otg_save_global_regs(core_if);
  64705. + dwc_otg_save_dev_regs(core_if);
  64706. +
  64707. + gusbcfg.d32 =
  64708. + DWC_READ_REG32(&core_if->core_global_regs->
  64709. + gusbcfg);
  64710. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  64711. + /* ULPI interface */
  64712. + /* Suspend the Phy Clock */
  64713. + pcgcctl.d32 = 0;
  64714. + pcgcctl.b.stoppclk = 1;
  64715. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64716. + pcgcctl.d32);
  64717. + dwc_udelay(10);
  64718. + gpwrdn.b.pmuactv = 1;
  64719. + DWC_MODIFY_REG32(&core_if->
  64720. + core_global_regs->
  64721. + gpwrdn, 0, gpwrdn.d32);
  64722. + } else {
  64723. + /* UTMI+ Interface */
  64724. + gpwrdn.b.pmuactv = 1;
  64725. + DWC_MODIFY_REG32(&core_if->
  64726. + core_global_regs->
  64727. + gpwrdn, 0, gpwrdn.d32);
  64728. + dwc_udelay(10);
  64729. + pcgcctl.b.stoppclk = 1;
  64730. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64731. + pcgcctl.d32);
  64732. + dwc_udelay(10);
  64733. + }
  64734. +
  64735. + /* Set flag to indicate that we are in hibernation */
  64736. + core_if->hibernation_suspend = 1;
  64737. + /* Enable interrupts from wake up logic */
  64738. + gpwrdn.d32 = 0;
  64739. + gpwrdn.b.pmuintsel = 1;
  64740. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64741. + gpwrdn, 0, gpwrdn.d32);
  64742. + dwc_udelay(10);
  64743. +
  64744. + /* Unmask device mode interrupts in GPWRDN */
  64745. + gpwrdn.d32 = 0;
  64746. + gpwrdn.b.rst_det_msk = 1;
  64747. + gpwrdn.b.lnstchng_msk = 1;
  64748. + gpwrdn.b.sts_chngint_msk = 1;
  64749. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64750. + gpwrdn, 0, gpwrdn.d32);
  64751. + dwc_udelay(10);
  64752. +
  64753. + /* Enable Power Down Clamp */
  64754. + gpwrdn.d32 = 0;
  64755. + gpwrdn.b.pwrdnclmp = 1;
  64756. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64757. + gpwrdn, 0, gpwrdn.d32);
  64758. + dwc_udelay(10);
  64759. +
  64760. + /* Switch off VDD */
  64761. + gpwrdn.d32 = 0;
  64762. + gpwrdn.b.pwrdnswtch = 1;
  64763. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64764. + gpwrdn, 0, gpwrdn.d32);
  64765. +
  64766. + /* Save gpwrdn register for further usage if stschng interrupt */
  64767. + core_if->gr_backup->gpwrdn_local =
  64768. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64769. + DWC_PRINTF("Hibernation completed\n");
  64770. +
  64771. + return 1;
  64772. + }
  64773. + } else if (core_if->power_down == 3) {
  64774. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64775. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64776. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  64777. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  64778. +
  64779. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64780. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  64781. + core_if->xhib = 1;
  64782. +
  64783. + /* Clear interrupt in gintsts */
  64784. + gintsts.d32 = 0;
  64785. + gintsts.b.usbsuspend = 1;
  64786. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64787. + gintsts, gintsts.d32);
  64788. +
  64789. + dwc_otg_save_global_regs(core_if);
  64790. + dwc_otg_save_dev_regs(core_if);
  64791. +
  64792. + /* Wait for 10 PHY clocks */
  64793. + dwc_udelay(10);
  64794. +
  64795. + /* Program GPIO register while entering to xHib */
  64796. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  64797. +
  64798. + pcgcctl.b.enbl_extnd_hiber = 1;
  64799. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64800. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64801. +
  64802. + pcgcctl.d32 = 0;
  64803. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  64804. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64805. +
  64806. + pcgcctl.d32 = 0;
  64807. + pcgcctl.b.extnd_hiber_switch = 1;
  64808. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64809. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  64810. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64811. +
  64812. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  64813. +
  64814. + return 1;
  64815. + }
  64816. + }
  64817. + } else {
  64818. + if (core_if->op_state == A_PERIPHERAL) {
  64819. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  64820. + /* Clear the a_peripheral flag, back to a_host. */
  64821. + DWC_SPINUNLOCK(core_if->lock);
  64822. + cil_pcd_stop(core_if);
  64823. + cil_hcd_start(core_if);
  64824. + DWC_SPINLOCK(core_if->lock);
  64825. + core_if->op_state = A_HOST;
  64826. + }
  64827. + }
  64828. +
  64829. + /* Change to L2(suspend) state */
  64830. + core_if->lx_state = DWC_OTG_L2;
  64831. +
  64832. + /* Clear interrupt */
  64833. + gintsts.d32 = 0;
  64834. + gintsts.b.usbsuspend = 1;
  64835. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64836. +
  64837. + return 1;
  64838. +}
  64839. +
  64840. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  64841. +{
  64842. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64843. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64844. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64845. +
  64846. + dwc_udelay(10);
  64847. +
  64848. + /* Program GPIO register while entering to xHib */
  64849. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  64850. +
  64851. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  64852. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64853. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64854. + dwc_udelay(10);
  64855. +
  64856. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  64857. + gpwrdn.b.restore = 1;
  64858. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  64859. + dwc_udelay(10);
  64860. +
  64861. + restore_lpm_i2c_regs(core_if);
  64862. +
  64863. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64864. + pcgcctl.b.max_xcvrselect = 1;
  64865. + pcgcctl.b.ess_reg_restored = 0;
  64866. + pcgcctl.b.extnd_hiber_switch = 0;
  64867. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64868. + pcgcctl.b.enbl_extnd_hiber = 1;
  64869. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64870. +
  64871. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  64872. + gahbcfg.b.glblintrmsk = 1;
  64873. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  64874. +
  64875. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  64876. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  64877. +
  64878. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  64879. + core_if->gr_backup->gusbcfg_local);
  64880. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  64881. + core_if->dr_backup->dcfg);
  64882. +
  64883. + pcgcctl.d32 = 0;
  64884. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64885. + pcgcctl.b.max_xcvrselect = 1;
  64886. + pcgcctl.d32 |= 0x608;
  64887. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64888. + dwc_udelay(10);
  64889. +
  64890. + pcgcctl.d32 = 0;
  64891. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64892. + pcgcctl.b.max_xcvrselect = 1;
  64893. + pcgcctl.b.ess_reg_restored = 1;
  64894. + pcgcctl.b.enbl_extnd_hiber = 1;
  64895. + pcgcctl.b.rstpdwnmodule = 1;
  64896. + pcgcctl.b.restoremode = 1;
  64897. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64898. +
  64899. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64900. +
  64901. + return 1;
  64902. +}
  64903. +
  64904. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64905. +/**
  64906. + * This function hadles LPM transaction received interrupt.
  64907. + */
  64908. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  64909. +{
  64910. + glpmcfg_data_t lpmcfg;
  64911. + gintsts_data_t gintsts;
  64912. +
  64913. + if (!core_if->core_params->lpm_enable) {
  64914. + DWC_PRINTF("Unexpected LPM interrupt\n");
  64915. + }
  64916. +
  64917. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64918. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  64919. +
  64920. + if (dwc_otg_is_host_mode(core_if)) {
  64921. + cil_hcd_sleep(core_if);
  64922. + } else {
  64923. + lpmcfg.b.hird_thres |= (1 << 4);
  64924. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64925. + lpmcfg.d32);
  64926. + }
  64927. +
  64928. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  64929. + dwc_udelay(10);
  64930. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64931. + if (lpmcfg.b.prt_sleep_sts) {
  64932. + /* Save the current state */
  64933. + core_if->lx_state = DWC_OTG_L1;
  64934. + }
  64935. +
  64936. + /* Clear interrupt */
  64937. + gintsts.d32 = 0;
  64938. + gintsts.b.lpmtranrcvd = 1;
  64939. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64940. + return 1;
  64941. +}
  64942. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  64943. +
  64944. +/**
  64945. + * This function returns the Core Interrupt register.
  64946. + */
  64947. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
  64948. +{
  64949. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64950. + gintsts_data_t gintsts;
  64951. + gintmsk_data_t gintmsk;
  64952. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  64953. + gintmsk_common.b.wkupintr = 1;
  64954. + gintmsk_common.b.sessreqintr = 1;
  64955. + gintmsk_common.b.conidstschng = 1;
  64956. + gintmsk_common.b.otgintr = 1;
  64957. + gintmsk_common.b.modemismatch = 1;
  64958. + gintmsk_common.b.disconnect = 1;
  64959. + gintmsk_common.b.usbsuspend = 1;
  64960. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64961. + gintmsk_common.b.lpmtranrcvd = 1;
  64962. +#endif
  64963. + gintmsk_common.b.restoredone = 1;
  64964. + if(dwc_otg_is_device_mode(core_if))
  64965. + {
  64966. + /** @todo: The port interrupt occurs while in device
  64967. + * mode. Added code to CIL to clear the interrupt for now!
  64968. + */
  64969. + gintmsk_common.b.portintr = 1;
  64970. + }
  64971. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  64972. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  64973. + {
  64974. + unsigned long flags;
  64975. +
  64976. + // Re-enable the saved interrupts
  64977. + local_irq_save(flags);
  64978. + local_fiq_disable();
  64979. + gintmsk.d32 |= gintmsk_common.d32;
  64980. + gintsts_saved.d32 &= ~gintmsk_common.d32;
  64981. + reenable_gintmsk->d32 = gintmsk.d32;
  64982. + local_irq_restore(flags);
  64983. + }
  64984. +
  64985. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  64986. +
  64987. +#ifdef DEBUG
  64988. + /* if any common interrupts set */
  64989. + if (gintsts.d32 & gintmsk_common.d32) {
  64990. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  64991. + gintsts.d32, gintmsk.d32);
  64992. + }
  64993. +#endif
  64994. + if (!fiq_fix_enable){
  64995. + if (gahbcfg.b.glblintrmsk)
  64996. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  64997. + else
  64998. + return 0;
  64999. + }
  65000. + else {
  65001. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65002. + }
  65003. +
  65004. +}
  65005. +
  65006. +/* MACRO for clearing interupt bits in GPWRDN register */
  65007. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  65008. +do { \
  65009. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  65010. + gpwrdn.b.__intr = 1; \
  65011. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  65012. + 0, gpwrdn.d32); \
  65013. +} while (0)
  65014. +
  65015. +/**
  65016. + * Common interrupt handler.
  65017. + *
  65018. + * The common interrupts are those that occur in both Host and Device mode.
  65019. + * This handler handles the following interrupts:
  65020. + * - Mode Mismatch Interrupt
  65021. + * - Disconnect Interrupt
  65022. + * - OTG Interrupt
  65023. + * - Connector ID Status Change Interrupt
  65024. + * - Session Request Interrupt.
  65025. + * - Resume / Remote Wakeup Detected Interrupt.
  65026. + * - LPM Transaction Received Interrupt
  65027. + * - ADP Transaction Received Interrupt
  65028. + *
  65029. + */
  65030. +int32_t dwc_otg_handle_common_intr(void *dev)
  65031. +{
  65032. + int retval = 0;
  65033. + gintsts_data_t gintsts;
  65034. + gintmsk_data_t reenable_gintmsk;
  65035. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65036. + dwc_otg_device_t *otg_dev = dev;
  65037. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65038. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65039. + if (dwc_otg_is_device_mode(core_if))
  65040. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  65041. +
  65042. + if (core_if->lock)
  65043. + DWC_SPINLOCK(core_if->lock);
  65044. +
  65045. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  65046. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  65047. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  65048. + core_if->xhib = 2;
  65049. + if (core_if->lock)
  65050. + DWC_SPINUNLOCK(core_if->lock);
  65051. +
  65052. + return retval;
  65053. + }
  65054. +
  65055. + if (core_if->hibernation_suspend <= 0) {
  65056. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
  65057. +
  65058. + if (gintsts.b.modemismatch) {
  65059. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  65060. + }
  65061. + if (gintsts.b.otgintr) {
  65062. + retval |= dwc_otg_handle_otg_intr(core_if);
  65063. + }
  65064. + if (gintsts.b.conidstschng) {
  65065. + retval |=
  65066. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  65067. + }
  65068. + if (gintsts.b.disconnect) {
  65069. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  65070. + }
  65071. + if (gintsts.b.sessreqintr) {
  65072. + retval |= dwc_otg_handle_session_req_intr(core_if);
  65073. + }
  65074. + if (gintsts.b.wkupintr) {
  65075. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  65076. + }
  65077. + if (gintsts.b.usbsuspend) {
  65078. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  65079. + }
  65080. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65081. + if (gintsts.b.lpmtranrcvd) {
  65082. + retval |= dwc_otg_handle_lpm_intr(core_if);
  65083. + }
  65084. +#endif
  65085. + if (gintsts.b.restoredone) {
  65086. + gintsts.d32 = 0;
  65087. + if (core_if->power_down == 2)
  65088. + core_if->hibernation_suspend = -1;
  65089. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  65090. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65091. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65092. + dctl_data_t dctl = {.d32 = 0 };
  65093. +
  65094. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65095. + gintsts, 0xFFFFFFFF);
  65096. +
  65097. + DWC_DEBUGPL(DBG_ANY,
  65098. + "RESTORE DONE generated\n");
  65099. +
  65100. + gpwrdn.b.restore = 1;
  65101. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65102. + dwc_udelay(10);
  65103. +
  65104. + pcgcctl.b.rstpdwnmodule = 1;
  65105. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65106. +
  65107. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  65108. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  65109. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  65110. + dwc_udelay(50);
  65111. +
  65112. + dctl.b.pwronprgdone = 1;
  65113. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  65114. + dwc_udelay(10);
  65115. +
  65116. + dwc_otg_restore_global_regs(core_if);
  65117. + dwc_otg_restore_dev_regs(core_if, 0);
  65118. +
  65119. + dctl.d32 = 0;
  65120. + dctl.b.pwronprgdone = 1;
  65121. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  65122. + dwc_udelay(10);
  65123. +
  65124. + pcgcctl.d32 = 0;
  65125. + pcgcctl.b.enbl_extnd_hiber = 1;
  65126. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65127. +
  65128. + /* The core will be in ON STATE */
  65129. + core_if->lx_state = DWC_OTG_L0;
  65130. + core_if->xhib = 0;
  65131. +
  65132. + DWC_SPINUNLOCK(core_if->lock);
  65133. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65134. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65135. + }
  65136. + DWC_SPINLOCK(core_if->lock);
  65137. +
  65138. + }
  65139. +
  65140. + gintsts.b.restoredone = 1;
  65141. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65142. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  65143. + retval |= 1;
  65144. + }
  65145. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  65146. + /* The port interrupt occurs while in device mode with HPRT0
  65147. + * Port Enable/Disable.
  65148. + */
  65149. + gintsts.d32 = 0;
  65150. + gintsts.b.portintr = 1;
  65151. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65152. + retval |= 1;
  65153. + reenable_gintmsk.b.portintr = 1;
  65154. +
  65155. + }
  65156. +
  65157. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
  65158. +
  65159. + } else {
  65160. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  65161. +
  65162. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  65163. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  65164. + if (gpwrdn.b.linestate == 0) {
  65165. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  65166. + } else {
  65167. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  65168. + }
  65169. +
  65170. + retval |= 1;
  65171. + }
  65172. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  65173. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  65174. + /* remote wakeup from hibernation */
  65175. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  65176. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  65177. + } else {
  65178. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  65179. + }
  65180. + retval |= 1;
  65181. + }
  65182. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  65183. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  65184. + if (gpwrdn.b.linestate == 0) {
  65185. + DWC_PRINTF("Reset detected\n");
  65186. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  65187. + }
  65188. + }
  65189. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  65190. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  65191. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  65192. + retval |= 1;
  65193. + }
  65194. + }
  65195. + /* Handle ADP interrupt here */
  65196. + if (gpwrdn.b.adp_int) {
  65197. + DWC_PRINTF("ADP interrupt\n");
  65198. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  65199. + dwc_otg_adp_handle_intr(core_if);
  65200. + retval |= 1;
  65201. + }
  65202. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  65203. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  65204. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  65205. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  65206. +
  65207. + retval |= 1;
  65208. + }
  65209. + if (core_if->lock)
  65210. + DWC_SPINUNLOCK(core_if->lock);
  65211. +
  65212. + return retval;
  65213. +}
  65214. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  65215. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  65216. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-02-07 19:57:30.000000000 +0100
  65217. @@ -0,0 +1,705 @@
  65218. +/* ==========================================================================
  65219. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  65220. + * $Revision: #13 $
  65221. + * $Date: 2012/08/10 $
  65222. + * $Change: 2047372 $
  65223. + *
  65224. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65225. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65226. + * otherwise expressly agreed to in writing between Synopsys and you.
  65227. + *
  65228. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65229. + * any End User Software License Agreement or Agreement for Licensed Product
  65230. + * with Synopsys or any supplement thereto. You are permitted to use and
  65231. + * redistribute this Software in source and binary forms, with or without
  65232. + * modification, provided that redistributions of source code must retain this
  65233. + * notice. You may not view, use, disclose, copy or distribute this file or
  65234. + * any information contained herein except pursuant to this license grant from
  65235. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65236. + * below, then you are not authorized to use the Software.
  65237. + *
  65238. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65239. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65240. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65241. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65242. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65243. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65244. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65245. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65246. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65247. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65248. + * DAMAGE.
  65249. + * ========================================================================== */
  65250. +#if !defined(__DWC_CORE_IF_H__)
  65251. +#define __DWC_CORE_IF_H__
  65252. +
  65253. +#include "dwc_os.h"
  65254. +
  65255. +/** @file
  65256. + * This file defines DWC_OTG Core API
  65257. + */
  65258. +
  65259. +struct dwc_otg_core_if;
  65260. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  65261. +
  65262. +/** Maximum number of Periodic FIFOs */
  65263. +#define MAX_PERIO_FIFOS 15
  65264. +/** Maximum number of Periodic FIFOs */
  65265. +#define MAX_TX_FIFOS 15
  65266. +
  65267. +/** Maximum number of Endpoints/HostChannels */
  65268. +#define MAX_EPS_CHANNELS 16
  65269. +
  65270. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  65271. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  65272. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  65273. +
  65274. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65275. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65276. +
  65277. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  65278. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  65279. +
  65280. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  65281. +
  65282. +/** This function should be called on every hardware interrupt. */
  65283. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  65284. +
  65285. +/** @name OTG Core Parameters */
  65286. +/** @{ */
  65287. +
  65288. +/**
  65289. + * Specifies the OTG capabilities. The driver will automatically
  65290. + * detect the value for this parameter if none is specified.
  65291. + * 0 - HNP and SRP capable (default)
  65292. + * 1 - SRP Only capable
  65293. + * 2 - No HNP/SRP capable
  65294. + */
  65295. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  65296. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  65297. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  65298. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  65299. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  65300. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  65301. +
  65302. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  65303. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  65304. +#define dwc_param_opt_default 1
  65305. +
  65306. +/**
  65307. + * Specifies whether to use slave or DMA mode for accessing the data
  65308. + * FIFOs. The driver will automatically detect the value for this
  65309. + * parameter if none is specified.
  65310. + * 0 - Slave
  65311. + * 1 - DMA (default, if available)
  65312. + */
  65313. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  65314. + int32_t val);
  65315. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  65316. +#define dwc_param_dma_enable_default 1
  65317. +
  65318. +/**
  65319. + * When DMA mode is enabled specifies whether to use
  65320. + * address DMA or DMA Descritor mode for accessing the data
  65321. + * FIFOs in device mode. The driver will automatically detect
  65322. + * the value for this parameter if none is specified.
  65323. + * 0 - address DMA
  65324. + * 1 - DMA Descriptor(default, if available)
  65325. + */
  65326. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  65327. + int32_t val);
  65328. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  65329. +//#define dwc_param_dma_desc_enable_default 1
  65330. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  65331. +
  65332. +/** The DMA Burst size (applicable only for External DMA
  65333. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  65334. + */
  65335. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  65336. + int32_t val);
  65337. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  65338. +#define dwc_param_dma_burst_size_default 32
  65339. +
  65340. +/**
  65341. + * Specifies the maximum speed of operation in host and device mode.
  65342. + * The actual speed depends on the speed of the attached device and
  65343. + * the value of phy_type. The actual speed depends on the speed of the
  65344. + * attached device.
  65345. + * 0 - High Speed (default)
  65346. + * 1 - Full Speed
  65347. + */
  65348. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  65349. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  65350. +#define dwc_param_speed_default 0
  65351. +#define DWC_SPEED_PARAM_HIGH 0
  65352. +#define DWC_SPEED_PARAM_FULL 1
  65353. +
  65354. +/** Specifies whether low power mode is supported when attached
  65355. + * to a Full Speed or Low Speed device in host mode.
  65356. + * 0 - Don't support low power mode (default)
  65357. + * 1 - Support low power mode
  65358. + */
  65359. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  65360. + core_if, int32_t val);
  65361. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  65362. + * core_if);
  65363. +#define dwc_param_host_support_fs_ls_low_power_default 0
  65364. +
  65365. +/** Specifies the PHY clock rate in low power mode when connected to a
  65366. + * Low Speed device in host mode. This parameter is applicable only if
  65367. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  65368. + * then defaults to 6 MHZ otherwise 48 MHZ.
  65369. + *
  65370. + * 0 - 48 MHz
  65371. + * 1 - 6 MHz
  65372. + */
  65373. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65374. + core_if, int32_t val);
  65375. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65376. + core_if);
  65377. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  65378. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  65379. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  65380. +
  65381. +/**
  65382. + * 0 - Use cC FIFO size parameters
  65383. + * 1 - Allow dynamic FIFO sizing (default)
  65384. + */
  65385. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  65386. + int32_t val);
  65387. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  65388. + core_if);
  65389. +#define dwc_param_enable_dynamic_fifo_default 1
  65390. +
  65391. +/** Total number of 4-byte words in the data FIFO memory. This
  65392. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  65393. + * Tx FIFOs.
  65394. + * 32 to 32768 (default 8192)
  65395. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  65396. + */
  65397. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  65398. + int32_t val);
  65399. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  65400. +//#define dwc_param_data_fifo_size_default 8192
  65401. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  65402. +
  65403. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  65404. + * FIFO sizing is enabled.
  65405. + * 16 to 32768 (default 1064)
  65406. + */
  65407. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65408. + int32_t val);
  65409. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65410. +#define dwc_param_dev_rx_fifo_size_default 1064
  65411. +
  65412. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  65413. + * when dynamic FIFO sizing is enabled.
  65414. + * 16 to 32768 (default 1024)
  65415. + */
  65416. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65417. + core_if, int32_t val);
  65418. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65419. + core_if);
  65420. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  65421. +
  65422. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  65423. + * mode when dynamic FIFO sizing is enabled.
  65424. + * 4 to 768 (default 256)
  65425. + */
  65426. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65427. + int32_t val, int fifo_num);
  65428. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  65429. + core_if, int fifo_num);
  65430. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  65431. +
  65432. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  65433. + * FIFO sizing is enabled.
  65434. + * 16 to 32768 (default 1024)
  65435. + */
  65436. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65437. + int32_t val);
  65438. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65439. +//#define dwc_param_host_rx_fifo_size_default 1024
  65440. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  65441. +
  65442. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  65443. + * when Dynamic FIFO sizing is enabled in the core.
  65444. + * 16 to 32768 (default 1024)
  65445. + */
  65446. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65447. + core_if, int32_t val);
  65448. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65449. + core_if);
  65450. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  65451. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  65452. +
  65453. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  65454. + * FIFO sizing is enabled.
  65455. + * 16 to 32768 (default 1024)
  65456. + */
  65457. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65458. + core_if, int32_t val);
  65459. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65460. + core_if);
  65461. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  65462. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  65463. +
  65464. +/** The maximum transfer size supported in bytes.
  65465. + * 2047 to 65,535 (default 65,535)
  65466. + */
  65467. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  65468. + int32_t val);
  65469. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  65470. +#define dwc_param_max_transfer_size_default 65535
  65471. +
  65472. +/** The maximum number of packets in a transfer.
  65473. + * 15 to 511 (default 511)
  65474. + */
  65475. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  65476. + int32_t val);
  65477. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  65478. +#define dwc_param_max_packet_count_default 511
  65479. +
  65480. +/** The number of host channel registers to use.
  65481. + * 1 to 16 (default 12)
  65482. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  65483. + */
  65484. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  65485. + int32_t val);
  65486. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  65487. +//#define dwc_param_host_channels_default 12
  65488. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  65489. +
  65490. +/** The number of endpoints in addition to EP0 available for device
  65491. + * mode operations.
  65492. + * 1 to 15 (default 6 IN and OUT)
  65493. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  65494. + * endpoints in addition to EP0.
  65495. + */
  65496. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  65497. + int32_t val);
  65498. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  65499. +#define dwc_param_dev_endpoints_default 6
  65500. +
  65501. +/**
  65502. + * Specifies the type of PHY interface to use. By default, the driver
  65503. + * will automatically detect the phy_type.
  65504. + *
  65505. + * 0 - Full Speed PHY
  65506. + * 1 - UTMI+ (default)
  65507. + * 2 - ULPI
  65508. + */
  65509. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  65510. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  65511. +#define DWC_PHY_TYPE_PARAM_FS 0
  65512. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  65513. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  65514. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  65515. +
  65516. +/**
  65517. + * Specifies the UTMI+ Data Width. This parameter is
  65518. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  65519. + * PHY_TYPE, this parameter indicates the data width between
  65520. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  65521. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  65522. + * to "8 and 16 bits", meaning that the core has been
  65523. + * configured to work at either data path width.
  65524. + *
  65525. + * 8 or 16 bits (default 16)
  65526. + */
  65527. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  65528. + int32_t val);
  65529. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  65530. +//#define dwc_param_phy_utmi_width_default 16
  65531. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  65532. +
  65533. +/**
  65534. + * Specifies whether the ULPI operates at double or single
  65535. + * data rate. This parameter is only applicable if PHY_TYPE is
  65536. + * ULPI.
  65537. + *
  65538. + * 0 - single data rate ULPI interface with 8 bit wide data
  65539. + * bus (default)
  65540. + * 1 - double data rate ULPI interface with 4 bit wide data
  65541. + * bus
  65542. + */
  65543. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  65544. + int32_t val);
  65545. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  65546. +#define dwc_param_phy_ulpi_ddr_default 0
  65547. +
  65548. +/**
  65549. + * Specifies whether to use the internal or external supply to
  65550. + * drive the vbus with a ULPI phy.
  65551. + */
  65552. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  65553. + int32_t val);
  65554. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  65555. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  65556. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  65557. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  65558. +
  65559. +/**
  65560. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  65561. + * parameter is only applicable if PHY_TYPE is FS.
  65562. + * 0 - No (default)
  65563. + * 1 - Yes
  65564. + */
  65565. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  65566. + int32_t val);
  65567. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  65568. +#define dwc_param_i2c_enable_default 0
  65569. +
  65570. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  65571. + int32_t val);
  65572. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  65573. +#define dwc_param_ulpi_fs_ls_default 0
  65574. +
  65575. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  65576. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  65577. +#define dwc_param_ts_dline_default 0
  65578. +
  65579. +/**
  65580. + * Specifies whether dedicated transmit FIFOs are
  65581. + * enabled for non periodic IN endpoints in device mode
  65582. + * 0 - No
  65583. + * 1 - Yes
  65584. + */
  65585. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  65586. + int32_t val);
  65587. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  65588. + core_if);
  65589. +#define dwc_param_en_multiple_tx_fifo_default 1
  65590. +
  65591. +/** Number of 4-byte words in each of the Tx FIFOs in device
  65592. + * mode when dynamic FIFO sizing is enabled.
  65593. + * 4 to 768 (default 256)
  65594. + */
  65595. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65596. + int fifo_num, int32_t val);
  65597. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65598. + int fifo_num);
  65599. +#define dwc_param_dev_tx_fifo_size_default 768
  65600. +
  65601. +/** Thresholding enable flag-
  65602. + * bit 0 - enable non-ISO Tx thresholding
  65603. + * bit 1 - enable ISO Tx thresholding
  65604. + * bit 2 - enable Rx thresholding
  65605. + */
  65606. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  65607. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  65608. +#define dwc_param_thr_ctl_default 0
  65609. +
  65610. +/** Thresholding length for Tx
  65611. + * FIFOs in 32 bit DWORDs
  65612. + */
  65613. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  65614. + int32_t val);
  65615. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  65616. +#define dwc_param_tx_thr_length_default 64
  65617. +
  65618. +/** Thresholding length for Rx
  65619. + * FIFOs in 32 bit DWORDs
  65620. + */
  65621. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  65622. + int32_t val);
  65623. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  65624. +#define dwc_param_rx_thr_length_default 64
  65625. +
  65626. +/**
  65627. + * Specifies whether LPM (Link Power Management) support is enabled
  65628. + */
  65629. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  65630. + int32_t val);
  65631. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  65632. +#define dwc_param_lpm_enable_default 1
  65633. +
  65634. +/**
  65635. + * Specifies whether PTI enhancement is enabled
  65636. + */
  65637. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  65638. + int32_t val);
  65639. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  65640. +#define dwc_param_pti_enable_default 0
  65641. +
  65642. +/**
  65643. + * Specifies whether MPI enhancement is enabled
  65644. + */
  65645. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  65646. + int32_t val);
  65647. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  65648. +#define dwc_param_mpi_enable_default 0
  65649. +
  65650. +/**
  65651. + * Specifies whether ADP capability is enabled
  65652. + */
  65653. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  65654. + int32_t val);
  65655. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  65656. +#define dwc_param_adp_enable_default 0
  65657. +
  65658. +/**
  65659. + * Specifies whether IC_USB capability is enabled
  65660. + */
  65661. +
  65662. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  65663. + int32_t val);
  65664. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  65665. +#define dwc_param_ic_usb_cap_default 0
  65666. +
  65667. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  65668. + int32_t val);
  65669. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  65670. +#define dwc_param_ahb_thr_ratio_default 0
  65671. +
  65672. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  65673. + int32_t val);
  65674. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  65675. +#define dwc_param_power_down_default 0
  65676. +
  65677. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  65678. + int32_t val);
  65679. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  65680. +#define dwc_param_reload_ctl_default 0
  65681. +
  65682. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  65683. + int32_t val);
  65684. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  65685. +#define dwc_param_dev_out_nak_default 0
  65686. +
  65687. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  65688. + int32_t val);
  65689. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  65690. +#define dwc_param_cont_on_bna_default 0
  65691. +
  65692. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  65693. + int32_t val);
  65694. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  65695. +#define dwc_param_ahb_single_default 0
  65696. +
  65697. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  65698. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  65699. +#define dwc_param_otg_ver_default 0
  65700. +
  65701. +/** @} */
  65702. +
  65703. +/** @name Access to registers and bit-fields */
  65704. +
  65705. +/**
  65706. + * Dump core registers and SPRAM
  65707. + */
  65708. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  65709. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  65710. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  65711. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  65712. +
  65713. +/**
  65714. + * Get host negotiation status.
  65715. + */
  65716. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  65717. +
  65718. +/**
  65719. + * Get srp status
  65720. + */
  65721. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  65722. +
  65723. +/**
  65724. + * Set hnpreq bit in the GOTGCTL register.
  65725. + */
  65726. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  65727. +
  65728. +/**
  65729. + * Get Content of SNPSID register.
  65730. + */
  65731. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  65732. +
  65733. +/**
  65734. + * Get current mode.
  65735. + * Returns 0 if in device mode, and 1 if in host mode.
  65736. + */
  65737. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  65738. +
  65739. +/**
  65740. + * Get value of hnpcapable field in the GUSBCFG register
  65741. + */
  65742. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  65743. +/**
  65744. + * Set value of hnpcapable field in the GUSBCFG register
  65745. + */
  65746. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65747. +
  65748. +/**
  65749. + * Get value of srpcapable field in the GUSBCFG register
  65750. + */
  65751. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  65752. +/**
  65753. + * Set value of srpcapable field in the GUSBCFG register
  65754. + */
  65755. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65756. +
  65757. +/**
  65758. + * Get value of devspeed field in the DCFG register
  65759. + */
  65760. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  65761. +/**
  65762. + * Set value of devspeed field in the DCFG register
  65763. + */
  65764. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  65765. +
  65766. +/**
  65767. + * Get the value of busconnected field from the HPRT0 register
  65768. + */
  65769. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  65770. +
  65771. +/**
  65772. + * Gets the device enumeration Speed.
  65773. + */
  65774. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  65775. +
  65776. +/**
  65777. + * Get value of prtpwr field from the HPRT0 register
  65778. + */
  65779. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  65780. +
  65781. +/**
  65782. + * Get value of flag indicating core state - hibernated or not
  65783. + */
  65784. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  65785. +
  65786. +/**
  65787. + * Set value of prtpwr field from the HPRT0 register
  65788. + */
  65789. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  65790. +
  65791. +/**
  65792. + * Get value of prtsusp field from the HPRT0 regsiter
  65793. + */
  65794. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  65795. +/**
  65796. + * Set value of prtpwr field from the HPRT0 register
  65797. + */
  65798. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  65799. +
  65800. +/**
  65801. + * Get value of ModeChTimEn field from the HCFG regsiter
  65802. + */
  65803. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  65804. +/**
  65805. + * Set value of ModeChTimEn field from the HCFG regsiter
  65806. + */
  65807. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  65808. +
  65809. +/**
  65810. + * Get value of Fram Interval field from the HFIR regsiter
  65811. + */
  65812. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  65813. +/**
  65814. + * Set value of Frame Interval field from the HFIR regsiter
  65815. + */
  65816. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  65817. +
  65818. +/**
  65819. + * Set value of prtres field from the HPRT0 register
  65820. + *FIXME Remove?
  65821. + */
  65822. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  65823. +
  65824. +/**
  65825. + * Get value of rmtwkupsig bit in DCTL register
  65826. + */
  65827. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  65828. +
  65829. +/**
  65830. + * Get value of prt_sleep_sts field from the GLPMCFG register
  65831. + */
  65832. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  65833. +
  65834. +/**
  65835. + * Get value of rem_wkup_en field from the GLPMCFG register
  65836. + */
  65837. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  65838. +
  65839. +/**
  65840. + * Get value of appl_resp field from the GLPMCFG register
  65841. + */
  65842. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  65843. +/**
  65844. + * Set value of appl_resp field from the GLPMCFG register
  65845. + */
  65846. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  65847. +
  65848. +/**
  65849. + * Get value of hsic_connect field from the GLPMCFG register
  65850. + */
  65851. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  65852. +/**
  65853. + * Set value of hsic_connect field from the GLPMCFG register
  65854. + */
  65855. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  65856. +
  65857. +/**
  65858. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  65859. + */
  65860. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  65861. +/**
  65862. + * Set value of inv_sel_hsic field from the GLPMFG register.
  65863. + */
  65864. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  65865. +
  65866. +/*
  65867. + * Some functions for accessing registers
  65868. + */
  65869. +
  65870. +/**
  65871. + * GOTGCTL register
  65872. + */
  65873. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  65874. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65875. +
  65876. +/**
  65877. + * GUSBCFG register
  65878. + */
  65879. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  65880. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  65881. +
  65882. +/**
  65883. + * GRXFSIZ register
  65884. + */
  65885. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  65886. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65887. +
  65888. +/**
  65889. + * GNPTXFSIZ register
  65890. + */
  65891. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  65892. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65893. +
  65894. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  65895. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65896. +
  65897. +/**
  65898. + * GGPIO register
  65899. + */
  65900. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  65901. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  65902. +
  65903. +/**
  65904. + * GUID register
  65905. + */
  65906. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  65907. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  65908. +
  65909. +/**
  65910. + * HPRT0 register
  65911. + */
  65912. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  65913. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  65914. +
  65915. +/**
  65916. + * GHPTXFSIZE
  65917. + */
  65918. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  65919. +
  65920. +/** @} */
  65921. +
  65922. +#endif /* __DWC_CORE_IF_H__ */
  65923. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  65924. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  65925. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-02-07 19:57:30.000000000 +0100
  65926. @@ -0,0 +1,117 @@
  65927. +/* ==========================================================================
  65928. + *
  65929. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65930. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65931. + * otherwise expressly agreed to in writing between Synopsys and you.
  65932. + *
  65933. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65934. + * any End User Software License Agreement or Agreement for Licensed Product
  65935. + * with Synopsys or any supplement thereto. You are permitted to use and
  65936. + * redistribute this Software in source and binary forms, with or without
  65937. + * modification, provided that redistributions of source code must retain this
  65938. + * notice. You may not view, use, disclose, copy or distribute this file or
  65939. + * any information contained herein except pursuant to this license grant from
  65940. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65941. + * below, then you are not authorized to use the Software.
  65942. + *
  65943. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65944. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65945. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65946. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65947. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65948. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65949. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65950. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65951. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65952. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65953. + * DAMAGE.
  65954. + * ========================================================================== */
  65955. +
  65956. +#ifndef __DWC_OTG_DBG_H__
  65957. +#define __DWC_OTG_DBG_H__
  65958. +
  65959. +/** @file
  65960. + * This file defines debug levels.
  65961. + * Debugging support vanishes in non-debug builds.
  65962. + */
  65963. +
  65964. +/**
  65965. + * The Debug Level bit-mask variable.
  65966. + */
  65967. +extern uint32_t g_dbg_lvl;
  65968. +/**
  65969. + * Set the Debug Level variable.
  65970. + */
  65971. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  65972. +{
  65973. + uint32_t old = g_dbg_lvl;
  65974. + g_dbg_lvl = new;
  65975. + return old;
  65976. +}
  65977. +
  65978. +#define DBG_USER (0x1)
  65979. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  65980. +#define DBG_CIL (0x2)
  65981. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  65982. + * messages */
  65983. +#define DBG_CILV (0x20)
  65984. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  65985. + * messages */
  65986. +#define DBG_PCD (0x4)
  65987. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  65988. + * messages */
  65989. +#define DBG_PCDV (0x40)
  65990. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  65991. +#define DBG_HCD (0x8)
  65992. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  65993. + * messages */
  65994. +#define DBG_HCDV (0x80)
  65995. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  65996. + * mode. */
  65997. +#define DBG_HCD_URB (0x800)
  65998. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  65999. + * messages. */
  66000. +#define DBG_HCDI (0x1000)
  66001. +
  66002. +/** When debug level has any bit set, display debug messages */
  66003. +#define DBG_ANY (0xFF)
  66004. +
  66005. +/** All debug messages off */
  66006. +#define DBG_OFF 0
  66007. +
  66008. +/** Prefix string for DWC_DEBUG print macros. */
  66009. +#define USB_DWC "DWC_otg: "
  66010. +
  66011. +/**
  66012. + * Print a debug message when the Global debug level variable contains
  66013. + * the bit defined in <code>lvl</code>.
  66014. + *
  66015. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  66016. + * @param[in] x - like printf
  66017. + *
  66018. + * Example:<p>
  66019. + * <code>
  66020. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  66021. + * </code>
  66022. + * <br>
  66023. + * results in:<br>
  66024. + * <code>
  66025. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  66026. + * </code>
  66027. + */
  66028. +#ifdef DEBUG
  66029. +
  66030. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  66031. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  66032. +
  66033. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  66034. +
  66035. +#else
  66036. +
  66037. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  66038. +# define DWC_DEBUGP(x...)
  66039. +
  66040. +# define CHK_DEBUG_LEVEL(level) (0)
  66041. +
  66042. +#endif /*DEBUG*/
  66043. +#endif
  66044. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  66045. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  66046. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-02-07 19:57:30.000000000 +0100
  66047. @@ -0,0 +1,1742 @@
  66048. +/* ==========================================================================
  66049. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  66050. + * $Revision: #92 $
  66051. + * $Date: 2012/08/10 $
  66052. + * $Change: 2047372 $
  66053. + *
  66054. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66055. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66056. + * otherwise expressly agreed to in writing between Synopsys and you.
  66057. + *
  66058. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66059. + * any End User Software License Agreement or Agreement for Licensed Product
  66060. + * with Synopsys or any supplement thereto. You are permitted to use and
  66061. + * redistribute this Software in source and binary forms, with or without
  66062. + * modification, provided that redistributions of source code must retain this
  66063. + * notice. You may not view, use, disclose, copy or distribute this file or
  66064. + * any information contained herein except pursuant to this license grant from
  66065. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66066. + * below, then you are not authorized to use the Software.
  66067. + *
  66068. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66069. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66070. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66071. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66072. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66073. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66074. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66075. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66076. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66077. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66078. + * DAMAGE.
  66079. + * ========================================================================== */
  66080. +
  66081. +/** @file
  66082. + * The dwc_otg_driver module provides the initialization and cleanup entry
  66083. + * points for the DWC_otg driver. This module will be dynamically installed
  66084. + * after Linux is booted using the insmod command. When the module is
  66085. + * installed, the dwc_otg_driver_init function is called. When the module is
  66086. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  66087. + *
  66088. + * This module also defines a data structure for the dwc_otg_driver, which is
  66089. + * used in conjunction with the standard ARM lm_device structure. These
  66090. + * structures allow the OTG driver to comply with the standard Linux driver
  66091. + * model in which devices and drivers are registered with a bus driver. This
  66092. + * has the benefit that Linux can expose attributes of the driver and device
  66093. + * in its special sysfs file system. Users can then read or write files in
  66094. + * this file system to perform diagnostics on the driver components or the
  66095. + * device.
  66096. + */
  66097. +
  66098. +#include "dwc_otg_os_dep.h"
  66099. +#include "dwc_os.h"
  66100. +#include "dwc_otg_dbg.h"
  66101. +#include "dwc_otg_driver.h"
  66102. +#include "dwc_otg_attr.h"
  66103. +#include "dwc_otg_core_if.h"
  66104. +#include "dwc_otg_pcd_if.h"
  66105. +#include "dwc_otg_hcd_if.h"
  66106. +
  66107. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  66108. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  66109. +
  66110. +bool microframe_schedule=true;
  66111. +
  66112. +static const char dwc_driver_name[] = "dwc_otg";
  66113. +
  66114. +extern void* dummy_send;
  66115. +
  66116. +extern int pcd_init(
  66117. +#ifdef LM_INTERFACE
  66118. + struct lm_device *_dev
  66119. +#elif defined(PCI_INTERFACE)
  66120. + struct pci_dev *_dev
  66121. +#elif defined(PLATFORM_INTERFACE)
  66122. + struct platform_device *dev
  66123. +#endif
  66124. + );
  66125. +extern int hcd_init(
  66126. +#ifdef LM_INTERFACE
  66127. + struct lm_device *_dev
  66128. +#elif defined(PCI_INTERFACE)
  66129. + struct pci_dev *_dev
  66130. +#elif defined(PLATFORM_INTERFACE)
  66131. + struct platform_device *dev
  66132. +#endif
  66133. + );
  66134. +
  66135. +extern int pcd_remove(
  66136. +#ifdef LM_INTERFACE
  66137. + struct lm_device *_dev
  66138. +#elif defined(PCI_INTERFACE)
  66139. + struct pci_dev *_dev
  66140. +#elif defined(PLATFORM_INTERFACE)
  66141. + struct platform_device *_dev
  66142. +#endif
  66143. + );
  66144. +
  66145. +extern void hcd_remove(
  66146. +#ifdef LM_INTERFACE
  66147. + struct lm_device *_dev
  66148. +#elif defined(PCI_INTERFACE)
  66149. + struct pci_dev *_dev
  66150. +#elif defined(PLATFORM_INTERFACE)
  66151. + struct platform_device *_dev
  66152. +#endif
  66153. + );
  66154. +
  66155. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  66156. +
  66157. +/*-------------------------------------------------------------------------*/
  66158. +/* Encapsulate the module parameter settings */
  66159. +
  66160. +struct dwc_otg_driver_module_params {
  66161. + int32_t opt;
  66162. + int32_t otg_cap;
  66163. + int32_t dma_enable;
  66164. + int32_t dma_desc_enable;
  66165. + int32_t dma_burst_size;
  66166. + int32_t speed;
  66167. + int32_t host_support_fs_ls_low_power;
  66168. + int32_t host_ls_low_power_phy_clk;
  66169. + int32_t enable_dynamic_fifo;
  66170. + int32_t data_fifo_size;
  66171. + int32_t dev_rx_fifo_size;
  66172. + int32_t dev_nperio_tx_fifo_size;
  66173. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  66174. + int32_t host_rx_fifo_size;
  66175. + int32_t host_nperio_tx_fifo_size;
  66176. + int32_t host_perio_tx_fifo_size;
  66177. + int32_t max_transfer_size;
  66178. + int32_t max_packet_count;
  66179. + int32_t host_channels;
  66180. + int32_t dev_endpoints;
  66181. + int32_t phy_type;
  66182. + int32_t phy_utmi_width;
  66183. + int32_t phy_ulpi_ddr;
  66184. + int32_t phy_ulpi_ext_vbus;
  66185. + int32_t i2c_enable;
  66186. + int32_t ulpi_fs_ls;
  66187. + int32_t ts_dline;
  66188. + int32_t en_multiple_tx_fifo;
  66189. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  66190. + uint32_t thr_ctl;
  66191. + uint32_t tx_thr_length;
  66192. + uint32_t rx_thr_length;
  66193. + int32_t pti_enable;
  66194. + int32_t mpi_enable;
  66195. + int32_t lpm_enable;
  66196. + int32_t ic_usb_cap;
  66197. + int32_t ahb_thr_ratio;
  66198. + int32_t power_down;
  66199. + int32_t reload_ctl;
  66200. + int32_t dev_out_nak;
  66201. + int32_t cont_on_bna;
  66202. + int32_t ahb_single;
  66203. + int32_t otg_ver;
  66204. + int32_t adp_enable;
  66205. +};
  66206. +
  66207. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  66208. + .opt = -1,
  66209. + .otg_cap = -1,
  66210. + .dma_enable = -1,
  66211. + .dma_desc_enable = -1,
  66212. + .dma_burst_size = -1,
  66213. + .speed = -1,
  66214. + .host_support_fs_ls_low_power = -1,
  66215. + .host_ls_low_power_phy_clk = -1,
  66216. + .enable_dynamic_fifo = -1,
  66217. + .data_fifo_size = -1,
  66218. + .dev_rx_fifo_size = -1,
  66219. + .dev_nperio_tx_fifo_size = -1,
  66220. + .dev_perio_tx_fifo_size = {
  66221. + /* dev_perio_tx_fifo_size_1 */
  66222. + -1,
  66223. + -1,
  66224. + -1,
  66225. + -1,
  66226. + -1,
  66227. + -1,
  66228. + -1,
  66229. + -1,
  66230. + -1,
  66231. + -1,
  66232. + -1,
  66233. + -1,
  66234. + -1,
  66235. + -1,
  66236. + -1
  66237. + /* 15 */
  66238. + },
  66239. + .host_rx_fifo_size = -1,
  66240. + .host_nperio_tx_fifo_size = -1,
  66241. + .host_perio_tx_fifo_size = -1,
  66242. + .max_transfer_size = -1,
  66243. + .max_packet_count = -1,
  66244. + .host_channels = -1,
  66245. + .dev_endpoints = -1,
  66246. + .phy_type = -1,
  66247. + .phy_utmi_width = -1,
  66248. + .phy_ulpi_ddr = -1,
  66249. + .phy_ulpi_ext_vbus = -1,
  66250. + .i2c_enable = -1,
  66251. + .ulpi_fs_ls = -1,
  66252. + .ts_dline = -1,
  66253. + .en_multiple_tx_fifo = -1,
  66254. + .dev_tx_fifo_size = {
  66255. + /* dev_tx_fifo_size */
  66256. + -1,
  66257. + -1,
  66258. + -1,
  66259. + -1,
  66260. + -1,
  66261. + -1,
  66262. + -1,
  66263. + -1,
  66264. + -1,
  66265. + -1,
  66266. + -1,
  66267. + -1,
  66268. + -1,
  66269. + -1,
  66270. + -1
  66271. + /* 15 */
  66272. + },
  66273. + .thr_ctl = -1,
  66274. + .tx_thr_length = -1,
  66275. + .rx_thr_length = -1,
  66276. + .pti_enable = -1,
  66277. + .mpi_enable = -1,
  66278. + .lpm_enable = 0,
  66279. + .ic_usb_cap = -1,
  66280. + .ahb_thr_ratio = -1,
  66281. + .power_down = -1,
  66282. + .reload_ctl = -1,
  66283. + .dev_out_nak = -1,
  66284. + .cont_on_bna = -1,
  66285. + .ahb_single = -1,
  66286. + .otg_ver = -1,
  66287. + .adp_enable = -1,
  66288. +};
  66289. +
  66290. +//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
  66291. +extern bool fiq_fix_enable;
  66292. +// Global variable to enable the split transaction fix
  66293. +bool fiq_split_enable = true;
  66294. +//Global variable to switch the nak holdoff on or off
  66295. +bool nak_holdoff_enable = true;
  66296. +
  66297. +
  66298. +/**
  66299. + * This function shows the Driver Version.
  66300. + */
  66301. +static ssize_t version_show(struct device_driver *dev, char *buf)
  66302. +{
  66303. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  66304. + DWC_DRIVER_VERSION);
  66305. +}
  66306. +
  66307. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  66308. +
  66309. +/**
  66310. + * Global Debug Level Mask.
  66311. + */
  66312. +uint32_t g_dbg_lvl = 0; /* OFF */
  66313. +
  66314. +/**
  66315. + * This function shows the driver Debug Level.
  66316. + */
  66317. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  66318. +{
  66319. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  66320. +}
  66321. +
  66322. +/**
  66323. + * This function stores the driver Debug Level.
  66324. + */
  66325. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  66326. + size_t count)
  66327. +{
  66328. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  66329. + return count;
  66330. +}
  66331. +
  66332. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  66333. + dbg_level_store);
  66334. +
  66335. +/**
  66336. + * This function is called during module intialization
  66337. + * to pass module parameters to the DWC_OTG CORE.
  66338. + */
  66339. +static int set_parameters(dwc_otg_core_if_t * core_if)
  66340. +{
  66341. + int retval = 0;
  66342. + int i;
  66343. +
  66344. + if (dwc_otg_module_params.otg_cap != -1) {
  66345. + retval +=
  66346. + dwc_otg_set_param_otg_cap(core_if,
  66347. + dwc_otg_module_params.otg_cap);
  66348. + }
  66349. + if (dwc_otg_module_params.dma_enable != -1) {
  66350. + retval +=
  66351. + dwc_otg_set_param_dma_enable(core_if,
  66352. + dwc_otg_module_params.
  66353. + dma_enable);
  66354. + }
  66355. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  66356. + retval +=
  66357. + dwc_otg_set_param_dma_desc_enable(core_if,
  66358. + dwc_otg_module_params.
  66359. + dma_desc_enable);
  66360. + }
  66361. + if (dwc_otg_module_params.opt != -1) {
  66362. + retval +=
  66363. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  66364. + }
  66365. + if (dwc_otg_module_params.dma_burst_size != -1) {
  66366. + retval +=
  66367. + dwc_otg_set_param_dma_burst_size(core_if,
  66368. + dwc_otg_module_params.
  66369. + dma_burst_size);
  66370. + }
  66371. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  66372. + retval +=
  66373. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  66374. + dwc_otg_module_params.
  66375. + host_support_fs_ls_low_power);
  66376. + }
  66377. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  66378. + retval +=
  66379. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  66380. + dwc_otg_module_params.
  66381. + enable_dynamic_fifo);
  66382. + }
  66383. + if (dwc_otg_module_params.data_fifo_size != -1) {
  66384. + retval +=
  66385. + dwc_otg_set_param_data_fifo_size(core_if,
  66386. + dwc_otg_module_params.
  66387. + data_fifo_size);
  66388. + }
  66389. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  66390. + retval +=
  66391. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  66392. + dwc_otg_module_params.
  66393. + dev_rx_fifo_size);
  66394. + }
  66395. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  66396. + retval +=
  66397. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  66398. + dwc_otg_module_params.
  66399. + dev_nperio_tx_fifo_size);
  66400. + }
  66401. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  66402. + retval +=
  66403. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  66404. + dwc_otg_module_params.host_rx_fifo_size);
  66405. + }
  66406. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  66407. + retval +=
  66408. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  66409. + dwc_otg_module_params.
  66410. + host_nperio_tx_fifo_size);
  66411. + }
  66412. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  66413. + retval +=
  66414. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  66415. + dwc_otg_module_params.
  66416. + host_perio_tx_fifo_size);
  66417. + }
  66418. + if (dwc_otg_module_params.max_transfer_size != -1) {
  66419. + retval +=
  66420. + dwc_otg_set_param_max_transfer_size(core_if,
  66421. + dwc_otg_module_params.
  66422. + max_transfer_size);
  66423. + }
  66424. + if (dwc_otg_module_params.max_packet_count != -1) {
  66425. + retval +=
  66426. + dwc_otg_set_param_max_packet_count(core_if,
  66427. + dwc_otg_module_params.
  66428. + max_packet_count);
  66429. + }
  66430. + if (dwc_otg_module_params.host_channels != -1) {
  66431. + retval +=
  66432. + dwc_otg_set_param_host_channels(core_if,
  66433. + dwc_otg_module_params.
  66434. + host_channels);
  66435. + }
  66436. + if (dwc_otg_module_params.dev_endpoints != -1) {
  66437. + retval +=
  66438. + dwc_otg_set_param_dev_endpoints(core_if,
  66439. + dwc_otg_module_params.
  66440. + dev_endpoints);
  66441. + }
  66442. + if (dwc_otg_module_params.phy_type != -1) {
  66443. + retval +=
  66444. + dwc_otg_set_param_phy_type(core_if,
  66445. + dwc_otg_module_params.phy_type);
  66446. + }
  66447. + if (dwc_otg_module_params.speed != -1) {
  66448. + retval +=
  66449. + dwc_otg_set_param_speed(core_if,
  66450. + dwc_otg_module_params.speed);
  66451. + }
  66452. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  66453. + retval +=
  66454. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  66455. + dwc_otg_module_params.
  66456. + host_ls_low_power_phy_clk);
  66457. + }
  66458. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  66459. + retval +=
  66460. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  66461. + dwc_otg_module_params.
  66462. + phy_ulpi_ddr);
  66463. + }
  66464. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  66465. + retval +=
  66466. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  66467. + dwc_otg_module_params.
  66468. + phy_ulpi_ext_vbus);
  66469. + }
  66470. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  66471. + retval +=
  66472. + dwc_otg_set_param_phy_utmi_width(core_if,
  66473. + dwc_otg_module_params.
  66474. + phy_utmi_width);
  66475. + }
  66476. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  66477. + retval +=
  66478. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  66479. + dwc_otg_module_params.ulpi_fs_ls);
  66480. + }
  66481. + if (dwc_otg_module_params.ts_dline != -1) {
  66482. + retval +=
  66483. + dwc_otg_set_param_ts_dline(core_if,
  66484. + dwc_otg_module_params.ts_dline);
  66485. + }
  66486. + if (dwc_otg_module_params.i2c_enable != -1) {
  66487. + retval +=
  66488. + dwc_otg_set_param_i2c_enable(core_if,
  66489. + dwc_otg_module_params.
  66490. + i2c_enable);
  66491. + }
  66492. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  66493. + retval +=
  66494. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  66495. + dwc_otg_module_params.
  66496. + en_multiple_tx_fifo);
  66497. + }
  66498. + for (i = 0; i < 15; i++) {
  66499. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  66500. + retval +=
  66501. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  66502. + dwc_otg_module_params.
  66503. + dev_perio_tx_fifo_size
  66504. + [i], i);
  66505. + }
  66506. + }
  66507. +
  66508. + for (i = 0; i < 15; i++) {
  66509. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  66510. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  66511. + dwc_otg_module_params.
  66512. + dev_tx_fifo_size
  66513. + [i], i);
  66514. + }
  66515. + }
  66516. + if (dwc_otg_module_params.thr_ctl != -1) {
  66517. + retval +=
  66518. + dwc_otg_set_param_thr_ctl(core_if,
  66519. + dwc_otg_module_params.thr_ctl);
  66520. + }
  66521. + if (dwc_otg_module_params.mpi_enable != -1) {
  66522. + retval +=
  66523. + dwc_otg_set_param_mpi_enable(core_if,
  66524. + dwc_otg_module_params.
  66525. + mpi_enable);
  66526. + }
  66527. + if (dwc_otg_module_params.pti_enable != -1) {
  66528. + retval +=
  66529. + dwc_otg_set_param_pti_enable(core_if,
  66530. + dwc_otg_module_params.
  66531. + pti_enable);
  66532. + }
  66533. + if (dwc_otg_module_params.lpm_enable != -1) {
  66534. + retval +=
  66535. + dwc_otg_set_param_lpm_enable(core_if,
  66536. + dwc_otg_module_params.
  66537. + lpm_enable);
  66538. + }
  66539. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  66540. + retval +=
  66541. + dwc_otg_set_param_ic_usb_cap(core_if,
  66542. + dwc_otg_module_params.
  66543. + ic_usb_cap);
  66544. + }
  66545. + if (dwc_otg_module_params.tx_thr_length != -1) {
  66546. + retval +=
  66547. + dwc_otg_set_param_tx_thr_length(core_if,
  66548. + dwc_otg_module_params.tx_thr_length);
  66549. + }
  66550. + if (dwc_otg_module_params.rx_thr_length != -1) {
  66551. + retval +=
  66552. + dwc_otg_set_param_rx_thr_length(core_if,
  66553. + dwc_otg_module_params.
  66554. + rx_thr_length);
  66555. + }
  66556. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  66557. + retval +=
  66558. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  66559. + dwc_otg_module_params.ahb_thr_ratio);
  66560. + }
  66561. + if (dwc_otg_module_params.power_down != -1) {
  66562. + retval +=
  66563. + dwc_otg_set_param_power_down(core_if,
  66564. + dwc_otg_module_params.power_down);
  66565. + }
  66566. + if (dwc_otg_module_params.reload_ctl != -1) {
  66567. + retval +=
  66568. + dwc_otg_set_param_reload_ctl(core_if,
  66569. + dwc_otg_module_params.reload_ctl);
  66570. + }
  66571. +
  66572. + if (dwc_otg_module_params.dev_out_nak != -1) {
  66573. + retval +=
  66574. + dwc_otg_set_param_dev_out_nak(core_if,
  66575. + dwc_otg_module_params.dev_out_nak);
  66576. + }
  66577. +
  66578. + if (dwc_otg_module_params.cont_on_bna != -1) {
  66579. + retval +=
  66580. + dwc_otg_set_param_cont_on_bna(core_if,
  66581. + dwc_otg_module_params.cont_on_bna);
  66582. + }
  66583. +
  66584. + if (dwc_otg_module_params.ahb_single != -1) {
  66585. + retval +=
  66586. + dwc_otg_set_param_ahb_single(core_if,
  66587. + dwc_otg_module_params.ahb_single);
  66588. + }
  66589. +
  66590. + if (dwc_otg_module_params.otg_ver != -1) {
  66591. + retval +=
  66592. + dwc_otg_set_param_otg_ver(core_if,
  66593. + dwc_otg_module_params.otg_ver);
  66594. + }
  66595. + if (dwc_otg_module_params.adp_enable != -1) {
  66596. + retval +=
  66597. + dwc_otg_set_param_adp_enable(core_if,
  66598. + dwc_otg_module_params.
  66599. + adp_enable);
  66600. + }
  66601. + return retval;
  66602. +}
  66603. +
  66604. +/**
  66605. + * This function is the top level interrupt handler for the Common
  66606. + * (Device and host modes) interrupts.
  66607. + */
  66608. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  66609. +{
  66610. + int32_t retval = IRQ_NONE;
  66611. +
  66612. + retval = dwc_otg_handle_common_intr(dev);
  66613. + if (retval != 0) {
  66614. + S3C2410X_CLEAR_EINTPEND();
  66615. + }
  66616. + return IRQ_RETVAL(retval);
  66617. +}
  66618. +
  66619. +/**
  66620. + * This function is called when a lm_device is unregistered with the
  66621. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  66622. + * executed. The device may or may not be electrically present. If it is
  66623. + * present, the driver stops device processing. Any resources used on behalf
  66624. + * of this device are freed.
  66625. + *
  66626. + * @param _dev
  66627. + */
  66628. +#ifdef LM_INTERFACE
  66629. +#define REM_RETVAL(n)
  66630. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  66631. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  66632. +#elif defined(PCI_INTERFACE)
  66633. +#define REM_RETVAL(n)
  66634. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  66635. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  66636. +#elif defined(PLATFORM_INTERFACE)
  66637. +#define REM_RETVAL(n) n
  66638. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  66639. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  66640. +#endif
  66641. +
  66642. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  66643. +
  66644. + if (!otg_dev) {
  66645. + /* Memory allocation for the dwc_otg_device failed. */
  66646. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  66647. + return REM_RETVAL(-ENOMEM);
  66648. + }
  66649. +#ifndef DWC_DEVICE_ONLY
  66650. + if (otg_dev->hcd) {
  66651. + hcd_remove(_dev);
  66652. + } else {
  66653. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  66654. + return REM_RETVAL(-EINVAL);
  66655. + }
  66656. +#endif
  66657. +
  66658. +#ifndef DWC_HOST_ONLY
  66659. + if (otg_dev->pcd) {
  66660. + pcd_remove(_dev);
  66661. + } else {
  66662. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  66663. + return REM_RETVAL(-EINVAL);
  66664. + }
  66665. +#endif
  66666. + /*
  66667. + * Free the IRQ
  66668. + */
  66669. + if (otg_dev->common_irq_installed) {
  66670. +#ifdef PLATFORM_INTERFACE
  66671. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  66672. +#else
  66673. + free_irq(_dev->irq, otg_dev);
  66674. +#endif
  66675. + } else {
  66676. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  66677. + return REM_RETVAL(-ENXIO);
  66678. + }
  66679. +
  66680. + if (otg_dev->core_if) {
  66681. + dwc_otg_cil_remove(otg_dev->core_if);
  66682. + } else {
  66683. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  66684. + return REM_RETVAL(-ENXIO);
  66685. + }
  66686. +
  66687. + /*
  66688. + * Remove the device attributes
  66689. + */
  66690. + dwc_otg_attr_remove(_dev);
  66691. +
  66692. + /*
  66693. + * Return the memory.
  66694. + */
  66695. + if (otg_dev->os_dep.base) {
  66696. + iounmap(otg_dev->os_dep.base);
  66697. + }
  66698. + DWC_FREE(otg_dev);
  66699. +
  66700. + /*
  66701. + * Clear the drvdata pointer.
  66702. + */
  66703. +#ifdef LM_INTERFACE
  66704. + lm_set_drvdata(_dev, 0);
  66705. +#elif defined(PCI_INTERFACE)
  66706. + release_mem_region(otg_dev->os_dep.rsrc_start,
  66707. + otg_dev->os_dep.rsrc_len);
  66708. + pci_set_drvdata(_dev, 0);
  66709. +#elif defined(PLATFORM_INTERFACE)
  66710. + platform_set_drvdata(_dev, 0);
  66711. +#endif
  66712. + return REM_RETVAL(0);
  66713. +}
  66714. +
  66715. +/**
  66716. + * This function is called when an lm_device is bound to a
  66717. + * dwc_otg_driver. It creates the driver components required to
  66718. + * control the device (CIL, HCD, and PCD) and it initializes the
  66719. + * device. The driver components are stored in a dwc_otg_device
  66720. + * structure. A reference to the dwc_otg_device is saved in the
  66721. + * lm_device. This allows the driver to access the dwc_otg_device
  66722. + * structure on subsequent calls to driver methods for this device.
  66723. + *
  66724. + * @param _dev Bus device
  66725. + */
  66726. +static int dwc_otg_driver_probe(
  66727. +#ifdef LM_INTERFACE
  66728. + struct lm_device *_dev
  66729. +#elif defined(PCI_INTERFACE)
  66730. + struct pci_dev *_dev,
  66731. + const struct pci_device_id *id
  66732. +#elif defined(PLATFORM_INTERFACE)
  66733. + struct platform_device *_dev
  66734. +#endif
  66735. + )
  66736. +{
  66737. + int retval = 0;
  66738. + dwc_otg_device_t *dwc_otg_device;
  66739. + int devirq;
  66740. +
  66741. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  66742. +#ifdef LM_INTERFACE
  66743. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  66744. +#elif defined(PCI_INTERFACE)
  66745. + if (!id) {
  66746. + DWC_ERROR("Invalid pci_device_id %p", id);
  66747. + return -EINVAL;
  66748. + }
  66749. +
  66750. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  66751. + DWC_ERROR("Invalid pci_device %p", _dev);
  66752. + return -ENODEV;
  66753. + }
  66754. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  66755. + /* other stuff needed as well? */
  66756. +
  66757. +#elif defined(PLATFORM_INTERFACE)
  66758. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  66759. + (unsigned)_dev->resource->start,
  66760. + (unsigned)(_dev->resource->end - _dev->resource->start));
  66761. +#endif
  66762. +
  66763. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  66764. +
  66765. + if (!dwc_otg_device) {
  66766. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  66767. + return -ENOMEM;
  66768. + }
  66769. +
  66770. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  66771. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  66772. +
  66773. + /*
  66774. + * Map the DWC_otg Core memory into virtual address space.
  66775. + */
  66776. +#ifdef LM_INTERFACE
  66777. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  66778. +
  66779. + if (!dwc_otg_device->os_dep.base) {
  66780. + dev_err(&_dev->dev, "ioremap() failed\n");
  66781. + DWC_FREE(dwc_otg_device);
  66782. + return -ENOMEM;
  66783. + }
  66784. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66785. + (unsigned)dwc_otg_device->os_dep.base);
  66786. +#elif defined(PCI_INTERFACE)
  66787. + _dev->current_state = PCI_D0;
  66788. + _dev->dev.power.power_state = PMSG_ON;
  66789. +
  66790. + if (!_dev->irq) {
  66791. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  66792. + pci_name(_dev));
  66793. + iounmap(dwc_otg_device->os_dep.base);
  66794. + DWC_FREE(dwc_otg_device);
  66795. + return -ENODEV;
  66796. + }
  66797. +
  66798. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  66799. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  66800. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  66801. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66802. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  66803. + if (!request_mem_region
  66804. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  66805. + "dwc_otg")) {
  66806. + dev_dbg(&_dev->dev, "error requesting memory\n");
  66807. + iounmap(dwc_otg_device->os_dep.base);
  66808. + DWC_FREE(dwc_otg_device);
  66809. + return -EFAULT;
  66810. + }
  66811. +
  66812. + dwc_otg_device->os_dep.base =
  66813. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  66814. + dwc_otg_device->os_dep.rsrc_len);
  66815. + if (dwc_otg_device->os_dep.base == NULL) {
  66816. + dev_dbg(&_dev->dev, "error mapping memory\n");
  66817. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  66818. + dwc_otg_device->os_dep.rsrc_len);
  66819. + iounmap(dwc_otg_device->os_dep.base);
  66820. + DWC_FREE(dwc_otg_device);
  66821. + return -EFAULT;
  66822. + }
  66823. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  66824. + dwc_otg_device->os_dep.base);
  66825. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  66826. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  66827. + dwc_otg_device->os_dep.base);
  66828. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  66829. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66830. + dwc_otg_device->os_dep.base);
  66831. +
  66832. + pci_set_master(_dev);
  66833. + pci_set_drvdata(_dev, dwc_otg_device);
  66834. +#elif defined(PLATFORM_INTERFACE)
  66835. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  66836. + _dev->resource->start,
  66837. + _dev->resource->end - _dev->resource->start + 1);
  66838. +#if 1
  66839. + if (!request_mem_region(_dev->resource[0].start,
  66840. + _dev->resource[0].end - _dev->resource[0].start + 1,
  66841. + "dwc_otg")) {
  66842. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66843. + retval = -EFAULT;
  66844. + goto fail;
  66845. + }
  66846. +
  66847. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  66848. + _dev->resource[0].end -
  66849. + _dev->resource[0].start+1);
  66850. + if (fiq_fix_enable)
  66851. + {
  66852. + if (!request_mem_region(_dev->resource[1].start,
  66853. + _dev->resource[1].end - _dev->resource[1].start + 1,
  66854. + "dwc_otg")) {
  66855. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66856. + retval = -EFAULT;
  66857. + goto fail;
  66858. + }
  66859. +
  66860. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  66861. + _dev->resource[1].end -
  66862. + _dev->resource[1].start + 1);
  66863. + dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
  66864. + }
  66865. +
  66866. +#else
  66867. + {
  66868. + struct map_desc desc = {
  66869. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  66870. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  66871. + .length = SZ_128K,
  66872. + .type = MT_DEVICE
  66873. + };
  66874. + iotable_init(&desc, 1);
  66875. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  66876. + }
  66877. +#endif
  66878. + if (!dwc_otg_device->os_dep.base) {
  66879. + dev_err(&_dev->dev, "ioremap() failed\n");
  66880. + retval = -ENOMEM;
  66881. + goto fail;
  66882. + }
  66883. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66884. + (unsigned)dwc_otg_device->os_dep.base);
  66885. +#endif
  66886. +
  66887. + /*
  66888. + * Initialize driver data to point to the global DWC_otg
  66889. + * Device structure.
  66890. + */
  66891. +#ifdef LM_INTERFACE
  66892. + lm_set_drvdata(_dev, dwc_otg_device);
  66893. +#elif defined(PLATFORM_INTERFACE)
  66894. + platform_set_drvdata(_dev, dwc_otg_device);
  66895. +#endif
  66896. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  66897. +
  66898. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  66899. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  66900. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  66901. +
  66902. + if (!dwc_otg_device->core_if) {
  66903. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  66904. + retval = -ENOMEM;
  66905. + goto fail;
  66906. + }
  66907. +
  66908. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  66909. + /*
  66910. + * Attempt to ensure this device is really a DWC_otg Controller.
  66911. + * Read and verify the SNPSID register contents. The value should be
  66912. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  66913. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  66914. + */
  66915. +
  66916. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  66917. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  66918. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  66919. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  66920. + retval = -EINVAL;
  66921. + goto fail;
  66922. + }
  66923. +
  66924. + /*
  66925. + * Validate parameter values.
  66926. + */
  66927. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  66928. + if (set_parameters(dwc_otg_device->core_if)) {
  66929. + retval = -EINVAL;
  66930. + goto fail;
  66931. + }
  66932. +
  66933. + /*
  66934. + * Create Device Attributes in sysfs
  66935. + */
  66936. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  66937. + dwc_otg_attr_create(_dev);
  66938. +
  66939. + /*
  66940. + * Disable the global interrupt until all the interrupt
  66941. + * handlers are installed.
  66942. + */
  66943. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  66944. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  66945. +
  66946. + /*
  66947. + * Install the interrupt handler for the common interrupts before
  66948. + * enabling common interrupts in core_init below.
  66949. + */
  66950. +
  66951. +#if defined(PLATFORM_INTERFACE)
  66952. + devirq = platform_get_irq(_dev, 0);
  66953. +#else
  66954. + devirq = _dev->irq;
  66955. +#endif
  66956. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  66957. + devirq);
  66958. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  66959. + retval = request_irq(devirq, dwc_otg_common_irq,
  66960. + IRQF_SHARED,
  66961. + "dwc_otg", dwc_otg_device);
  66962. + if (retval) {
  66963. + DWC_ERROR("request of irq%d failed\n", devirq);
  66964. + retval = -EBUSY;
  66965. + goto fail;
  66966. + } else {
  66967. + dwc_otg_device->common_irq_installed = 1;
  66968. + }
  66969. +
  66970. +#ifndef IRQF_TRIGGER_LOW
  66971. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  66972. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  66973. + set_irq_type(devirq,
  66974. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  66975. + IRQT_LOW
  66976. +#else
  66977. + IRQ_TYPE_LEVEL_LOW
  66978. +#endif
  66979. + );
  66980. +#endif
  66981. +#endif /*IRQF_TRIGGER_LOW*/
  66982. +
  66983. + /*
  66984. + * Initialize the DWC_otg core.
  66985. + */
  66986. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  66987. + dwc_otg_core_init(dwc_otg_device->core_if);
  66988. +
  66989. +#ifndef DWC_HOST_ONLY
  66990. + /*
  66991. + * Initialize the PCD
  66992. + */
  66993. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  66994. + retval = pcd_init(_dev);
  66995. + if (retval != 0) {
  66996. + DWC_ERROR("pcd_init failed\n");
  66997. + dwc_otg_device->pcd = NULL;
  66998. + goto fail;
  66999. + }
  67000. +#endif
  67001. +#ifndef DWC_DEVICE_ONLY
  67002. + /*
  67003. + * Initialize the HCD
  67004. + */
  67005. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  67006. + retval = hcd_init(_dev);
  67007. + if (retval != 0) {
  67008. + DWC_ERROR("hcd_init failed\n");
  67009. + dwc_otg_device->hcd = NULL;
  67010. + goto fail;
  67011. + }
  67012. +#endif
  67013. + /* Recover from drvdata having been overwritten by hcd_init() */
  67014. +#ifdef LM_INTERFACE
  67015. + lm_set_drvdata(_dev, dwc_otg_device);
  67016. +#elif defined(PLATFORM_INTERFACE)
  67017. + platform_set_drvdata(_dev, dwc_otg_device);
  67018. +#elif defined(PCI_INTERFACE)
  67019. + pci_set_drvdata(_dev, dwc_otg_device);
  67020. + dwc_otg_device->os_dep.pcidev = _dev;
  67021. +#endif
  67022. +
  67023. + /*
  67024. + * Enable the global interrupt after all the interrupt
  67025. + * handlers are installed if there is no ADP support else
  67026. + * perform initial actions required for Internal ADP logic.
  67027. + */
  67028. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  67029. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  67030. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  67031. + dev_dbg(&_dev->dev, "Done\n");
  67032. + } else
  67033. + dwc_otg_adp_start(dwc_otg_device->core_if,
  67034. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  67035. +
  67036. + return 0;
  67037. +
  67038. +fail:
  67039. + dwc_otg_driver_remove(_dev);
  67040. + return retval;
  67041. +}
  67042. +
  67043. +/**
  67044. + * This structure defines the methods to be called by a bus driver
  67045. + * during the lifecycle of a device on that bus. Both drivers and
  67046. + * devices are registered with a bus driver. The bus driver matches
  67047. + * devices to drivers based on information in the device and driver
  67048. + * structures.
  67049. + *
  67050. + * The probe function is called when the bus driver matches a device
  67051. + * to this driver. The remove function is called when a device is
  67052. + * unregistered with the bus driver.
  67053. + */
  67054. +#ifdef LM_INTERFACE
  67055. +static struct lm_driver dwc_otg_driver = {
  67056. + .drv = {.name = (char *)dwc_driver_name,},
  67057. + .probe = dwc_otg_driver_probe,
  67058. + .remove = dwc_otg_driver_remove,
  67059. + // 'suspend' and 'resume' absent
  67060. +};
  67061. +#elif defined(PCI_INTERFACE)
  67062. +static const struct pci_device_id pci_ids[] = { {
  67063. + PCI_DEVICE(0x16c3, 0xabcd),
  67064. + .driver_data =
  67065. + (unsigned long)0xdeadbeef,
  67066. + }, { /* end: all zeroes */ }
  67067. +};
  67068. +
  67069. +MODULE_DEVICE_TABLE(pci, pci_ids);
  67070. +
  67071. +/* pci driver glue; this is a "new style" PCI driver module */
  67072. +static struct pci_driver dwc_otg_driver = {
  67073. + .name = "dwc_otg",
  67074. + .id_table = pci_ids,
  67075. +
  67076. + .probe = dwc_otg_driver_probe,
  67077. + .remove = dwc_otg_driver_remove,
  67078. +
  67079. + .driver = {
  67080. + .name = (char *)dwc_driver_name,
  67081. + },
  67082. +};
  67083. +#elif defined(PLATFORM_INTERFACE)
  67084. +static struct platform_device_id platform_ids[] = {
  67085. + {
  67086. + .name = "bcm2708_usb",
  67087. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  67088. + },
  67089. + { /* end: all zeroes */ }
  67090. +};
  67091. +MODULE_DEVICE_TABLE(platform, platform_ids);
  67092. +
  67093. +static struct platform_driver dwc_otg_driver = {
  67094. + .driver = {
  67095. + .name = (char *)dwc_driver_name,
  67096. + },
  67097. + .id_table = platform_ids,
  67098. +
  67099. + .probe = dwc_otg_driver_probe,
  67100. + .remove = dwc_otg_driver_remove,
  67101. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  67102. +};
  67103. +#endif
  67104. +
  67105. +/**
  67106. + * This function is called when the dwc_otg_driver is installed with the
  67107. + * insmod command. It registers the dwc_otg_driver structure with the
  67108. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  67109. + * to be called. In addition, the bus driver will automatically expose
  67110. + * attributes defined for the device and driver in the special sysfs file
  67111. + * system.
  67112. + *
  67113. + * @return
  67114. + */
  67115. +static int __init dwc_otg_driver_init(void)
  67116. +{
  67117. + int retval = 0;
  67118. + int error;
  67119. + struct device_driver *drv;
  67120. +
  67121. + if(fiq_split_enable && !fiq_fix_enable) {
  67122. + printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
  67123. + fiq_fix_enable = 1;
  67124. + }
  67125. +
  67126. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  67127. + DWC_DRIVER_VERSION,
  67128. +#ifdef LM_INTERFACE
  67129. + "logicmodule");
  67130. + retval = lm_driver_register(&dwc_otg_driver);
  67131. + drv = &dwc_otg_driver.drv;
  67132. +#elif defined(PCI_INTERFACE)
  67133. + "pci");
  67134. + retval = pci_register_driver(&dwc_otg_driver);
  67135. + drv = &dwc_otg_driver.driver;
  67136. +#elif defined(PLATFORM_INTERFACE)
  67137. + "platform");
  67138. + retval = platform_driver_register(&dwc_otg_driver);
  67139. + drv = &dwc_otg_driver.driver;
  67140. +#endif
  67141. + if (retval < 0) {
  67142. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  67143. + return retval;
  67144. + }
  67145. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
  67146. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
  67147. + printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
  67148. +
  67149. + error = driver_create_file(drv, &driver_attr_version);
  67150. +#ifdef DEBUG
  67151. + error = driver_create_file(drv, &driver_attr_debuglevel);
  67152. +#endif
  67153. + return retval;
  67154. +}
  67155. +
  67156. +module_init(dwc_otg_driver_init);
  67157. +
  67158. +/**
  67159. + * This function is called when the driver is removed from the kernel
  67160. + * with the rmmod command. The driver unregisters itself with its bus
  67161. + * driver.
  67162. + *
  67163. + */
  67164. +static void __exit dwc_otg_driver_cleanup(void)
  67165. +{
  67166. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  67167. +
  67168. +#ifdef LM_INTERFACE
  67169. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  67170. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  67171. + lm_driver_unregister(&dwc_otg_driver);
  67172. +#elif defined(PCI_INTERFACE)
  67173. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67174. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67175. + pci_unregister_driver(&dwc_otg_driver);
  67176. +#elif defined(PLATFORM_INTERFACE)
  67177. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67178. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67179. + platform_driver_unregister(&dwc_otg_driver);
  67180. +#endif
  67181. +
  67182. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  67183. +}
  67184. +
  67185. +module_exit(dwc_otg_driver_cleanup);
  67186. +
  67187. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  67188. +MODULE_AUTHOR("Synopsys Inc.");
  67189. +MODULE_LICENSE("GPL");
  67190. +
  67191. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  67192. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  67193. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  67194. +MODULE_PARM_DESC(opt, "OPT Mode");
  67195. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  67196. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  67197. +
  67198. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  67199. + 0444);
  67200. +MODULE_PARM_DESC(dma_desc_enable,
  67201. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  67202. +
  67203. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  67204. + 0444);
  67205. +MODULE_PARM_DESC(dma_burst_size,
  67206. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  67207. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  67208. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  67209. +module_param_named(host_support_fs_ls_low_power,
  67210. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  67211. + 0444);
  67212. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  67213. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  67214. +module_param_named(host_ls_low_power_phy_clk,
  67215. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  67216. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  67217. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  67218. +module_param_named(enable_dynamic_fifo,
  67219. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  67220. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  67221. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  67222. + 0444);
  67223. +MODULE_PARM_DESC(data_fifo_size,
  67224. + "Total number of words in the data FIFO memory 32-32768");
  67225. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  67226. + int, 0444);
  67227. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67228. +module_param_named(dev_nperio_tx_fifo_size,
  67229. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  67230. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  67231. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67232. +module_param_named(dev_perio_tx_fifo_size_1,
  67233. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  67234. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  67235. + "Number of words in the periodic Tx FIFO 4-768");
  67236. +module_param_named(dev_perio_tx_fifo_size_2,
  67237. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  67238. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  67239. + "Number of words in the periodic Tx FIFO 4-768");
  67240. +module_param_named(dev_perio_tx_fifo_size_3,
  67241. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  67242. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  67243. + "Number of words in the periodic Tx FIFO 4-768");
  67244. +module_param_named(dev_perio_tx_fifo_size_4,
  67245. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  67246. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  67247. + "Number of words in the periodic Tx FIFO 4-768");
  67248. +module_param_named(dev_perio_tx_fifo_size_5,
  67249. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  67250. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  67251. + "Number of words in the periodic Tx FIFO 4-768");
  67252. +module_param_named(dev_perio_tx_fifo_size_6,
  67253. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  67254. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  67255. + "Number of words in the periodic Tx FIFO 4-768");
  67256. +module_param_named(dev_perio_tx_fifo_size_7,
  67257. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  67258. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  67259. + "Number of words in the periodic Tx FIFO 4-768");
  67260. +module_param_named(dev_perio_tx_fifo_size_8,
  67261. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  67262. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  67263. + "Number of words in the periodic Tx FIFO 4-768");
  67264. +module_param_named(dev_perio_tx_fifo_size_9,
  67265. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  67266. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  67267. + "Number of words in the periodic Tx FIFO 4-768");
  67268. +module_param_named(dev_perio_tx_fifo_size_10,
  67269. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  67270. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  67271. + "Number of words in the periodic Tx FIFO 4-768");
  67272. +module_param_named(dev_perio_tx_fifo_size_11,
  67273. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  67274. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  67275. + "Number of words in the periodic Tx FIFO 4-768");
  67276. +module_param_named(dev_perio_tx_fifo_size_12,
  67277. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  67278. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  67279. + "Number of words in the periodic Tx FIFO 4-768");
  67280. +module_param_named(dev_perio_tx_fifo_size_13,
  67281. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  67282. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  67283. + "Number of words in the periodic Tx FIFO 4-768");
  67284. +module_param_named(dev_perio_tx_fifo_size_14,
  67285. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  67286. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  67287. + "Number of words in the periodic Tx FIFO 4-768");
  67288. +module_param_named(dev_perio_tx_fifo_size_15,
  67289. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  67290. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  67291. + "Number of words in the periodic Tx FIFO 4-768");
  67292. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  67293. + int, 0444);
  67294. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67295. +module_param_named(host_nperio_tx_fifo_size,
  67296. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  67297. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  67298. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67299. +module_param_named(host_perio_tx_fifo_size,
  67300. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  67301. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  67302. + "Number of words in the host periodic Tx FIFO 16-32768");
  67303. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  67304. + int, 0444);
  67305. +/** @todo Set the max to 512K, modify checks */
  67306. +MODULE_PARM_DESC(max_transfer_size,
  67307. + "The maximum transfer size supported in bytes 2047-65535");
  67308. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  67309. + int, 0444);
  67310. +MODULE_PARM_DESC(max_packet_count,
  67311. + "The maximum number of packets in a transfer 15-511");
  67312. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  67313. + 0444);
  67314. +MODULE_PARM_DESC(host_channels,
  67315. + "The number of host channel registers to use 1-16");
  67316. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  67317. + 0444);
  67318. +MODULE_PARM_DESC(dev_endpoints,
  67319. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  67320. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  67321. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  67322. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  67323. + 0444);
  67324. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  67325. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  67326. +MODULE_PARM_DESC(phy_ulpi_ddr,
  67327. + "ULPI at double or single data rate 0=Single 1=Double");
  67328. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  67329. + int, 0444);
  67330. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  67331. + "ULPI PHY using internal or external vbus 0=Internal");
  67332. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  67333. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  67334. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  67335. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  67336. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  67337. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  67338. +module_param_named(debug, g_dbg_lvl, int, 0444);
  67339. +MODULE_PARM_DESC(debug, "");
  67340. +
  67341. +module_param_named(en_multiple_tx_fifo,
  67342. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  67343. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  67344. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  67345. +module_param_named(dev_tx_fifo_size_1,
  67346. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  67347. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  67348. +module_param_named(dev_tx_fifo_size_2,
  67349. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  67350. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  67351. +module_param_named(dev_tx_fifo_size_3,
  67352. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  67353. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  67354. +module_param_named(dev_tx_fifo_size_4,
  67355. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  67356. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  67357. +module_param_named(dev_tx_fifo_size_5,
  67358. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  67359. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  67360. +module_param_named(dev_tx_fifo_size_6,
  67361. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  67362. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  67363. +module_param_named(dev_tx_fifo_size_7,
  67364. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  67365. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  67366. +module_param_named(dev_tx_fifo_size_8,
  67367. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  67368. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  67369. +module_param_named(dev_tx_fifo_size_9,
  67370. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  67371. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  67372. +module_param_named(dev_tx_fifo_size_10,
  67373. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  67374. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  67375. +module_param_named(dev_tx_fifo_size_11,
  67376. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  67377. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  67378. +module_param_named(dev_tx_fifo_size_12,
  67379. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  67380. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  67381. +module_param_named(dev_tx_fifo_size_13,
  67382. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  67383. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  67384. +module_param_named(dev_tx_fifo_size_14,
  67385. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  67386. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  67387. +module_param_named(dev_tx_fifo_size_15,
  67388. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  67389. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  67390. +
  67391. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  67392. +MODULE_PARM_DESC(thr_ctl,
  67393. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  67394. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  67395. + 0444);
  67396. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  67397. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  67398. + 0444);
  67399. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  67400. +
  67401. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  67402. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  67403. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  67404. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  67405. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  67406. +MODULE_PARM_DESC(ic_usb_cap,
  67407. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  67408. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  67409. + 0444);
  67410. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  67411. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  67412. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  67413. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  67414. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  67415. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  67416. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  67417. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  67418. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  67419. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  67420. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  67421. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  67422. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  67423. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  67424. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  67425. +module_param(microframe_schedule, bool, 0444);
  67426. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  67427. +
  67428. +module_param(fiq_fix_enable, bool, 0444);
  67429. +MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
  67430. +module_param(nak_holdoff_enable, bool, 0444);
  67431. +MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
  67432. +module_param(fiq_split_enable, bool, 0444);
  67433. +MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
  67434. +
  67435. +/** @page "Module Parameters"
  67436. + *
  67437. + * The following parameters may be specified when starting the module.
  67438. + * These parameters define how the DWC_otg controller should be
  67439. + * configured. Parameter values are passed to the CIL initialization
  67440. + * function dwc_otg_cil_init
  67441. + *
  67442. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  67443. + *
  67444. +
  67445. + <table>
  67446. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  67447. +
  67448. + <tr>
  67449. + <td>otg_cap</td>
  67450. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  67451. + value for this parameter if none is specified.
  67452. + - 0: HNP and SRP capable (default, if available)
  67453. + - 1: SRP Only capable
  67454. + - 2: No HNP/SRP capable
  67455. + </td></tr>
  67456. +
  67457. + <tr>
  67458. + <td>dma_enable</td>
  67459. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  67460. + The driver will automatically detect the value for this parameter if none is
  67461. + specified.
  67462. + - 0: Slave
  67463. + - 1: DMA (default, if available)
  67464. + </td></tr>
  67465. +
  67466. + <tr>
  67467. + <td>dma_burst_size</td>
  67468. + <td>The DMA Burst size (applicable only for External DMA Mode).
  67469. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  67470. + </td></tr>
  67471. +
  67472. + <tr>
  67473. + <td>speed</td>
  67474. + <td>Specifies the maximum speed of operation in host and device mode. The
  67475. + actual speed depends on the speed of the attached device and the value of
  67476. + phy_type.
  67477. + - 0: High Speed (default)
  67478. + - 1: Full Speed
  67479. + </td></tr>
  67480. +
  67481. + <tr>
  67482. + <td>host_support_fs_ls_low_power</td>
  67483. + <td>Specifies whether low power mode is supported when attached to a Full
  67484. + Speed or Low Speed device in host mode.
  67485. + - 0: Don't support low power mode (default)
  67486. + - 1: Support low power mode
  67487. + </td></tr>
  67488. +
  67489. + <tr>
  67490. + <td>host_ls_low_power_phy_clk</td>
  67491. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  67492. + Speed device in host mode. This parameter is applicable only if
  67493. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  67494. + - 0: 48 MHz (default)
  67495. + - 1: 6 MHz
  67496. + </td></tr>
  67497. +
  67498. + <tr>
  67499. + <td>enable_dynamic_fifo</td>
  67500. + <td> Specifies whether FIFOs may be resized by the driver software.
  67501. + - 0: Use cC FIFO size parameters
  67502. + - 1: Allow dynamic FIFO sizing (default)
  67503. + </td></tr>
  67504. +
  67505. + <tr>
  67506. + <td>data_fifo_size</td>
  67507. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  67508. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  67509. + - Values: 32 to 32768 (default 8192)
  67510. +
  67511. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  67512. + </td></tr>
  67513. +
  67514. + <tr>
  67515. + <td>dev_rx_fifo_size</td>
  67516. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  67517. + FIFO sizing is enabled.
  67518. + - Values: 16 to 32768 (default 1064)
  67519. + </td></tr>
  67520. +
  67521. + <tr>
  67522. + <td>dev_nperio_tx_fifo_size</td>
  67523. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  67524. + dynamic FIFO sizing is enabled.
  67525. + - Values: 16 to 32768 (default 1024)
  67526. + </td></tr>
  67527. +
  67528. + <tr>
  67529. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  67530. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  67531. + when dynamic FIFO sizing is enabled.
  67532. + - Values: 4 to 768 (default 256)
  67533. + </td></tr>
  67534. +
  67535. + <tr>
  67536. + <td>host_rx_fifo_size</td>
  67537. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  67538. + sizing is enabled.
  67539. + - Values: 16 to 32768 (default 1024)
  67540. + </td></tr>
  67541. +
  67542. + <tr>
  67543. + <td>host_nperio_tx_fifo_size</td>
  67544. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  67545. + dynamic FIFO sizing is enabled in the core.
  67546. + - Values: 16 to 32768 (default 1024)
  67547. + </td></tr>
  67548. +
  67549. + <tr>
  67550. + <td>host_perio_tx_fifo_size</td>
  67551. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  67552. + sizing is enabled.
  67553. + - Values: 16 to 32768 (default 1024)
  67554. + </td></tr>
  67555. +
  67556. + <tr>
  67557. + <td>max_transfer_size</td>
  67558. + <td>The maximum transfer size supported in bytes.
  67559. + - Values: 2047 to 65,535 (default 65,535)
  67560. + </td></tr>
  67561. +
  67562. + <tr>
  67563. + <td>max_packet_count</td>
  67564. + <td>The maximum number of packets in a transfer.
  67565. + - Values: 15 to 511 (default 511)
  67566. + </td></tr>
  67567. +
  67568. + <tr>
  67569. + <td>host_channels</td>
  67570. + <td>The number of host channel registers to use.
  67571. + - Values: 1 to 16 (default 12)
  67572. +
  67573. + Note: The FPGA configuration supports a maximum of 12 host channels.
  67574. + </td></tr>
  67575. +
  67576. + <tr>
  67577. + <td>dev_endpoints</td>
  67578. + <td>The number of endpoints in addition to EP0 available for device mode
  67579. + operations.
  67580. + - Values: 1 to 15 (default 6 IN and OUT)
  67581. +
  67582. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  67583. + addition to EP0.
  67584. + </td></tr>
  67585. +
  67586. + <tr>
  67587. + <td>phy_type</td>
  67588. + <td>Specifies the type of PHY interface to use. By default, the driver will
  67589. + automatically detect the phy_type.
  67590. + - 0: Full Speed
  67591. + - 1: UTMI+ (default, if available)
  67592. + - 2: ULPI
  67593. + </td></tr>
  67594. +
  67595. + <tr>
  67596. + <td>phy_utmi_width</td>
  67597. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  67598. + phy_type of UTMI+. Also, this parameter is applicable only if the
  67599. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  67600. + core has been configured to work at either data path width.
  67601. + - Values: 8 or 16 bits (default 16)
  67602. + </td></tr>
  67603. +
  67604. + <tr>
  67605. + <td>phy_ulpi_ddr</td>
  67606. + <td>Specifies whether the ULPI operates at double or single data rate. This
  67607. + parameter is only applicable if phy_type is ULPI.
  67608. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  67609. + - 1: double data rate ULPI interface with 4 bit wide data bus
  67610. + </td></tr>
  67611. +
  67612. + <tr>
  67613. + <td>i2c_enable</td>
  67614. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  67615. + parameter is only applicable if PHY_TYPE is FS.
  67616. + - 0: Disabled (default)
  67617. + - 1: Enabled
  67618. + </td></tr>
  67619. +
  67620. + <tr>
  67621. + <td>ulpi_fs_ls</td>
  67622. + <td>Specifies whether to use ULPI FS/LS mode only.
  67623. + - 0: Disabled (default)
  67624. + - 1: Enabled
  67625. + </td></tr>
  67626. +
  67627. + <tr>
  67628. + <td>ts_dline</td>
  67629. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  67630. + - 0: Disabled (default)
  67631. + - 1: Enabled
  67632. + </td></tr>
  67633. +
  67634. + <tr>
  67635. + <td>en_multiple_tx_fifo</td>
  67636. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  67637. + The driver will automatically detect the value for this parameter if none is
  67638. + specified.
  67639. + - 0: Disabled
  67640. + - 1: Enabled (default, if available)
  67641. + </td></tr>
  67642. +
  67643. + <tr>
  67644. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  67645. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  67646. + when dynamic FIFO sizing is enabled.
  67647. + - Values: 4 to 768 (default 256)
  67648. + </td></tr>
  67649. +
  67650. + <tr>
  67651. + <td>tx_thr_length</td>
  67652. + <td>Transmit Threshold length in 32 bit double words
  67653. + - Values: 8 to 128 (default 64)
  67654. + </td></tr>
  67655. +
  67656. + <tr>
  67657. + <td>rx_thr_length</td>
  67658. + <td>Receive Threshold length in 32 bit double words
  67659. + - Values: 8 to 128 (default 64)
  67660. + </td></tr>
  67661. +
  67662. +<tr>
  67663. + <td>thr_ctl</td>
  67664. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  67665. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  67666. + Rx transfers accordingly.
  67667. + The driver will automatically detect the value for this parameter if none is
  67668. + specified.
  67669. + - Values: 0 to 7 (default 0)
  67670. + Bit values indicate:
  67671. + - 0: Thresholding disabled
  67672. + - 1: Thresholding enabled
  67673. + </td></tr>
  67674. +
  67675. +<tr>
  67676. + <td>dma_desc_enable</td>
  67677. + <td>Specifies whether to enable Descriptor DMA mode.
  67678. + The driver will automatically detect the value for this parameter if none is
  67679. + specified.
  67680. + - 0: Descriptor DMA disabled
  67681. + - 1: Descriptor DMA (default, if available)
  67682. + </td></tr>
  67683. +
  67684. +<tr>
  67685. + <td>mpi_enable</td>
  67686. + <td>Specifies whether to enable MPI enhancement mode.
  67687. + The driver will automatically detect the value for this parameter if none is
  67688. + specified.
  67689. + - 0: MPI disabled (default)
  67690. + - 1: MPI enable
  67691. + </td></tr>
  67692. +
  67693. +<tr>
  67694. + <td>pti_enable</td>
  67695. + <td>Specifies whether to enable PTI enhancement support.
  67696. + The driver will automatically detect the value for this parameter if none is
  67697. + specified.
  67698. + - 0: PTI disabled (default)
  67699. + - 1: PTI enable
  67700. + </td></tr>
  67701. +
  67702. +<tr>
  67703. + <td>lpm_enable</td>
  67704. + <td>Specifies whether to enable LPM support.
  67705. + The driver will automatically detect the value for this parameter if none is
  67706. + specified.
  67707. + - 0: LPM disabled
  67708. + - 1: LPM enable (default, if available)
  67709. + </td></tr>
  67710. +
  67711. +<tr>
  67712. + <td>ic_usb_cap</td>
  67713. + <td>Specifies whether to enable IC_USB capability.
  67714. + The driver will automatically detect the value for this parameter if none is
  67715. + specified.
  67716. + - 0: IC_USB disabled (default, if available)
  67717. + - 1: IC_USB enable
  67718. + </td></tr>
  67719. +
  67720. +<tr>
  67721. + <td>ahb_thr_ratio</td>
  67722. + <td>Specifies AHB Threshold ratio.
  67723. + - Values: 0 to 3 (default 0)
  67724. + </td></tr>
  67725. +
  67726. +<tr>
  67727. + <td>power_down</td>
  67728. + <td>Specifies Power Down(Hibernation) Mode.
  67729. + The driver will automatically detect the value for this parameter if none is
  67730. + specified.
  67731. + - 0: Power Down disabled (default)
  67732. + - 2: Power Down enabled
  67733. + </td></tr>
  67734. +
  67735. + <tr>
  67736. + <td>reload_ctl</td>
  67737. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  67738. + run time. The driver will automatically detect the value for this parameter if
  67739. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  67740. + the core might misbehave.
  67741. + - 0: Reload Control disabled (default)
  67742. + - 1: Reload Control enabled
  67743. + </td></tr>
  67744. +
  67745. + <tr>
  67746. + <td>dev_out_nak</td>
  67747. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  67748. + The driver will automatically detect the value for this parameter if
  67749. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67750. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  67751. + - 1: The core sets NAK after Bulk OUT transfer complete
  67752. + </td></tr>
  67753. +
  67754. + <tr>
  67755. + <td>cont_on_bna</td>
  67756. + <td>Specifies whether Enable Continue on BNA enabled or no.
  67757. + After receiving BNA interrupt the core disables the endpoint,when the
  67758. + endpoint is re-enabled by the application the
  67759. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  67760. + - 1: Core starts processing from the descriptor which received the BNA.
  67761. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67762. + </td></tr>
  67763. +
  67764. + <tr>
  67765. + <td>ahb_single</td>
  67766. + <td>This bit when programmed supports SINGLE transfers for remainder data
  67767. + in a transfer for DMA mode of operation.
  67768. + - 0: The remainder data will be sent using INCR burst size (default)
  67769. + - 1: The remainder data will be sent using SINGLE burst size.
  67770. + </td></tr>
  67771. +
  67772. +<tr>
  67773. + <td>adp_enable</td>
  67774. + <td>Specifies whether ADP feature is enabled.
  67775. + The driver will automatically detect the value for this parameter if none is
  67776. + specified.
  67777. + - 0: ADP feature disabled (default)
  67778. + - 1: ADP feature enabled
  67779. + </td></tr>
  67780. +
  67781. + <tr>
  67782. + <td>otg_ver</td>
  67783. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  67784. + USB OTG device.
  67785. + - 0: OTG 2.0 support disabled (default)
  67786. + - 1: OTG 2.0 support enabled
  67787. + </td></tr>
  67788. +
  67789. +*/
  67790. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  67791. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  67792. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-02-07 19:57:30.000000000 +0100
  67793. @@ -0,0 +1,86 @@
  67794. +/* ==========================================================================
  67795. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  67796. + * $Revision: #19 $
  67797. + * $Date: 2010/11/15 $
  67798. + * $Change: 1627671 $
  67799. + *
  67800. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67801. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67802. + * otherwise expressly agreed to in writing between Synopsys and you.
  67803. + *
  67804. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67805. + * any End User Software License Agreement or Agreement for Licensed Product
  67806. + * with Synopsys or any supplement thereto. You are permitted to use and
  67807. + * redistribute this Software in source and binary forms, with or without
  67808. + * modification, provided that redistributions of source code must retain this
  67809. + * notice. You may not view, use, disclose, copy or distribute this file or
  67810. + * any information contained herein except pursuant to this license grant from
  67811. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67812. + * below, then you are not authorized to use the Software.
  67813. + *
  67814. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67815. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67816. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67817. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67818. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67819. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67820. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67821. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67822. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67823. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67824. + * DAMAGE.
  67825. + * ========================================================================== */
  67826. +
  67827. +#ifndef __DWC_OTG_DRIVER_H__
  67828. +#define __DWC_OTG_DRIVER_H__
  67829. +
  67830. +/** @file
  67831. + * This file contains the interface to the Linux driver.
  67832. + */
  67833. +#include "dwc_otg_os_dep.h"
  67834. +#include "dwc_otg_core_if.h"
  67835. +
  67836. +/* Type declarations */
  67837. +struct dwc_otg_pcd;
  67838. +struct dwc_otg_hcd;
  67839. +
  67840. +/**
  67841. + * This structure is a wrapper that encapsulates the driver components used to
  67842. + * manage a single DWC_otg controller.
  67843. + */
  67844. +typedef struct dwc_otg_device {
  67845. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  67846. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  67847. + * require this. */
  67848. + struct os_dependent os_dep;
  67849. +
  67850. + /** Pointer to the core interface structure. */
  67851. + dwc_otg_core_if_t *core_if;
  67852. +
  67853. + /** Pointer to the PCD structure. */
  67854. + struct dwc_otg_pcd *pcd;
  67855. +
  67856. + /** Pointer to the HCD structure. */
  67857. + struct dwc_otg_hcd *hcd;
  67858. +
  67859. + /** Flag to indicate whether the common IRQ handler is installed. */
  67860. + uint8_t common_irq_installed;
  67861. +
  67862. +} dwc_otg_device_t;
  67863. +
  67864. +/*We must clear S3C24XX_EINTPEND external interrupt register
  67865. + * because after clearing in this register trigerred IRQ from
  67866. + * H/W core in kernel interrupt can be occured again before OTG
  67867. + * handlers clear all IRQ sources of Core registers because of
  67868. + * timing latencies and Low Level IRQ Type.
  67869. + */
  67870. +#ifdef CONFIG_MACH_IPMATE
  67871. +#define S3C2410X_CLEAR_EINTPEND() \
  67872. +do { \
  67873. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  67874. +} while (0)
  67875. +#else
  67876. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  67877. +#endif
  67878. +
  67879. +#endif
  67880. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  67881. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  67882. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-02-07 19:57:30.000000000 +0100
  67883. @@ -0,0 +1,3674 @@
  67884. +
  67885. +/* ==========================================================================
  67886. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  67887. + * $Revision: #104 $
  67888. + * $Date: 2011/10/24 $
  67889. + * $Change: 1871159 $
  67890. + *
  67891. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67892. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67893. + * otherwise expressly agreed to in writing between Synopsys and you.
  67894. + *
  67895. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67896. + * any End User Software License Agreement or Agreement for Licensed Product
  67897. + * with Synopsys or any supplement thereto. You are permitted to use and
  67898. + * redistribute this Software in source and binary forms, with or without
  67899. + * modification, provided that redistributions of source code must retain this
  67900. + * notice. You may not view, use, disclose, copy or distribute this file or
  67901. + * any information contained herein except pursuant to this license grant from
  67902. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67903. + * below, then you are not authorized to use the Software.
  67904. + *
  67905. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67906. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67907. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67908. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67909. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67910. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67911. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67912. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67913. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67914. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67915. + * DAMAGE.
  67916. + * ========================================================================== */
  67917. +#ifndef DWC_DEVICE_ONLY
  67918. +
  67919. +/** @file
  67920. + * This file implements HCD Core. All code in this file is portable and doesn't
  67921. + * use any OS specific functions.
  67922. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  67923. + * header file.
  67924. + */
  67925. +
  67926. +#include <linux/usb.h>
  67927. +#include <linux/usb/hcd.h>
  67928. +
  67929. +#include "dwc_otg_hcd.h"
  67930. +#include "dwc_otg_regs.h"
  67931. +#include "dwc_otg_mphi_fix.h"
  67932. +
  67933. +extern bool microframe_schedule, nak_holdoff_enable;
  67934. +
  67935. +//#define DEBUG_HOST_CHANNELS
  67936. +#ifdef DEBUG_HOST_CHANNELS
  67937. +static int last_sel_trans_num_per_scheduled = 0;
  67938. +static int last_sel_trans_num_nonper_scheduled = 0;
  67939. +static int last_sel_trans_num_avail_hc_at_start = 0;
  67940. +static int last_sel_trans_num_avail_hc_at_end = 0;
  67941. +#endif /* DEBUG_HOST_CHANNELS */
  67942. +
  67943. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  67944. +
  67945. +extern haint_data_t haint_saved;
  67946. +extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  67947. +extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  67948. +extern gintsts_data_t ginsts_saved;
  67949. +
  67950. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  67951. +{
  67952. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  67953. +}
  67954. +
  67955. +/**
  67956. + * Connection timeout function. An OTG host is required to display a
  67957. + * message if the device does not connect within 10 seconds.
  67958. + */
  67959. +void dwc_otg_hcd_connect_timeout(void *ptr)
  67960. +{
  67961. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  67962. + DWC_PRINTF("Connect Timeout\n");
  67963. + __DWC_ERROR("Device Not Connected/Responding\n");
  67964. +}
  67965. +
  67966. +#if defined(DEBUG)
  67967. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  67968. +{
  67969. + if (qh->channel != NULL) {
  67970. + dwc_hc_t *hc = qh->channel;
  67971. + dwc_list_link_t *item;
  67972. + dwc_otg_qh_t *qh_item;
  67973. + int num_channels = hcd->core_if->core_params->host_channels;
  67974. + int i;
  67975. +
  67976. + dwc_otg_hc_regs_t *hc_regs;
  67977. + hcchar_data_t hcchar;
  67978. + hcsplt_data_t hcsplt;
  67979. + hctsiz_data_t hctsiz;
  67980. + uint32_t hcdma;
  67981. +
  67982. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  67983. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  67984. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  67985. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  67986. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  67987. +
  67988. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  67989. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  67990. + hcsplt.d32);
  67991. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  67992. + hcdma);
  67993. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  67994. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  67995. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  67996. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  67997. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  67998. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  67999. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  68000. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  68001. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  68002. + DWC_PRINTF(" qh: %p\n", hc->qh);
  68003. + DWC_PRINTF(" NP inactive sched:\n");
  68004. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  68005. + qh_item =
  68006. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68007. + DWC_PRINTF(" %p\n", qh_item);
  68008. + }
  68009. + DWC_PRINTF(" NP active sched:\n");
  68010. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  68011. + qh_item =
  68012. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68013. + DWC_PRINTF(" %p\n", qh_item);
  68014. + }
  68015. + DWC_PRINTF(" Channels: \n");
  68016. + for (i = 0; i < num_channels; i++) {
  68017. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  68018. + DWC_PRINTF(" %2d: %p\n", i, hc);
  68019. + }
  68020. + }
  68021. +}
  68022. +#else
  68023. +#define dump_channel_info(hcd, qh)
  68024. +#endif /* DEBUG */
  68025. +
  68026. +/**
  68027. + * Work queue function for starting the HCD when A-Cable is connected.
  68028. + * The hcd_start() must be called in a process context.
  68029. + */
  68030. +static void hcd_start_func(void *_vp)
  68031. +{
  68032. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  68033. +
  68034. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  68035. + if (hcd) {
  68036. + hcd->fops->start(hcd);
  68037. + }
  68038. +}
  68039. +
  68040. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  68041. +{
  68042. +#ifdef DEBUG
  68043. + int i;
  68044. + int num_channels = hcd->core_if->core_params->host_channels;
  68045. + for (i = 0; i < num_channels; i++) {
  68046. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  68047. + }
  68048. +#endif
  68049. +}
  68050. +
  68051. +static void del_timers(dwc_otg_hcd_t * hcd)
  68052. +{
  68053. + del_xfer_timers(hcd);
  68054. + DWC_TIMER_CANCEL(hcd->conn_timer);
  68055. +}
  68056. +
  68057. +/**
  68058. + * Processes all the URBs in a single list of QHs. Completes them with
  68059. + * -ESHUTDOWN and frees the QTD.
  68060. + */
  68061. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  68062. +{
  68063. + dwc_list_link_t *qh_item, *qh_tmp;
  68064. + dwc_otg_qh_t *qh;
  68065. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  68066. +
  68067. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  68068. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  68069. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  68070. + &qh->qtd_list, qtd_list_entry) {
  68071. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68072. + if (qtd->urb != NULL) {
  68073. + hcd->fops->complete(hcd, qtd->urb->priv,
  68074. + qtd->urb, -DWC_E_SHUTDOWN);
  68075. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  68076. + }
  68077. +
  68078. + }
  68079. + if(qh->channel) {
  68080. + /* Using hcchar.chen == 1 is not a reliable test.
  68081. + * It is possible that the channel has already halted
  68082. + * but not yet been through the IRQ handler.
  68083. + */
  68084. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  68085. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  68086. + if(microframe_schedule)
  68087. + hcd->available_host_channels++;
  68088. + qh->channel = NULL;
  68089. + }
  68090. + dwc_otg_hcd_qh_remove(hcd, qh);
  68091. + }
  68092. +}
  68093. +
  68094. +/**
  68095. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  68096. + * and periodic schedules. The QTD associated with each URB is removed from
  68097. + * the schedule and freed. This function may be called when a disconnect is
  68098. + * detected or when the HCD is being stopped.
  68099. + */
  68100. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  68101. +{
  68102. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  68103. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  68104. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  68105. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  68106. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  68107. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  68108. +}
  68109. +
  68110. +/**
  68111. + * Start the connection timer. An OTG host is required to display a
  68112. + * message if the device does not connect within 10 seconds. The
  68113. + * timer is deleted if a port connect interrupt occurs before the
  68114. + * timer expires.
  68115. + */
  68116. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  68117. +{
  68118. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  68119. +}
  68120. +
  68121. +/**
  68122. + * HCD Callback function for disconnect of the HCD.
  68123. + *
  68124. + * @param p void pointer to the <code>struct usb_hcd</code>
  68125. + */
  68126. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  68127. +{
  68128. + dwc_otg_hcd_t *dwc_otg_hcd;
  68129. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  68130. + dwc_otg_hcd = p;
  68131. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  68132. + return 1;
  68133. +}
  68134. +
  68135. +/**
  68136. + * HCD Callback function for starting the HCD when A-Cable is
  68137. + * connected.
  68138. + *
  68139. + * @param p void pointer to the <code>struct usb_hcd</code>
  68140. + */
  68141. +static int32_t dwc_otg_hcd_start_cb(void *p)
  68142. +{
  68143. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68144. + dwc_otg_core_if_t *core_if;
  68145. + hprt0_data_t hprt0;
  68146. +
  68147. + core_if = dwc_otg_hcd->core_if;
  68148. +
  68149. + if (core_if->op_state == B_HOST) {
  68150. + /*
  68151. + * Reset the port. During a HNP mode switch the reset
  68152. + * needs to occur within 1ms and have a duration of at
  68153. + * least 50ms.
  68154. + */
  68155. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  68156. + hprt0.b.prtrst = 1;
  68157. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  68158. + }
  68159. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  68160. + hcd_start_func, dwc_otg_hcd, 50,
  68161. + "start hcd");
  68162. +
  68163. + return 1;
  68164. +}
  68165. +
  68166. +/**
  68167. + * HCD Callback function for disconnect of the HCD.
  68168. + *
  68169. + * @param p void pointer to the <code>struct usb_hcd</code>
  68170. + */
  68171. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  68172. +{
  68173. + gintsts_data_t intr;
  68174. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68175. +
  68176. + /*
  68177. + * Set status flags for the hub driver.
  68178. + */
  68179. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  68180. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  68181. + if(fiq_fix_enable)
  68182. + local_fiq_disable();
  68183. + /*
  68184. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  68185. + * interrupt mask and status bits and disabling subsequent host
  68186. + * channel interrupts.
  68187. + */
  68188. + intr.d32 = 0;
  68189. + intr.b.nptxfempty = 1;
  68190. + intr.b.ptxfempty = 1;
  68191. + intr.b.hcintr = 1;
  68192. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  68193. + intr.d32, 0);
  68194. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  68195. + intr.d32, 0);
  68196. +
  68197. + del_timers(dwc_otg_hcd);
  68198. +
  68199. + /*
  68200. + * Turn off the vbus power only if the core has transitioned to device
  68201. + * mode. If still in host mode, need to keep power on to detect a
  68202. + * reconnection.
  68203. + */
  68204. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  68205. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  68206. + hprt0_data_t hprt0 = {.d32 = 0 };
  68207. + DWC_PRINTF("Disconnect: PortPower off\n");
  68208. + hprt0.b.prtpwr = 0;
  68209. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  68210. + hprt0.d32);
  68211. + }
  68212. +
  68213. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  68214. + }
  68215. +
  68216. + /* Respond with an error status to all URBs in the schedule. */
  68217. + kill_all_urbs(dwc_otg_hcd);
  68218. +
  68219. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  68220. + /* Clean up any host channels that were in use. */
  68221. + int num_channels;
  68222. + int i;
  68223. + dwc_hc_t *channel;
  68224. + dwc_otg_hc_regs_t *hc_regs;
  68225. + hcchar_data_t hcchar;
  68226. +
  68227. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  68228. +
  68229. + if (!dwc_otg_hcd->core_if->dma_enable) {
  68230. + /* Flush out any channel requests in slave mode. */
  68231. + for (i = 0; i < num_channels; i++) {
  68232. + channel = dwc_otg_hcd->hc_ptr_array[i];
  68233. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  68234. + (channel, hc_list_entry)) {
  68235. + hc_regs =
  68236. + dwc_otg_hcd->core_if->
  68237. + host_if->hc_regs[i];
  68238. + hcchar.d32 =
  68239. + DWC_READ_REG32(&hc_regs->hcchar);
  68240. + if (hcchar.b.chen) {
  68241. + hcchar.b.chen = 0;
  68242. + hcchar.b.chdis = 1;
  68243. + hcchar.b.epdir = 0;
  68244. + DWC_WRITE_REG32
  68245. + (&hc_regs->hcchar,
  68246. + hcchar.d32);
  68247. + }
  68248. + }
  68249. + }
  68250. + }
  68251. +
  68252. + for (i = 0; i < num_channels; i++) {
  68253. + channel = dwc_otg_hcd->hc_ptr_array[i];
  68254. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  68255. + hc_regs =
  68256. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  68257. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  68258. + if (hcchar.b.chen) {
  68259. + /* Halt the channel. */
  68260. + hcchar.b.chdis = 1;
  68261. + DWC_WRITE_REG32(&hc_regs->hcchar,
  68262. + hcchar.d32);
  68263. + }
  68264. +
  68265. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  68266. + channel);
  68267. + DWC_CIRCLEQ_INSERT_TAIL
  68268. + (&dwc_otg_hcd->free_hc_list, channel,
  68269. + hc_list_entry);
  68270. + /*
  68271. + * Added for Descriptor DMA to prevent channel double cleanup
  68272. + * in release_channel_ddma(). Which called from ep_disable
  68273. + * when device disconnect.
  68274. + */
  68275. + channel->qh = NULL;
  68276. + }
  68277. + }
  68278. + if(fiq_split_enable) {
  68279. + for(i=0; i < 128; i++) {
  68280. + dwc_otg_hcd->hub_port[i] = 0;
  68281. + }
  68282. + haint_saved.d32 = 0;
  68283. + for(i=0; i < MAX_EPS_CHANNELS; i++) {
  68284. + hcint_saved[i].d32 = 0;
  68285. + hcintmsk_saved[i].d32 = 0;
  68286. + }
  68287. + }
  68288. +
  68289. + }
  68290. +
  68291. + if(fiq_fix_enable)
  68292. + local_fiq_enable();
  68293. +
  68294. + if (dwc_otg_hcd->fops->disconnect) {
  68295. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  68296. + }
  68297. +
  68298. + return 1;
  68299. +}
  68300. +
  68301. +/**
  68302. + * HCD Callback function for stopping the HCD.
  68303. + *
  68304. + * @param p void pointer to the <code>struct usb_hcd</code>
  68305. + */
  68306. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  68307. +{
  68308. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  68309. +
  68310. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  68311. + dwc_otg_hcd_stop(dwc_otg_hcd);
  68312. + return 1;
  68313. +}
  68314. +
  68315. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68316. +/**
  68317. + * HCD Callback function for sleep of HCD.
  68318. + *
  68319. + * @param p void pointer to the <code>struct usb_hcd</code>
  68320. + */
  68321. +static int dwc_otg_hcd_sleep_cb(void *p)
  68322. +{
  68323. + dwc_otg_hcd_t *hcd = p;
  68324. +
  68325. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  68326. +
  68327. + return 0;
  68328. +}
  68329. +#endif
  68330. +
  68331. +
  68332. +/**
  68333. + * HCD Callback function for Remote Wakeup.
  68334. + *
  68335. + * @param p void pointer to the <code>struct usb_hcd</code>
  68336. + */
  68337. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  68338. +{
  68339. + dwc_otg_hcd_t *hcd = p;
  68340. +
  68341. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  68342. + hcd->flags.b.port_suspend_change = 1;
  68343. + }
  68344. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68345. + else {
  68346. + hcd->flags.b.port_l1_change = 1;
  68347. + }
  68348. +#endif
  68349. + return 0;
  68350. +}
  68351. +
  68352. +/**
  68353. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  68354. + * stopped.
  68355. + */
  68356. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  68357. +{
  68358. + hprt0_data_t hprt0 = {.d32 = 0 };
  68359. +
  68360. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  68361. +
  68362. + /*
  68363. + * The root hub should be disconnected before this function is called.
  68364. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  68365. + * and the QH lists (via ..._hcd_endpoint_disable).
  68366. + */
  68367. +
  68368. + /* Turn off all host-specific interrupts. */
  68369. + dwc_otg_disable_host_interrupts(hcd->core_if);
  68370. +
  68371. + /* Turn off the vbus power */
  68372. + DWC_PRINTF("PortPower off\n");
  68373. + hprt0.b.prtpwr = 0;
  68374. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  68375. + dwc_mdelay(1);
  68376. +}
  68377. +
  68378. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  68379. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  68380. + int atomic_alloc)
  68381. +{
  68382. + int retval = 0;
  68383. + uint8_t needs_scheduling = 0;
  68384. + dwc_otg_transaction_type_e tr_type;
  68385. + dwc_otg_qtd_t *qtd;
  68386. + gintmsk_data_t intr_mask = {.d32 = 0 };
  68387. +
  68388. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68389. + if (NULL == hcd->core_if) {
  68390. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  68391. + /* No longer connected. */
  68392. + return -DWC_E_INVALID;
  68393. + }
  68394. +#endif
  68395. + if (!hcd->flags.b.port_connect_status) {
  68396. + /* No longer connected. */
  68397. + DWC_ERROR("Not connected\n");
  68398. + return -DWC_E_NO_DEVICE;
  68399. + }
  68400. +
  68401. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  68402. + if (qtd == NULL) {
  68403. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  68404. + return -DWC_E_NO_MEMORY;
  68405. + }
  68406. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68407. + if (qtd->urb == NULL) {
  68408. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  68409. + return -DWC_E_NO_MEMORY;
  68410. + }
  68411. + if (qtd->urb->priv == NULL) {
  68412. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  68413. + return -DWC_E_NO_MEMORY;
  68414. + }
  68415. +#endif
  68416. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  68417. + if(!intr_mask.b.sofintr) needs_scheduling = 1;
  68418. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  68419. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  68420. + needs_scheduling = 0;
  68421. +
  68422. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  68423. + // creates a new queue in ep_handle if it doesn't exist already
  68424. + if (retval < 0) {
  68425. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  68426. + "Error status %d\n", retval);
  68427. + dwc_otg_hcd_qtd_free(qtd);
  68428. + return retval;
  68429. + }
  68430. +
  68431. + if(needs_scheduling) {
  68432. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  68433. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  68434. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  68435. + }
  68436. + }
  68437. + return retval;
  68438. +}
  68439. +
  68440. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  68441. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  68442. +{
  68443. + dwc_otg_qh_t *qh;
  68444. + dwc_otg_qtd_t *urb_qtd;
  68445. + BUG_ON(!hcd);
  68446. + BUG_ON(!dwc_otg_urb);
  68447. +
  68448. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68449. +
  68450. + if (hcd == NULL) {
  68451. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  68452. + return -DWC_E_INVALID;
  68453. + }
  68454. + if (dwc_otg_urb == NULL) {
  68455. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  68456. + return -DWC_E_INVALID;
  68457. + }
  68458. + if (dwc_otg_urb->qtd == NULL) {
  68459. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  68460. + return -DWC_E_INVALID;
  68461. + }
  68462. + urb_qtd = dwc_otg_urb->qtd;
  68463. + BUG_ON(!urb_qtd);
  68464. + if (urb_qtd->qh == NULL) {
  68465. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  68466. + return -DWC_E_INVALID;
  68467. + }
  68468. +#else
  68469. + urb_qtd = dwc_otg_urb->qtd;
  68470. + BUG_ON(!urb_qtd);
  68471. +#endif
  68472. + qh = urb_qtd->qh;
  68473. + BUG_ON(!qh);
  68474. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  68475. + if (urb_qtd->in_process) {
  68476. + dump_channel_info(hcd, qh);
  68477. + }
  68478. + }
  68479. +#ifdef DEBUG /* integrity checks (Broadcom) */
  68480. + if (hcd->core_if == NULL) {
  68481. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  68482. + return -DWC_E_INVALID;
  68483. + }
  68484. +#endif
  68485. + if (urb_qtd->in_process && qh->channel) {
  68486. + /* The QTD is in process (it has been assigned to a channel). */
  68487. + if (hcd->flags.b.port_connect_status) {
  68488. + /*
  68489. + * If still connected (i.e. in host mode), halt the
  68490. + * channel so it can be used for other transfers. If
  68491. + * no longer connected, the host registers can't be
  68492. + * written to halt the channel since the core is in
  68493. + * device mode.
  68494. + */
  68495. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  68496. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  68497. +
  68498. + dwc_otg_hcd_release_port(hcd, qh);
  68499. + }
  68500. + }
  68501. +
  68502. + /*
  68503. + * Free the QTD and clean up the associated QH. Leave the QH in the
  68504. + * schedule if it has any remaining QTDs.
  68505. + */
  68506. +
  68507. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  68508. + "delete %sQueue handler\n",
  68509. + hcd->core_if->dma_desc_enable?"DMA ":"");
  68510. + if (!hcd->core_if->dma_desc_enable) {
  68511. + uint8_t b = urb_qtd->in_process;
  68512. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  68513. + if (b) {
  68514. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  68515. + qh->channel = NULL;
  68516. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  68517. + dwc_otg_hcd_qh_remove(hcd, qh);
  68518. + }
  68519. + } else {
  68520. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  68521. + }
  68522. + return 0;
  68523. +}
  68524. +
  68525. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  68526. + int retry)
  68527. +{
  68528. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  68529. + int retval = 0;
  68530. + dwc_irqflags_t flags;
  68531. +
  68532. + if (retry < 0) {
  68533. + retval = -DWC_E_INVALID;
  68534. + goto done;
  68535. + }
  68536. +
  68537. + if (!qh) {
  68538. + retval = -DWC_E_INVALID;
  68539. + goto done;
  68540. + }
  68541. +
  68542. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68543. +
  68544. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  68545. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68546. + retry--;
  68547. + dwc_msleep(5);
  68548. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68549. + }
  68550. +
  68551. + dwc_otg_hcd_qh_remove(hcd, qh);
  68552. +
  68553. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68554. + /*
  68555. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  68556. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  68557. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  68558. + * and dwc_otg_hcd_frame_list_alloc().
  68559. + */
  68560. + dwc_otg_hcd_qh_free(hcd, qh);
  68561. +
  68562. +done:
  68563. + return retval;
  68564. +}
  68565. +
  68566. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  68567. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  68568. +{
  68569. + int retval = 0;
  68570. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  68571. + if (!qh)
  68572. + return -DWC_E_INVALID;
  68573. +
  68574. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  68575. + return retval;
  68576. +}
  68577. +#endif
  68578. +
  68579. +/**
  68580. + * HCD Callback structure for handling mode switching.
  68581. + */
  68582. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  68583. + .start = dwc_otg_hcd_start_cb,
  68584. + .stop = dwc_otg_hcd_stop_cb,
  68585. + .disconnect = dwc_otg_hcd_disconnect_cb,
  68586. + .session_start = dwc_otg_hcd_session_start_cb,
  68587. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  68588. +#ifdef CONFIG_USB_DWC_OTG_LPM
  68589. + .sleep = dwc_otg_hcd_sleep_cb,
  68590. +#endif
  68591. + .p = 0,
  68592. +};
  68593. +
  68594. +/**
  68595. + * Reset tasklet function
  68596. + */
  68597. +static void reset_tasklet_func(void *data)
  68598. +{
  68599. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  68600. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  68601. + hprt0_data_t hprt0;
  68602. +
  68603. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  68604. +
  68605. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  68606. + hprt0.b.prtrst = 1;
  68607. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  68608. + dwc_mdelay(60);
  68609. +
  68610. + hprt0.b.prtrst = 0;
  68611. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  68612. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  68613. +}
  68614. +
  68615. +static void completion_tasklet_func(void *ptr)
  68616. +{
  68617. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  68618. + struct urb *urb;
  68619. + urb_tq_entry_t *item;
  68620. + dwc_irqflags_t flags;
  68621. +
  68622. + /* This could just be spin_lock_irq */
  68623. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68624. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  68625. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  68626. + urb = item->urb;
  68627. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  68628. + urb_tq_entries);
  68629. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68630. + DWC_FREE(item);
  68631. +
  68632. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  68633. +
  68634. + fiq_print(FIQDBG_PORTHUB, "COMPLETE");
  68635. +
  68636. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68637. + }
  68638. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68639. + return;
  68640. +}
  68641. +
  68642. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  68643. +{
  68644. + dwc_list_link_t *item;
  68645. + dwc_otg_qh_t *qh;
  68646. + dwc_irqflags_t flags;
  68647. +
  68648. + if (!qh_list->next) {
  68649. + /* The list hasn't been initialized yet. */
  68650. + return;
  68651. + }
  68652. + /*
  68653. + * Hold spinlock here. Not needed in that case if bellow
  68654. + * function is being called from ISR
  68655. + */
  68656. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  68657. + /* Ensure there are no QTDs or URBs left. */
  68658. + kill_urbs_in_qh_list(hcd, qh_list);
  68659. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  68660. +
  68661. + DWC_LIST_FOREACH(item, qh_list) {
  68662. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  68663. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  68664. + }
  68665. +}
  68666. +
  68667. +/**
  68668. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  68669. + * Device during SRP time by host power up.
  68670. + */
  68671. +void dwc_otg_hcd_power_up(void *ptr)
  68672. +{
  68673. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  68674. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  68675. +
  68676. + DWC_PRINTF("%s called\n", __FUNCTION__);
  68677. +
  68678. + if (!core_if->hibernation_suspend) {
  68679. + DWC_PRINTF("Already exited from Hibernation\n");
  68680. + return;
  68681. + }
  68682. +
  68683. + /* Switch on the voltage to the core */
  68684. + gpwrdn.b.pwrdnswtch = 1;
  68685. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68686. + dwc_udelay(10);
  68687. +
  68688. + /* Reset the core */
  68689. + gpwrdn.d32 = 0;
  68690. + gpwrdn.b.pwrdnrstn = 1;
  68691. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68692. + dwc_udelay(10);
  68693. +
  68694. + /* Disable power clamps */
  68695. + gpwrdn.d32 = 0;
  68696. + gpwrdn.b.pwrdnclmp = 1;
  68697. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68698. +
  68699. + /* Remove reset the core signal */
  68700. + gpwrdn.d32 = 0;
  68701. + gpwrdn.b.pwrdnrstn = 1;
  68702. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  68703. + dwc_udelay(10);
  68704. +
  68705. + /* Disable PMU interrupt */
  68706. + gpwrdn.d32 = 0;
  68707. + gpwrdn.b.pmuintsel = 1;
  68708. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68709. +
  68710. + core_if->hibernation_suspend = 0;
  68711. +
  68712. + /* Disable PMU */
  68713. + gpwrdn.d32 = 0;
  68714. + gpwrdn.b.pmuactv = 1;
  68715. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68716. + dwc_udelay(10);
  68717. +
  68718. + /* Enable VBUS */
  68719. + gpwrdn.d32 = 0;
  68720. + gpwrdn.b.dis_vbus = 1;
  68721. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  68722. +
  68723. + core_if->op_state = A_HOST;
  68724. + dwc_otg_core_init(core_if);
  68725. + dwc_otg_enable_global_interrupts(core_if);
  68726. + cil_hcd_start(core_if);
  68727. +}
  68728. +
  68729. +/**
  68730. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  68731. + * in the struct usb_hcd field.
  68732. + */
  68733. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  68734. +{
  68735. + int i;
  68736. +
  68737. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  68738. +
  68739. + del_timers(dwc_otg_hcd);
  68740. +
  68741. + /* Free memory for QH/QTD lists */
  68742. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  68743. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  68744. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  68745. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  68746. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  68747. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  68748. +
  68749. + /* Free memory for the host channels. */
  68750. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  68751. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  68752. +
  68753. +#ifdef DEBUG
  68754. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  68755. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  68756. + }
  68757. +#endif
  68758. + if (hc != NULL) {
  68759. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  68760. + i, hc);
  68761. + DWC_FREE(hc);
  68762. + }
  68763. + }
  68764. +
  68765. + if (dwc_otg_hcd->core_if->dma_enable) {
  68766. + if (dwc_otg_hcd->status_buf_dma) {
  68767. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  68768. + dwc_otg_hcd->status_buf,
  68769. + dwc_otg_hcd->status_buf_dma);
  68770. + }
  68771. + } else if (dwc_otg_hcd->status_buf != NULL) {
  68772. + DWC_FREE(dwc_otg_hcd->status_buf);
  68773. + }
  68774. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  68775. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  68776. + /* Set core_if's lock pointer to NULL */
  68777. + dwc_otg_hcd->core_if->lock = NULL;
  68778. +
  68779. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  68780. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  68781. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  68782. +
  68783. +#ifdef DWC_DEV_SRPCAP
  68784. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  68785. + dwc_otg_hcd->core_if->pwron_timer) {
  68786. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  68787. + }
  68788. +#endif
  68789. + DWC_FREE(dwc_otg_hcd);
  68790. +}
  68791. +
  68792. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  68793. +
  68794. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  68795. +{
  68796. + int retval = 0;
  68797. + int num_channels;
  68798. + int i;
  68799. + dwc_hc_t *channel;
  68800. +
  68801. + hcd->lock = DWC_SPINLOCK_ALLOC();
  68802. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  68803. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  68804. + hcd, core_if);
  68805. + if (!hcd->lock) {
  68806. + DWC_ERROR("Could not allocate lock for pcd");
  68807. + DWC_FREE(hcd);
  68808. + retval = -DWC_E_NO_MEMORY;
  68809. + goto out;
  68810. + }
  68811. + hcd->core_if = core_if;
  68812. +
  68813. + /* Register the HCD CIL Callbacks */
  68814. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  68815. + &hcd_cil_callbacks, hcd);
  68816. +
  68817. + /* Initialize the non-periodic schedule. */
  68818. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  68819. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  68820. +
  68821. + /* Initialize the periodic schedule. */
  68822. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  68823. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  68824. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  68825. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  68826. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  68827. + /*
  68828. + * Create a host channel descriptor for each host channel implemented
  68829. + * in the controller. Initialize the channel descriptor array.
  68830. + */
  68831. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  68832. + num_channels = hcd->core_if->core_params->host_channels;
  68833. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  68834. + for (i = 0; i < num_channels; i++) {
  68835. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  68836. + if (channel == NULL) {
  68837. + retval = -DWC_E_NO_MEMORY;
  68838. + DWC_ERROR("%s: host channel allocation failed\n",
  68839. + __func__);
  68840. + dwc_otg_hcd_free(hcd);
  68841. + goto out;
  68842. + }
  68843. + channel->hc_num = i;
  68844. + hcd->hc_ptr_array[i] = channel;
  68845. +#ifdef DEBUG
  68846. + hcd->core_if->hc_xfer_timer[i] =
  68847. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  68848. + &hcd->core_if->hc_xfer_info[i]);
  68849. +#endif
  68850. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  68851. + channel);
  68852. + }
  68853. +
  68854. + /* Initialize the Connection timeout timer. */
  68855. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  68856. + dwc_otg_hcd_connect_timeout, 0);
  68857. +
  68858. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  68859. + if (microframe_schedule)
  68860. + init_hcd_usecs(hcd);
  68861. +
  68862. + /* Initialize reset tasklet. */
  68863. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  68864. +
  68865. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  68866. + completion_tasklet_func, hcd);
  68867. +#ifdef DWC_DEV_SRPCAP
  68868. + if (hcd->core_if->power_down == 2) {
  68869. + /* Initialize Power on timer for Host power up in case hibernation */
  68870. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  68871. + dwc_otg_hcd_power_up, core_if);
  68872. + }
  68873. +#endif
  68874. +
  68875. + /*
  68876. + * Allocate space for storing data on status transactions. Normally no
  68877. + * data is sent, but this space acts as a bit bucket. This must be
  68878. + * done after usb_add_hcd since that function allocates the DMA buffer
  68879. + * pool.
  68880. + */
  68881. + if (hcd->core_if->dma_enable) {
  68882. + hcd->status_buf =
  68883. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  68884. + &hcd->status_buf_dma);
  68885. + } else {
  68886. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  68887. + }
  68888. + if (!hcd->status_buf) {
  68889. + retval = -DWC_E_NO_MEMORY;
  68890. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  68891. + dwc_otg_hcd_free(hcd);
  68892. + goto out;
  68893. + }
  68894. +
  68895. + hcd->otg_port = 1;
  68896. + hcd->frame_list = NULL;
  68897. + hcd->frame_list_dma = 0;
  68898. + hcd->periodic_qh_count = 0;
  68899. +
  68900. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  68901. +#ifdef FIQ_DEBUG
  68902. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  68903. +#endif
  68904. +
  68905. +out:
  68906. + return retval;
  68907. +}
  68908. +
  68909. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  68910. +{
  68911. + /* Turn off all host-specific interrupts. */
  68912. + dwc_otg_disable_host_interrupts(hcd->core_if);
  68913. +
  68914. + dwc_otg_hcd_free(hcd);
  68915. +}
  68916. +
  68917. +/**
  68918. + * Initializes dynamic portions of the DWC_otg HCD state.
  68919. + */
  68920. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  68921. +{
  68922. + int num_channels;
  68923. + int i;
  68924. + dwc_hc_t *channel;
  68925. + dwc_hc_t *channel_tmp;
  68926. +
  68927. + hcd->flags.d32 = 0;
  68928. +
  68929. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  68930. + if (!microframe_schedule) {
  68931. + hcd->non_periodic_channels = 0;
  68932. + hcd->periodic_channels = 0;
  68933. + } else {
  68934. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  68935. + }
  68936. + /*
  68937. + * Put all channels in the free channel list and clean up channel
  68938. + * states.
  68939. + */
  68940. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  68941. + &hcd->free_hc_list, hc_list_entry) {
  68942. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  68943. + }
  68944. +
  68945. + num_channels = hcd->core_if->core_params->host_channels;
  68946. + for (i = 0; i < num_channels; i++) {
  68947. + channel = hcd->hc_ptr_array[i];
  68948. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  68949. + hc_list_entry);
  68950. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  68951. + }
  68952. +
  68953. + /* Initialize the DWC core for host mode operation. */
  68954. + dwc_otg_core_host_init(hcd->core_if);
  68955. +
  68956. + /* Set core_if's lock pointer to the hcd->lock */
  68957. + hcd->core_if->lock = hcd->lock;
  68958. +}
  68959. +
  68960. +/**
  68961. + * Assigns transactions from a QTD to a free host channel and initializes the
  68962. + * host channel to perform the transactions. The host channel is removed from
  68963. + * the free list.
  68964. + *
  68965. + * @param hcd The HCD state structure.
  68966. + * @param qh Transactions from the first QTD for this QH are selected and
  68967. + * assigned to a free host channel.
  68968. + */
  68969. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  68970. +{
  68971. + dwc_hc_t *hc;
  68972. + dwc_otg_qtd_t *qtd;
  68973. + dwc_otg_hcd_urb_t *urb;
  68974. + void* ptr = NULL;
  68975. +
  68976. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  68977. +
  68978. + urb = qtd->urb;
  68979. +
  68980. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  68981. +
  68982. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  68983. + urb->actual_length = urb->length;
  68984. +
  68985. +
  68986. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  68987. +
  68988. + /* Remove the host channel from the free list. */
  68989. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  68990. +
  68991. + qh->channel = hc;
  68992. +
  68993. + qtd->in_process = 1;
  68994. +
  68995. + /*
  68996. + * Use usb_pipedevice to determine device address. This address is
  68997. + * 0 before the SET_ADDRESS command and the correct address afterward.
  68998. + */
  68999. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  69000. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  69001. + hc->speed = qh->dev_speed;
  69002. + hc->max_packet = dwc_max_packet(qh->maxp);
  69003. +
  69004. + hc->xfer_started = 0;
  69005. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  69006. + hc->error_state = (qtd->error_count > 0);
  69007. + hc->halt_on_queue = 0;
  69008. + hc->halt_pending = 0;
  69009. + hc->requests = 0;
  69010. +
  69011. + /*
  69012. + * The following values may be modified in the transfer type section
  69013. + * below. The xfer_len value may be reduced when the transfer is
  69014. + * started to accommodate the max widths of the XferSize and PktCnt
  69015. + * fields in the HCTSIZn register.
  69016. + */
  69017. +
  69018. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  69019. + if (hc->ep_is_in) {
  69020. + hc->do_ping = 0;
  69021. + } else {
  69022. + hc->do_ping = qh->ping_state;
  69023. + }
  69024. +
  69025. + hc->data_pid_start = qh->data_toggle;
  69026. + hc->multi_count = 1;
  69027. +
  69028. + if (hcd->core_if->dma_enable) {
  69029. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  69030. +
  69031. + /* For non-dword aligned case */
  69032. + if (((unsigned long)hc->xfer_buff & 0x3)
  69033. + && !hcd->core_if->dma_desc_enable) {
  69034. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  69035. + }
  69036. + } else {
  69037. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  69038. + }
  69039. + hc->xfer_len = urb->length - urb->actual_length;
  69040. + hc->xfer_count = 0;
  69041. +
  69042. + /*
  69043. + * Set the split attributes
  69044. + */
  69045. + hc->do_split = 0;
  69046. + if (qh->do_split) {
  69047. + uint32_t hub_addr, port_addr;
  69048. + hc->do_split = 1;
  69049. + hc->xact_pos = qtd->isoc_split_pos;
  69050. + /* We don't need to do complete splits anymore */
  69051. + if(fiq_split_enable)
  69052. + hc->complete_split = qtd->complete_split = 0;
  69053. + else
  69054. + hc->complete_split = qtd->complete_split;
  69055. +
  69056. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  69057. + hc->hub_addr = (uint8_t) hub_addr;
  69058. + hc->port_addr = (uint8_t) port_addr;
  69059. + }
  69060. +
  69061. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  69062. + case UE_CONTROL:
  69063. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  69064. + switch (qtd->control_phase) {
  69065. + case DWC_OTG_CONTROL_SETUP:
  69066. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  69067. + hc->do_ping = 0;
  69068. + hc->ep_is_in = 0;
  69069. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  69070. + if (hcd->core_if->dma_enable) {
  69071. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  69072. + } else {
  69073. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  69074. + }
  69075. + hc->xfer_len = 8;
  69076. + ptr = NULL;
  69077. + break;
  69078. + case DWC_OTG_CONTROL_DATA:
  69079. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  69080. + hc->data_pid_start = qtd->data_toggle;
  69081. + break;
  69082. + case DWC_OTG_CONTROL_STATUS:
  69083. + /*
  69084. + * Direction is opposite of data direction or IN if no
  69085. + * data.
  69086. + */
  69087. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  69088. + if (urb->length == 0) {
  69089. + hc->ep_is_in = 1;
  69090. + } else {
  69091. + hc->ep_is_in =
  69092. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  69093. + }
  69094. + if (hc->ep_is_in) {
  69095. + hc->do_ping = 0;
  69096. + }
  69097. +
  69098. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  69099. +
  69100. + hc->xfer_len = 0;
  69101. + if (hcd->core_if->dma_enable) {
  69102. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  69103. + } else {
  69104. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  69105. + }
  69106. + ptr = NULL;
  69107. + break;
  69108. + }
  69109. + break;
  69110. + case UE_BULK:
  69111. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  69112. + break;
  69113. + case UE_INTERRUPT:
  69114. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  69115. + break;
  69116. + case UE_ISOCHRONOUS:
  69117. + {
  69118. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  69119. +
  69120. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  69121. +
  69122. + if (hcd->core_if->dma_desc_enable)
  69123. + break;
  69124. +
  69125. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  69126. +
  69127. + frame_desc->status = 0;
  69128. +
  69129. + if (hcd->core_if->dma_enable) {
  69130. + hc->xfer_buff = (uint8_t *) urb->dma;
  69131. + } else {
  69132. + hc->xfer_buff = (uint8_t *) urb->buf;
  69133. + }
  69134. + hc->xfer_buff +=
  69135. + frame_desc->offset + qtd->isoc_split_offset;
  69136. + hc->xfer_len =
  69137. + frame_desc->length - qtd->isoc_split_offset;
  69138. +
  69139. + /* For non-dword aligned buffers */
  69140. + if (((unsigned long)hc->xfer_buff & 0x3)
  69141. + && hcd->core_if->dma_enable) {
  69142. + ptr =
  69143. + (uint8_t *) urb->buf + frame_desc->offset +
  69144. + qtd->isoc_split_offset;
  69145. + } else
  69146. + ptr = NULL;
  69147. +
  69148. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  69149. + if (hc->xfer_len <= 188) {
  69150. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  69151. + } else {
  69152. + hc->xact_pos =
  69153. + DWC_HCSPLIT_XACTPOS_BEGIN;
  69154. + }
  69155. + }
  69156. + }
  69157. + break;
  69158. + }
  69159. + /* non DWORD-aligned buffer case */
  69160. + if (ptr) {
  69161. + uint32_t buf_size;
  69162. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  69163. + buf_size = hcd->core_if->core_params->max_transfer_size;
  69164. + } else {
  69165. + buf_size = 4096;
  69166. + }
  69167. + if (!qh->dw_align_buf) {
  69168. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  69169. + &qh->dw_align_buf_dma);
  69170. + if (!qh->dw_align_buf) {
  69171. + DWC_ERROR
  69172. + ("%s: Failed to allocate memory to handle "
  69173. + "non-dword aligned buffer case\n",
  69174. + __func__);
  69175. + return;
  69176. + }
  69177. + }
  69178. + if (!hc->ep_is_in) {
  69179. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  69180. + }
  69181. + hc->align_buff = qh->dw_align_buf_dma;
  69182. + } else {
  69183. + hc->align_buff = 0;
  69184. + }
  69185. +
  69186. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  69187. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  69188. + /*
  69189. + * This value may be modified when the transfer is started to
  69190. + * reflect the actual transfer length.
  69191. + */
  69192. + hc->multi_count = dwc_hb_mult(qh->maxp);
  69193. + }
  69194. +
  69195. + if (hcd->core_if->dma_desc_enable)
  69196. + hc->desc_list_addr = qh->desc_list_dma;
  69197. +
  69198. + dwc_otg_hc_init(hcd->core_if, hc);
  69199. + hc->qh = qh;
  69200. +}
  69201. +
  69202. +/*
  69203. +** Check the transaction to see if the port / hub has already been assigned for
  69204. +** a split transaction
  69205. +**
  69206. +** Return 0 - Port is already in use
  69207. +*/
  69208. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  69209. +{
  69210. + uint32_t hub_addr, port_addr;
  69211. +
  69212. + if(!fiq_split_enable)
  69213. + return 0;
  69214. +
  69215. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  69216. +
  69217. + if(hcd->hub_port[hub_addr] & (1 << port_addr))
  69218. + {
  69219. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
  69220. +
  69221. + qh->skip_count++;
  69222. +
  69223. + if(qh->skip_count > 40000)
  69224. + {
  69225. + printk_once(KERN_ERR "Error: Having to skip port allocation");
  69226. + local_fiq_disable();
  69227. + BUG();
  69228. + return 0;
  69229. + }
  69230. + return 1;
  69231. + }
  69232. + else
  69233. + {
  69234. + qh->skip_count = 0;
  69235. + hcd->hub_port[hub_addr] |= 1 << port_addr;
  69236. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  69237. +#ifdef FIQ_DEBUG
  69238. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
  69239. +#endif
  69240. + return 0;
  69241. + }
  69242. +}
  69243. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  69244. +{
  69245. + uint32_t hub_addr, port_addr;
  69246. +
  69247. + if(!fiq_split_enable)
  69248. + return;
  69249. +
  69250. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  69251. +
  69252. + hcd->hub_port[hub_addr] &= ~(1 << port_addr);
  69253. +#ifdef FIQ_DEBUG
  69254. + hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
  69255. +#endif
  69256. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  69257. +
  69258. +}
  69259. +
  69260. +
  69261. +/**
  69262. + * This function selects transactions from the HCD transfer schedule and
  69263. + * assigns them to available host channels. It is called from HCD interrupt
  69264. + * handler functions.
  69265. + *
  69266. + * @param hcd The HCD state structure.
  69267. + *
  69268. + * @return The types of new transactions that were assigned to host channels.
  69269. + */
  69270. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  69271. +{
  69272. + dwc_list_link_t *qh_ptr;
  69273. + dwc_otg_qh_t *qh;
  69274. + dwc_otg_qtd_t *qtd;
  69275. + int num_channels;
  69276. + dwc_irqflags_t flags;
  69277. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  69278. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  69279. +
  69280. +#ifdef DEBUG_SOF
  69281. + DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
  69282. +#endif
  69283. +
  69284. +#ifdef DEBUG_HOST_CHANNELS
  69285. + last_sel_trans_num_per_scheduled = 0;
  69286. + last_sel_trans_num_nonper_scheduled = 0;
  69287. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  69288. +#endif /* DEBUG_HOST_CHANNELS */
  69289. +
  69290. + /* Process entries in the periodic ready list. */
  69291. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  69292. +
  69293. + while (qh_ptr != &hcd->periodic_sched_ready &&
  69294. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  69295. +
  69296. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69297. +
  69298. + if(qh->do_split) {
  69299. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69300. + if(!(qh->ep_type == UE_ISOCHRONOUS &&
  69301. + (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  69302. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
  69303. + if(dwc_otg_hcd_allocate_port(hcd, qh))
  69304. + {
  69305. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69306. + g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
  69307. + continue;
  69308. + }
  69309. + }
  69310. + }
  69311. +
  69312. + if (microframe_schedule) {
  69313. + // Make sure we leave one channel for non periodic transactions.
  69314. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69315. + if (hcd->available_host_channels <= 1) {
  69316. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69317. + if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
  69318. + break;
  69319. + }
  69320. + hcd->available_host_channels--;
  69321. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69322. +#ifdef DEBUG_HOST_CHANNELS
  69323. + last_sel_trans_num_per_scheduled++;
  69324. +#endif /* DEBUG_HOST_CHANNELS */
  69325. + }
  69326. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69327. + assign_and_init_hc(hcd, qh);
  69328. +
  69329. + /*
  69330. + * Move the QH from the periodic ready schedule to the
  69331. + * periodic assigned schedule.
  69332. + */
  69333. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69334. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69335. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  69336. + &qh->qh_list_entry);
  69337. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69338. + }
  69339. +
  69340. + /*
  69341. + * Process entries in the inactive portion of the non-periodic
  69342. + * schedule. Some free host channels may not be used if they are
  69343. + * reserved for periodic transfers.
  69344. + */
  69345. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  69346. + num_channels = hcd->core_if->core_params->host_channels;
  69347. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  69348. + (microframe_schedule || hcd->non_periodic_channels <
  69349. + num_channels - hcd->periodic_channels) &&
  69350. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  69351. +
  69352. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69353. +
  69354. + /*
  69355. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  69356. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  69357. + * cheeky devices that just hold off using NAKs
  69358. + */
  69359. + if (nak_holdoff_enable && qh->do_split) {
  69360. + if (qh->nak_frame != 0xffff &&
  69361. + dwc_full_frame_num(qh->nak_frame) ==
  69362. + dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
  69363. + /*
  69364. + * Revisit: Need to avoid trampling on periodic scheduling.
  69365. + * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
  69366. + * but if this behaviour is changed then periodic endpoints will get a slower
  69367. + * polling rate.
  69368. + */
  69369. + g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
  69370. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69371. + continue;
  69372. + } else {
  69373. + qh->nak_frame = 0xffff;
  69374. + }
  69375. + }
  69376. +
  69377. + if (microframe_schedule) {
  69378. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69379. + if (hcd->available_host_channels < 1) {
  69380. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69381. + break;
  69382. + }
  69383. + hcd->available_host_channels--;
  69384. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69385. +#ifdef DEBUG_HOST_CHANNELS
  69386. + last_sel_trans_num_nonper_scheduled++;
  69387. +#endif /* DEBUG_HOST_CHANNELS */
  69388. + }
  69389. +
  69390. + assign_and_init_hc(hcd, qh);
  69391. +
  69392. + /*
  69393. + * Move the QH from the non-periodic inactive schedule to the
  69394. + * non-periodic active schedule.
  69395. + */
  69396. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  69397. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  69398. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  69399. + &qh->qh_list_entry);
  69400. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  69401. +
  69402. + g_np_sent++;
  69403. +
  69404. + if (!microframe_schedule)
  69405. + hcd->non_periodic_channels++;
  69406. + }
  69407. +
  69408. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  69409. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  69410. +
  69411. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  69412. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  69413. +
  69414. +
  69415. +#ifdef DEBUG_HOST_CHANNELS
  69416. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  69417. +#endif /* DEBUG_HOST_CHANNELS */
  69418. + return ret_val;
  69419. +}
  69420. +
  69421. +/**
  69422. + * Attempts to queue a single transaction request for a host channel
  69423. + * associated with either a periodic or non-periodic transfer. This function
  69424. + * assumes that there is space available in the appropriate request queue. For
  69425. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  69426. + * is available in the appropriate Tx FIFO.
  69427. + *
  69428. + * @param hcd The HCD state structure.
  69429. + * @param hc Host channel descriptor associated with either a periodic or
  69430. + * non-periodic transfer.
  69431. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  69432. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  69433. + * transfers.
  69434. + *
  69435. + * @return 1 if a request is queued and more requests may be needed to
  69436. + * complete the transfer, 0 if no more requests are required for this
  69437. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  69438. + */
  69439. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  69440. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  69441. +{
  69442. + int retval;
  69443. +
  69444. + if (hcd->core_if->dma_enable) {
  69445. + if (hcd->core_if->dma_desc_enable) {
  69446. + if (!hc->xfer_started
  69447. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  69448. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  69449. + hc->qh->ping_state = 0;
  69450. + }
  69451. + } else if (!hc->xfer_started) {
  69452. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69453. + hc->qh->ping_state = 0;
  69454. + }
  69455. + retval = 0;
  69456. + } else if (hc->halt_pending) {
  69457. + /* Don't queue a request if the channel has been halted. */
  69458. + retval = 0;
  69459. + } else if (hc->halt_on_queue) {
  69460. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  69461. + retval = 0;
  69462. + } else if (hc->do_ping) {
  69463. + if (!hc->xfer_started) {
  69464. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69465. + }
  69466. + retval = 0;
  69467. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  69468. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  69469. + if (!hc->xfer_started) {
  69470. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69471. + retval = 1;
  69472. + } else {
  69473. + retval =
  69474. + dwc_otg_hc_continue_transfer(hcd->core_if,
  69475. + hc);
  69476. + }
  69477. + } else {
  69478. + retval = -1;
  69479. + }
  69480. + } else {
  69481. + if (!hc->xfer_started) {
  69482. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  69483. + retval = 1;
  69484. + } else {
  69485. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  69486. + }
  69487. + }
  69488. +
  69489. + return retval;
  69490. +}
  69491. +
  69492. +/**
  69493. + * Processes periodic channels for the next frame and queues transactions for
  69494. + * these channels to the DWC_otg controller. After queueing transactions, the
  69495. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  69496. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  69497. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  69498. + */
  69499. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  69500. +{
  69501. + hptxsts_data_t tx_status;
  69502. + dwc_list_link_t *qh_ptr;
  69503. + dwc_otg_qh_t *qh;
  69504. + int status;
  69505. + int no_queue_space = 0;
  69506. + int no_fifo_space = 0;
  69507. +
  69508. + dwc_otg_host_global_regs_t *host_regs;
  69509. + host_regs = hcd->core_if->host_if->host_global_regs;
  69510. +
  69511. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  69512. +#ifdef DEBUG
  69513. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  69514. + DWC_DEBUGPL(DBG_HCDV,
  69515. + " P Tx Req Queue Space Avail (before queue): %d\n",
  69516. + tx_status.b.ptxqspcavail);
  69517. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  69518. + tx_status.b.ptxfspcavail);
  69519. +#endif
  69520. +
  69521. + qh_ptr = hcd->periodic_sched_assigned.next;
  69522. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  69523. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  69524. + if (tx_status.b.ptxqspcavail == 0) {
  69525. + no_queue_space = 1;
  69526. + break;
  69527. + }
  69528. +
  69529. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  69530. +
  69531. + // Do not send a split start transaction any later than frame .6
  69532. + // Note, we have to schedule a periodic in .5 to make it go in .6
  69533. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  69534. + {
  69535. + qh_ptr = qh_ptr->next;
  69536. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  69537. + continue;
  69538. + }
  69539. +
  69540. + /*
  69541. + * Set a flag if we're queuing high-bandwidth in slave mode.
  69542. + * The flag prevents any halts to get into the request queue in
  69543. + * the middle of multiple high-bandwidth packets getting queued.
  69544. + */
  69545. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  69546. + hcd->core_if->queuing_high_bandwidth = 1;
  69547. + }
  69548. + status =
  69549. + queue_transaction(hcd, qh->channel,
  69550. + tx_status.b.ptxfspcavail);
  69551. + if (status < 0) {
  69552. + no_fifo_space = 1;
  69553. + break;
  69554. + }
  69555. +
  69556. + /*
  69557. + * In Slave mode, stay on the current transfer until there is
  69558. + * nothing more to do or the high-bandwidth request count is
  69559. + * reached. In DMA mode, only need to queue one request. The
  69560. + * controller automatically handles multiple packets for
  69561. + * high-bandwidth transfers.
  69562. + */
  69563. + if (hcd->core_if->dma_enable || status == 0 ||
  69564. + qh->channel->requests == qh->channel->multi_count) {
  69565. + qh_ptr = qh_ptr->next;
  69566. + /*
  69567. + * Move the QH from the periodic assigned schedule to
  69568. + * the periodic queued schedule.
  69569. + */
  69570. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  69571. + &qh->qh_list_entry);
  69572. +
  69573. + /* done queuing high bandwidth */
  69574. + hcd->core_if->queuing_high_bandwidth = 0;
  69575. + }
  69576. + }
  69577. +
  69578. + if (!hcd->core_if->dma_enable) {
  69579. + dwc_otg_core_global_regs_t *global_regs;
  69580. + gintmsk_data_t intr_mask = {.d32 = 0 };
  69581. +
  69582. + global_regs = hcd->core_if->core_global_regs;
  69583. + intr_mask.b.ptxfempty = 1;
  69584. +#ifdef DEBUG
  69585. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  69586. + DWC_DEBUGPL(DBG_HCDV,
  69587. + " P Tx Req Queue Space Avail (after queue): %d\n",
  69588. + tx_status.b.ptxqspcavail);
  69589. + DWC_DEBUGPL(DBG_HCDV,
  69590. + " P Tx FIFO Space Avail (after queue): %d\n",
  69591. + tx_status.b.ptxfspcavail);
  69592. +#endif
  69593. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  69594. + no_queue_space || no_fifo_space) {
  69595. + /*
  69596. + * May need to queue more transactions as the request
  69597. + * queue or Tx FIFO empties. Enable the periodic Tx
  69598. + * FIFO empty interrupt. (Always use the half-empty
  69599. + * level to ensure that new requests are loaded as
  69600. + * soon as possible.)
  69601. + */
  69602. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  69603. + intr_mask.d32);
  69604. + } else {
  69605. + /*
  69606. + * Disable the Tx FIFO empty interrupt since there are
  69607. + * no more transactions that need to be queued right
  69608. + * now. This function is called from interrupt
  69609. + * handlers to queue more transactions as transfer
  69610. + * states change.
  69611. + */
  69612. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  69613. + 0);
  69614. + }
  69615. + }
  69616. +}
  69617. +
  69618. +/**
  69619. + * Processes active non-periodic channels and queues transactions for these
  69620. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  69621. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  69622. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  69623. + * FIFO Empty interrupt is disabled.
  69624. + */
  69625. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  69626. +{
  69627. + gnptxsts_data_t tx_status;
  69628. + dwc_list_link_t *orig_qh_ptr;
  69629. + dwc_otg_qh_t *qh;
  69630. + int status;
  69631. + int no_queue_space = 0;
  69632. + int no_fifo_space = 0;
  69633. + int more_to_do = 0;
  69634. +
  69635. + dwc_otg_core_global_regs_t *global_regs =
  69636. + hcd->core_if->core_global_regs;
  69637. +
  69638. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  69639. +#ifdef DEBUG
  69640. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  69641. + DWC_DEBUGPL(DBG_HCDV,
  69642. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  69643. + tx_status.b.nptxqspcavail);
  69644. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  69645. + tx_status.b.nptxfspcavail);
  69646. +#endif
  69647. + /*
  69648. + * Keep track of the starting point. Skip over the start-of-list
  69649. + * entry.
  69650. + */
  69651. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  69652. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  69653. + }
  69654. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  69655. +
  69656. + /*
  69657. + * Process once through the active list or until no more space is
  69658. + * available in the request queue or the Tx FIFO.
  69659. + */
  69660. + do {
  69661. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  69662. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  69663. + no_queue_space = 1;
  69664. + break;
  69665. + }
  69666. +
  69667. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  69668. + qh_list_entry);
  69669. +
  69670. + // Do not send a split start transaction any later than frame .5
  69671. + // non periodic transactions will start immediately in this uframe
  69672. + if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  69673. + {
  69674. + g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  69675. + break;
  69676. + }
  69677. +
  69678. + status =
  69679. + queue_transaction(hcd, qh->channel,
  69680. + tx_status.b.nptxfspcavail);
  69681. +
  69682. + if (status > 0) {
  69683. + more_to_do = 1;
  69684. + } else if (status < 0) {
  69685. + no_fifo_space = 1;
  69686. + break;
  69687. + }
  69688. +
  69689. + /* Advance to next QH, skipping start-of-list entry. */
  69690. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  69691. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  69692. + hcd->non_periodic_qh_ptr =
  69693. + hcd->non_periodic_qh_ptr->next;
  69694. + }
  69695. +
  69696. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  69697. +
  69698. + if (!hcd->core_if->dma_enable) {
  69699. + gintmsk_data_t intr_mask = {.d32 = 0 };
  69700. + intr_mask.b.nptxfempty = 1;
  69701. +
  69702. +#ifdef DEBUG
  69703. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  69704. + DWC_DEBUGPL(DBG_HCDV,
  69705. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  69706. + tx_status.b.nptxqspcavail);
  69707. + DWC_DEBUGPL(DBG_HCDV,
  69708. + " NP Tx FIFO Space Avail (after queue): %d\n",
  69709. + tx_status.b.nptxfspcavail);
  69710. +#endif
  69711. + if (more_to_do || no_queue_space || no_fifo_space) {
  69712. + /*
  69713. + * May need to queue more transactions as the request
  69714. + * queue or Tx FIFO empties. Enable the non-periodic
  69715. + * Tx FIFO empty interrupt. (Always use the half-empty
  69716. + * level to ensure that new requests are loaded as
  69717. + * soon as possible.)
  69718. + */
  69719. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  69720. + intr_mask.d32);
  69721. + } else {
  69722. + /*
  69723. + * Disable the Tx FIFO empty interrupt since there are
  69724. + * no more transactions that need to be queued right
  69725. + * now. This function is called from interrupt
  69726. + * handlers to queue more transactions as transfer
  69727. + * states change.
  69728. + */
  69729. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  69730. + 0);
  69731. + }
  69732. + }
  69733. +}
  69734. +
  69735. +/**
  69736. + * This function processes the currently active host channels and queues
  69737. + * transactions for these channels to the DWC_otg controller. It is called
  69738. + * from HCD interrupt handler functions.
  69739. + *
  69740. + * @param hcd The HCD state structure.
  69741. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  69742. + * periodic, or both).
  69743. + */
  69744. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  69745. + dwc_otg_transaction_type_e tr_type)
  69746. +{
  69747. +#ifdef DEBUG_SOF
  69748. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  69749. +#endif
  69750. + /* Process host channels associated with periodic transfers. */
  69751. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  69752. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  69753. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  69754. +
  69755. + process_periodic_channels(hcd);
  69756. + }
  69757. +
  69758. + /* Process host channels associated with non-periodic transfers. */
  69759. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  69760. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  69761. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  69762. + process_non_periodic_channels(hcd);
  69763. + } else {
  69764. + /*
  69765. + * Ensure NP Tx FIFO empty interrupt is disabled when
  69766. + * there are no non-periodic transfers to process.
  69767. + */
  69768. + gintmsk_data_t gintmsk = {.d32 = 0 };
  69769. + gintmsk.b.nptxfempty = 1;
  69770. + DWC_MODIFY_REG32(&hcd->core_if->
  69771. + core_global_regs->gintmsk, gintmsk.d32,
  69772. + 0);
  69773. + }
  69774. + }
  69775. +}
  69776. +
  69777. +#ifdef DWC_HS_ELECT_TST
  69778. +/*
  69779. + * Quick and dirty hack to implement the HS Electrical Test
  69780. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  69781. + *
  69782. + * This code was copied from our userspace app "hset". It sends a
  69783. + * Get Device Descriptor control sequence in two parts, first the
  69784. + * Setup packet by itself, followed some time later by the In and
  69785. + * Ack packets. Rather than trying to figure out how to add this
  69786. + * functionality to the normal driver code, we just hijack the
  69787. + * hardware, using these two function to drive the hardware
  69788. + * directly.
  69789. + */
  69790. +
  69791. +static dwc_otg_core_global_regs_t *global_regs;
  69792. +static dwc_otg_host_global_regs_t *hc_global_regs;
  69793. +static dwc_otg_hc_regs_t *hc_regs;
  69794. +static uint32_t *data_fifo;
  69795. +
  69796. +static void do_setup(void)
  69797. +{
  69798. + gintsts_data_t gintsts;
  69799. + hctsiz_data_t hctsiz;
  69800. + hcchar_data_t hcchar;
  69801. + haint_data_t haint;
  69802. + hcint_data_t hcint;
  69803. +
  69804. + /* Enable HAINTs */
  69805. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  69806. +
  69807. + /* Enable HCINTs */
  69808. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  69809. +
  69810. + /* Read GINTSTS */
  69811. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69812. +
  69813. + /* Read HAINT */
  69814. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69815. +
  69816. + /* Read HCINT */
  69817. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69818. +
  69819. + /* Read HCCHAR */
  69820. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69821. +
  69822. + /* Clear HCINT */
  69823. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69824. +
  69825. + /* Clear HAINT */
  69826. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69827. +
  69828. + /* Clear GINTSTS */
  69829. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69830. +
  69831. + /* Read GINTSTS */
  69832. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69833. +
  69834. + /*
  69835. + * Send Setup packet (Get Device Descriptor)
  69836. + */
  69837. +
  69838. + /* Make sure channel is disabled */
  69839. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69840. + if (hcchar.b.chen) {
  69841. + hcchar.b.chdis = 1;
  69842. +// hcchar.b.chen = 1;
  69843. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69844. + //sleep(1);
  69845. + dwc_mdelay(1000);
  69846. +
  69847. + /* Read GINTSTS */
  69848. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69849. +
  69850. + /* Read HAINT */
  69851. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69852. +
  69853. + /* Read HCINT */
  69854. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69855. +
  69856. + /* Read HCCHAR */
  69857. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69858. +
  69859. + /* Clear HCINT */
  69860. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69861. +
  69862. + /* Clear HAINT */
  69863. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69864. +
  69865. + /* Clear GINTSTS */
  69866. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69867. +
  69868. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69869. + }
  69870. +
  69871. + /* Set HCTSIZ */
  69872. + hctsiz.d32 = 0;
  69873. + hctsiz.b.xfersize = 8;
  69874. + hctsiz.b.pktcnt = 1;
  69875. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  69876. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  69877. +
  69878. + /* Set HCCHAR */
  69879. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69880. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  69881. + hcchar.b.epdir = 0;
  69882. + hcchar.b.epnum = 0;
  69883. + hcchar.b.mps = 8;
  69884. + hcchar.b.chen = 1;
  69885. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69886. +
  69887. + /* Fill FIFO with Setup data for Get Device Descriptor */
  69888. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  69889. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  69890. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  69891. +
  69892. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69893. +
  69894. + /* Wait for host channel interrupt */
  69895. + do {
  69896. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69897. + } while (gintsts.b.hcintr == 0);
  69898. +
  69899. + /* Disable HCINTs */
  69900. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  69901. +
  69902. + /* Disable HAINTs */
  69903. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  69904. +
  69905. + /* Read HAINT */
  69906. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69907. +
  69908. + /* Read HCINT */
  69909. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69910. +
  69911. + /* Read HCCHAR */
  69912. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69913. +
  69914. + /* Clear HCINT */
  69915. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69916. +
  69917. + /* Clear HAINT */
  69918. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69919. +
  69920. + /* Clear GINTSTS */
  69921. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69922. +
  69923. + /* Read GINTSTS */
  69924. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69925. +}
  69926. +
  69927. +static void do_in_ack(void)
  69928. +{
  69929. + gintsts_data_t gintsts;
  69930. + hctsiz_data_t hctsiz;
  69931. + hcchar_data_t hcchar;
  69932. + haint_data_t haint;
  69933. + hcint_data_t hcint;
  69934. + host_grxsts_data_t grxsts;
  69935. +
  69936. + /* Enable HAINTs */
  69937. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  69938. +
  69939. + /* Enable HCINTs */
  69940. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  69941. +
  69942. + /* Read GINTSTS */
  69943. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69944. +
  69945. + /* Read HAINT */
  69946. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69947. +
  69948. + /* Read HCINT */
  69949. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69950. +
  69951. + /* Read HCCHAR */
  69952. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69953. +
  69954. + /* Clear HCINT */
  69955. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69956. +
  69957. + /* Clear HAINT */
  69958. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69959. +
  69960. + /* Clear GINTSTS */
  69961. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69962. +
  69963. + /* Read GINTSTS */
  69964. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69965. +
  69966. + /*
  69967. + * Receive Control In packet
  69968. + */
  69969. +
  69970. + /* Make sure channel is disabled */
  69971. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69972. + if (hcchar.b.chen) {
  69973. + hcchar.b.chdis = 1;
  69974. + hcchar.b.chen = 1;
  69975. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  69976. + //sleep(1);
  69977. + dwc_mdelay(1000);
  69978. +
  69979. + /* Read GINTSTS */
  69980. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  69981. +
  69982. + /* Read HAINT */
  69983. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  69984. +
  69985. + /* Read HCINT */
  69986. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  69987. +
  69988. + /* Read HCCHAR */
  69989. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69990. +
  69991. + /* Clear HCINT */
  69992. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  69993. +
  69994. + /* Clear HAINT */
  69995. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  69996. +
  69997. + /* Clear GINTSTS */
  69998. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  69999. +
  70000. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70001. + }
  70002. +
  70003. + /* Set HCTSIZ */
  70004. + hctsiz.d32 = 0;
  70005. + hctsiz.b.xfersize = 8;
  70006. + hctsiz.b.pktcnt = 1;
  70007. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  70008. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70009. +
  70010. + /* Set HCCHAR */
  70011. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70012. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70013. + hcchar.b.epdir = 1;
  70014. + hcchar.b.epnum = 0;
  70015. + hcchar.b.mps = 8;
  70016. + hcchar.b.chen = 1;
  70017. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70018. +
  70019. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70020. +
  70021. + /* Wait for receive status queue interrupt */
  70022. + do {
  70023. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70024. + } while (gintsts.b.rxstsqlvl == 0);
  70025. +
  70026. + /* Read RXSTS */
  70027. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70028. +
  70029. + /* Clear RXSTSQLVL in GINTSTS */
  70030. + gintsts.d32 = 0;
  70031. + gintsts.b.rxstsqlvl = 1;
  70032. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70033. +
  70034. + switch (grxsts.b.pktsts) {
  70035. + case DWC_GRXSTS_PKTSTS_IN:
  70036. + /* Read the data into the host buffer */
  70037. + if (grxsts.b.bcnt > 0) {
  70038. + int i;
  70039. + int word_count = (grxsts.b.bcnt + 3) / 4;
  70040. +
  70041. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  70042. +
  70043. + for (i = 0; i < word_count; i++) {
  70044. + (void)DWC_READ_REG32(data_fifo++);
  70045. + }
  70046. + }
  70047. + break;
  70048. +
  70049. + default:
  70050. + break;
  70051. + }
  70052. +
  70053. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70054. +
  70055. + /* Wait for receive status queue interrupt */
  70056. + do {
  70057. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70058. + } while (gintsts.b.rxstsqlvl == 0);
  70059. +
  70060. + /* Read RXSTS */
  70061. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  70062. +
  70063. + /* Clear RXSTSQLVL in GINTSTS */
  70064. + gintsts.d32 = 0;
  70065. + gintsts.b.rxstsqlvl = 1;
  70066. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70067. +
  70068. + switch (grxsts.b.pktsts) {
  70069. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  70070. + break;
  70071. +
  70072. + default:
  70073. + break;
  70074. + }
  70075. +
  70076. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70077. +
  70078. + /* Wait for host channel interrupt */
  70079. + do {
  70080. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70081. + } while (gintsts.b.hcintr == 0);
  70082. +
  70083. + /* Read HAINT */
  70084. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70085. +
  70086. + /* Read HCINT */
  70087. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70088. +
  70089. + /* Read HCCHAR */
  70090. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70091. +
  70092. + /* Clear HCINT */
  70093. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70094. +
  70095. + /* Clear HAINT */
  70096. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70097. +
  70098. + /* Clear GINTSTS */
  70099. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70100. +
  70101. + /* Read GINTSTS */
  70102. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70103. +
  70104. +// usleep(100000);
  70105. +// mdelay(100);
  70106. + dwc_mdelay(1);
  70107. +
  70108. + /*
  70109. + * Send handshake packet
  70110. + */
  70111. +
  70112. + /* Read HAINT */
  70113. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70114. +
  70115. + /* Read HCINT */
  70116. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70117. +
  70118. + /* Read HCCHAR */
  70119. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70120. +
  70121. + /* Clear HCINT */
  70122. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70123. +
  70124. + /* Clear HAINT */
  70125. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70126. +
  70127. + /* Clear GINTSTS */
  70128. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70129. +
  70130. + /* Read GINTSTS */
  70131. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70132. +
  70133. + /* Make sure channel is disabled */
  70134. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70135. + if (hcchar.b.chen) {
  70136. + hcchar.b.chdis = 1;
  70137. + hcchar.b.chen = 1;
  70138. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70139. + //sleep(1);
  70140. + dwc_mdelay(1000);
  70141. +
  70142. + /* Read GINTSTS */
  70143. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70144. +
  70145. + /* Read HAINT */
  70146. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70147. +
  70148. + /* Read HCINT */
  70149. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70150. +
  70151. + /* Read HCCHAR */
  70152. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70153. +
  70154. + /* Clear HCINT */
  70155. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70156. +
  70157. + /* Clear HAINT */
  70158. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70159. +
  70160. + /* Clear GINTSTS */
  70161. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70162. +
  70163. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70164. + }
  70165. +
  70166. + /* Set HCTSIZ */
  70167. + hctsiz.d32 = 0;
  70168. + hctsiz.b.xfersize = 0;
  70169. + hctsiz.b.pktcnt = 1;
  70170. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  70171. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  70172. +
  70173. + /* Set HCCHAR */
  70174. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70175. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  70176. + hcchar.b.epdir = 0;
  70177. + hcchar.b.epnum = 0;
  70178. + hcchar.b.mps = 8;
  70179. + hcchar.b.chen = 1;
  70180. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  70181. +
  70182. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70183. +
  70184. + /* Wait for host channel interrupt */
  70185. + do {
  70186. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70187. + } while (gintsts.b.hcintr == 0);
  70188. +
  70189. + /* Disable HCINTs */
  70190. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  70191. +
  70192. + /* Disable HAINTs */
  70193. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  70194. +
  70195. + /* Read HAINT */
  70196. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  70197. +
  70198. + /* Read HCINT */
  70199. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  70200. +
  70201. + /* Read HCCHAR */
  70202. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70203. +
  70204. + /* Clear HCINT */
  70205. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  70206. +
  70207. + /* Clear HAINT */
  70208. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  70209. +
  70210. + /* Clear GINTSTS */
  70211. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  70212. +
  70213. + /* Read GINTSTS */
  70214. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  70215. +}
  70216. +#endif
  70217. +
  70218. +/** Handles hub class-specific requests. */
  70219. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  70220. + uint16_t typeReq,
  70221. + uint16_t wValue,
  70222. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  70223. +{
  70224. + int retval = 0;
  70225. +
  70226. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  70227. + usb_hub_descriptor_t *hub_desc;
  70228. + hprt0_data_t hprt0 = {.d32 = 0 };
  70229. +
  70230. + uint32_t port_status;
  70231. +
  70232. + switch (typeReq) {
  70233. + case UCR_CLEAR_HUB_FEATURE:
  70234. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70235. + "ClearHubFeature 0x%x\n", wValue);
  70236. + switch (wValue) {
  70237. + case UHF_C_HUB_LOCAL_POWER:
  70238. + case UHF_C_HUB_OVER_CURRENT:
  70239. + /* Nothing required here */
  70240. + break;
  70241. + default:
  70242. + retval = -DWC_E_INVALID;
  70243. + DWC_ERROR("DWC OTG HCD - "
  70244. + "ClearHubFeature request %xh unknown\n",
  70245. + wValue);
  70246. + }
  70247. + break;
  70248. + case UCR_CLEAR_PORT_FEATURE:
  70249. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70250. + if (wValue != UHF_PORT_L1)
  70251. +#endif
  70252. + if (!wIndex || wIndex > 1)
  70253. + goto error;
  70254. +
  70255. + switch (wValue) {
  70256. + case UHF_PORT_ENABLE:
  70257. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  70258. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  70259. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70260. + hprt0.b.prtena = 1;
  70261. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70262. + break;
  70263. + case UHF_PORT_SUSPEND:
  70264. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70265. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  70266. +
  70267. + if (core_if->power_down == 2) {
  70268. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  70269. + } else {
  70270. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  70271. + dwc_mdelay(5);
  70272. +
  70273. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70274. + hprt0.b.prtres = 1;
  70275. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70276. + hprt0.b.prtsusp = 0;
  70277. + /* Clear Resume bit */
  70278. + dwc_mdelay(100);
  70279. + hprt0.b.prtres = 0;
  70280. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70281. + }
  70282. + break;
  70283. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70284. + case UHF_PORT_L1:
  70285. + {
  70286. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70287. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  70288. +
  70289. + lpmcfg.d32 =
  70290. + DWC_READ_REG32(&core_if->
  70291. + core_global_regs->glpmcfg);
  70292. + lpmcfg.b.en_utmi_sleep = 0;
  70293. + lpmcfg.b.hird_thres &= (~(1 << 4));
  70294. + lpmcfg.b.prt_sleep_sts = 1;
  70295. + DWC_WRITE_REG32(&core_if->
  70296. + core_global_regs->glpmcfg,
  70297. + lpmcfg.d32);
  70298. +
  70299. + /* Clear Enbl_L1Gating bit. */
  70300. + pcgcctl.b.enbl_sleep_gating = 1;
  70301. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  70302. + 0);
  70303. +
  70304. + dwc_mdelay(5);
  70305. +
  70306. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70307. + hprt0.b.prtres = 1;
  70308. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70309. + hprt0.d32);
  70310. + /* This bit will be cleared in wakeup interrupt handle */
  70311. + break;
  70312. + }
  70313. +#endif
  70314. + case UHF_PORT_POWER:
  70315. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70316. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  70317. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70318. + hprt0.b.prtpwr = 0;
  70319. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70320. + break;
  70321. + case UHF_PORT_INDICATOR:
  70322. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70323. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  70324. + /* Port inidicator not supported */
  70325. + break;
  70326. + case UHF_C_PORT_CONNECTION:
  70327. + /* Clears drivers internal connect status change
  70328. + * flag */
  70329. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70330. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  70331. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  70332. + break;
  70333. + case UHF_C_PORT_RESET:
  70334. + /* Clears the driver's internal Port Reset Change
  70335. + * flag */
  70336. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70337. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  70338. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  70339. + break;
  70340. + case UHF_C_PORT_ENABLE:
  70341. + /* Clears the driver's internal Port
  70342. + * Enable/Disable Change flag */
  70343. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70344. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  70345. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  70346. + break;
  70347. + case UHF_C_PORT_SUSPEND:
  70348. + /* Clears the driver's internal Port Suspend
  70349. + * Change flag, which is set when resume signaling on
  70350. + * the host port is complete */
  70351. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70352. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  70353. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  70354. + break;
  70355. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70356. + case UHF_C_PORT_L1:
  70357. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  70358. + break;
  70359. +#endif
  70360. + case UHF_C_PORT_OVER_CURRENT:
  70361. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70362. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  70363. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  70364. + break;
  70365. + default:
  70366. + retval = -DWC_E_INVALID;
  70367. + DWC_ERROR("DWC OTG HCD - "
  70368. + "ClearPortFeature request %xh "
  70369. + "unknown or unsupported\n", wValue);
  70370. + }
  70371. + break;
  70372. + case UCR_GET_HUB_DESCRIPTOR:
  70373. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70374. + "GetHubDescriptor\n");
  70375. + hub_desc = (usb_hub_descriptor_t *) buf;
  70376. + hub_desc->bDescLength = 9;
  70377. + hub_desc->bDescriptorType = 0x29;
  70378. + hub_desc->bNbrPorts = 1;
  70379. + USETW(hub_desc->wHubCharacteristics, 0x08);
  70380. + hub_desc->bPwrOn2PwrGood = 1;
  70381. + hub_desc->bHubContrCurrent = 0;
  70382. + hub_desc->DeviceRemovable[0] = 0;
  70383. + hub_desc->DeviceRemovable[1] = 0xff;
  70384. + break;
  70385. + case UCR_GET_HUB_STATUS:
  70386. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70387. + "GetHubStatus\n");
  70388. + DWC_MEMSET(buf, 0, 4);
  70389. + break;
  70390. + case UCR_GET_PORT_STATUS:
  70391. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70392. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  70393. + wIndex, dwc_otg_hcd->flags.d32);
  70394. + if (!wIndex || wIndex > 1)
  70395. + goto error;
  70396. +
  70397. + port_status = 0;
  70398. +
  70399. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  70400. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  70401. +
  70402. + if (dwc_otg_hcd->flags.b.port_enable_change)
  70403. + port_status |= (1 << UHF_C_PORT_ENABLE);
  70404. +
  70405. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  70406. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  70407. +
  70408. + if (dwc_otg_hcd->flags.b.port_l1_change)
  70409. + port_status |= (1 << UHF_C_PORT_L1);
  70410. +
  70411. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  70412. + port_status |= (1 << UHF_C_PORT_RESET);
  70413. + }
  70414. +
  70415. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  70416. + DWC_WARN("Overcurrent change detected\n");
  70417. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  70418. + }
  70419. +
  70420. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  70421. + /*
  70422. + * The port is disconnected, which means the core is
  70423. + * either in device mode or it soon will be. Just
  70424. + * return 0's for the remainder of the port status
  70425. + * since the port register can't be read if the core
  70426. + * is in device mode.
  70427. + */
  70428. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  70429. + break;
  70430. + }
  70431. +
  70432. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  70433. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  70434. +
  70435. + if (hprt0.b.prtconnsts)
  70436. + port_status |= (1 << UHF_PORT_CONNECTION);
  70437. +
  70438. + if (hprt0.b.prtena)
  70439. + port_status |= (1 << UHF_PORT_ENABLE);
  70440. +
  70441. + if (hprt0.b.prtsusp)
  70442. + port_status |= (1 << UHF_PORT_SUSPEND);
  70443. +
  70444. + if (hprt0.b.prtovrcurract)
  70445. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  70446. +
  70447. + if (hprt0.b.prtrst)
  70448. + port_status |= (1 << UHF_PORT_RESET);
  70449. +
  70450. + if (hprt0.b.prtpwr)
  70451. + port_status |= (1 << UHF_PORT_POWER);
  70452. +
  70453. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  70454. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  70455. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  70456. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  70457. +
  70458. + if (hprt0.b.prttstctl)
  70459. + port_status |= (1 << UHF_PORT_TEST);
  70460. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  70461. + port_status |= (1 << UHF_PORT_L1);
  70462. + }
  70463. + /*
  70464. + For Synopsys HW emulation of Power down wkup_control asserts the
  70465. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  70466. + We intentionally tell the software that port is in L2Suspend state.
  70467. + Only for STE.
  70468. + */
  70469. + if ((core_if->power_down == 2)
  70470. + && (core_if->hibernation_suspend == 1)) {
  70471. + port_status |= (1 << UHF_PORT_SUSPEND);
  70472. + }
  70473. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  70474. +
  70475. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  70476. +
  70477. + break;
  70478. + case UCR_SET_HUB_FEATURE:
  70479. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70480. + "SetHubFeature\n");
  70481. + /* No HUB features supported */
  70482. + break;
  70483. + case UCR_SET_PORT_FEATURE:
  70484. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  70485. + goto error;
  70486. +
  70487. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  70488. + /*
  70489. + * The port is disconnected, which means the core is
  70490. + * either in device mode or it soon will be. Just
  70491. + * return without doing anything since the port
  70492. + * register can't be written if the core is in device
  70493. + * mode.
  70494. + */
  70495. + break;
  70496. + }
  70497. +
  70498. + switch (wValue) {
  70499. + case UHF_PORT_SUSPEND:
  70500. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70501. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  70502. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  70503. + goto error;
  70504. + }
  70505. + if (core_if->power_down == 2) {
  70506. + int timeout = 300;
  70507. + dwc_irqflags_t flags;
  70508. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70509. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  70510. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  70511. +#ifdef DWC_DEV_SRPCAP
  70512. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  70513. +#endif
  70514. + DWC_PRINTF("Preparing for complete power-off\n");
  70515. +
  70516. + /* Save registers before hibernation */
  70517. + dwc_otg_save_global_regs(core_if);
  70518. + dwc_otg_save_host_regs(core_if);
  70519. +
  70520. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70521. + hprt0.b.prtsusp = 1;
  70522. + hprt0.b.prtena = 0;
  70523. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70524. + /* Spin hprt0.b.prtsusp to became 1 */
  70525. + do {
  70526. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70527. + if (hprt0.b.prtsusp) {
  70528. + break;
  70529. + }
  70530. + dwc_mdelay(1);
  70531. + } while (--timeout);
  70532. + if (!timeout) {
  70533. + DWC_WARN("Suspend wasn't genereted\n");
  70534. + }
  70535. + dwc_udelay(10);
  70536. +
  70537. + /*
  70538. + * We need to disable interrupts to prevent servicing of any IRQ
  70539. + * during going to hibernation
  70540. + */
  70541. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  70542. + core_if->lx_state = DWC_OTG_L2;
  70543. +#ifdef DWC_DEV_SRPCAP
  70544. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70545. + hprt0.b.prtpwr = 0;
  70546. + hprt0.b.prtena = 0;
  70547. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70548. + hprt0.d32);
  70549. +#endif
  70550. + gusbcfg.d32 =
  70551. + DWC_READ_REG32(&core_if->core_global_regs->
  70552. + gusbcfg);
  70553. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  70554. + /* ULPI interface */
  70555. + /* Suspend the Phy Clock */
  70556. + pcgcctl.d32 = 0;
  70557. + pcgcctl.b.stoppclk = 1;
  70558. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  70559. + pcgcctl.d32);
  70560. + dwc_udelay(10);
  70561. + gpwrdn.b.pmuactv = 1;
  70562. + DWC_MODIFY_REG32(&core_if->
  70563. + core_global_regs->
  70564. + gpwrdn, 0, gpwrdn.d32);
  70565. + } else {
  70566. + /* UTMI+ Interface */
  70567. + gpwrdn.b.pmuactv = 1;
  70568. + DWC_MODIFY_REG32(&core_if->
  70569. + core_global_regs->
  70570. + gpwrdn, 0, gpwrdn.d32);
  70571. + dwc_udelay(10);
  70572. + pcgcctl.b.stoppclk = 1;
  70573. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  70574. + dwc_udelay(10);
  70575. + }
  70576. +#ifdef DWC_DEV_SRPCAP
  70577. + gpwrdn.d32 = 0;
  70578. + gpwrdn.b.dis_vbus = 1;
  70579. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70580. + gpwrdn, 0, gpwrdn.d32);
  70581. +#endif
  70582. + gpwrdn.d32 = 0;
  70583. + gpwrdn.b.pmuintsel = 1;
  70584. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70585. + gpwrdn, 0, gpwrdn.d32);
  70586. + dwc_udelay(10);
  70587. +
  70588. + gpwrdn.d32 = 0;
  70589. +#ifdef DWC_DEV_SRPCAP
  70590. + gpwrdn.b.srp_det_msk = 1;
  70591. +#endif
  70592. + gpwrdn.b.disconn_det_msk = 1;
  70593. + gpwrdn.b.lnstchng_msk = 1;
  70594. + gpwrdn.b.sts_chngint_msk = 1;
  70595. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70596. + gpwrdn, 0, gpwrdn.d32);
  70597. + dwc_udelay(10);
  70598. +
  70599. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  70600. + gpwrdn.d32 = 0;
  70601. + gpwrdn.b.pwrdnclmp = 1;
  70602. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70603. + gpwrdn, 0, gpwrdn.d32);
  70604. + dwc_udelay(10);
  70605. +
  70606. + /* Switch off VDD */
  70607. + gpwrdn.d32 = 0;
  70608. + gpwrdn.b.pwrdnswtch = 1;
  70609. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70610. + gpwrdn, 0, gpwrdn.d32);
  70611. +
  70612. +#ifdef DWC_DEV_SRPCAP
  70613. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  70614. + {
  70615. + core_if->pwron_timer_started = 1;
  70616. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  70617. + }
  70618. +#endif
  70619. + /* Save gpwrdn register for further usage if stschng interrupt */
  70620. + core_if->gr_backup->gpwrdn_local =
  70621. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  70622. +
  70623. + /* Set flag to indicate that we are in hibernation */
  70624. + core_if->hibernation_suspend = 1;
  70625. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  70626. +
  70627. + DWC_PRINTF("Host hibernation completed\n");
  70628. + // Exit from case statement
  70629. + break;
  70630. +
  70631. + }
  70632. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  70633. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  70634. + gotgctl_data_t gotgctl = {.d32 = 0 };
  70635. + gotgctl.b.hstsethnpen = 1;
  70636. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70637. + gotgctl, 0, gotgctl.d32);
  70638. + core_if->op_state = A_SUSPEND;
  70639. + }
  70640. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70641. + hprt0.b.prtsusp = 1;
  70642. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70643. + {
  70644. + dwc_irqflags_t flags;
  70645. + /* Update lx_state */
  70646. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  70647. + core_if->lx_state = DWC_OTG_L2;
  70648. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  70649. + }
  70650. + /* Suspend the Phy Clock */
  70651. + {
  70652. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70653. + pcgcctl.b.stoppclk = 1;
  70654. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  70655. + pcgcctl.d32);
  70656. + dwc_udelay(10);
  70657. + }
  70658. +
  70659. + /* For HNP the bus must be suspended for at least 200ms. */
  70660. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  70661. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70662. + pcgcctl.b.stoppclk = 1;
  70663. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  70664. + dwc_mdelay(200);
  70665. + }
  70666. +
  70667. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  70668. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  70669. + if (core_if->adp_enable) {
  70670. + gotgctl_data_t gotgctl = {.d32 = 0 };
  70671. + gpwrdn_data_t gpwrdn;
  70672. +
  70673. + while (gotgctl.b.asesvld == 1) {
  70674. + gotgctl.d32 =
  70675. + DWC_READ_REG32(&core_if->
  70676. + core_global_regs->
  70677. + gotgctl);
  70678. + dwc_mdelay(100);
  70679. + }
  70680. +
  70681. + /* Enable Power Down Logic */
  70682. + gpwrdn.d32 = 0;
  70683. + gpwrdn.b.pmuactv = 1;
  70684. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70685. + gpwrdn, 0, gpwrdn.d32);
  70686. +
  70687. + /* Unmask SRP detected interrupt from Power Down Logic */
  70688. + gpwrdn.d32 = 0;
  70689. + gpwrdn.b.srp_det_msk = 1;
  70690. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  70691. + gpwrdn, 0, gpwrdn.d32);
  70692. +
  70693. + dwc_otg_adp_probe_start(core_if);
  70694. + }
  70695. +#endif
  70696. + break;
  70697. + case UHF_PORT_POWER:
  70698. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70699. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  70700. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70701. + hprt0.b.prtpwr = 1;
  70702. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70703. + break;
  70704. + case UHF_PORT_RESET:
  70705. + if ((core_if->power_down == 2)
  70706. + && (core_if->hibernation_suspend == 1)) {
  70707. + /* If we are going to exit from Hibernated
  70708. + * state via USB RESET.
  70709. + */
  70710. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  70711. + } else {
  70712. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70713. +
  70714. + DWC_DEBUGPL(DBG_HCD,
  70715. + "DWC OTG HCD HUB CONTROL - "
  70716. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  70717. + {
  70718. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  70719. + pcgcctl.b.enbl_sleep_gating = 1;
  70720. + pcgcctl.b.stoppclk = 1;
  70721. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  70722. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  70723. + }
  70724. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70725. + {
  70726. + glpmcfg_data_t lpmcfg;
  70727. + lpmcfg.d32 =
  70728. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70729. + if (lpmcfg.b.prt_sleep_sts) {
  70730. + lpmcfg.b.en_utmi_sleep = 0;
  70731. + lpmcfg.b.hird_thres &= (~(1 << 4));
  70732. + DWC_WRITE_REG32
  70733. + (&core_if->core_global_regs->glpmcfg,
  70734. + lpmcfg.d32);
  70735. + dwc_mdelay(1);
  70736. + }
  70737. + }
  70738. +#endif
  70739. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70740. + /* Clear suspend bit if resetting from suspended state. */
  70741. + hprt0.b.prtsusp = 0;
  70742. + /* When B-Host the Port reset bit is set in
  70743. + * the Start HCD Callback function, so that
  70744. + * the reset is started within 1ms of the HNP
  70745. + * success interrupt. */
  70746. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  70747. + hprt0.b.prtpwr = 1;
  70748. + hprt0.b.prtrst = 1;
  70749. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  70750. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70751. + hprt0.d32);
  70752. + }
  70753. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  70754. + dwc_mdelay(60);
  70755. + hprt0.b.prtrst = 0;
  70756. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70757. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  70758. + }
  70759. + break;
  70760. +#ifdef DWC_HS_ELECT_TST
  70761. + case UHF_PORT_TEST:
  70762. + {
  70763. + uint32_t t;
  70764. + gintmsk_data_t gintmsk;
  70765. +
  70766. + t = (wIndex >> 8); /* MSB wIndex USB */
  70767. + DWC_DEBUGPL(DBG_HCD,
  70768. + "DWC OTG HCD HUB CONTROL - "
  70769. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  70770. + t);
  70771. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  70772. + if (t < 6) {
  70773. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70774. + hprt0.b.prttstctl = t;
  70775. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  70776. + hprt0.d32);
  70777. + } else {
  70778. + /* Setup global vars with reg addresses (quick and
  70779. + * dirty hack, should be cleaned up)
  70780. + */
  70781. + global_regs = core_if->core_global_regs;
  70782. + hc_global_regs =
  70783. + core_if->host_if->host_global_regs;
  70784. + hc_regs =
  70785. + (dwc_otg_hc_regs_t *) ((char *)
  70786. + global_regs +
  70787. + 0x500);
  70788. + data_fifo =
  70789. + (uint32_t *) ((char *)global_regs +
  70790. + 0x1000);
  70791. +
  70792. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  70793. + /* Save current interrupt mask */
  70794. + gintmsk.d32 =
  70795. + DWC_READ_REG32
  70796. + (&global_regs->gintmsk);
  70797. +
  70798. + /* Disable all interrupts while we muck with
  70799. + * the hardware directly
  70800. + */
  70801. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70802. +
  70803. + /* 15 second delay per the test spec */
  70804. + dwc_mdelay(15000);
  70805. +
  70806. + /* Drive suspend on the root port */
  70807. + hprt0.d32 =
  70808. + dwc_otg_read_hprt0(core_if);
  70809. + hprt0.b.prtsusp = 1;
  70810. + hprt0.b.prtres = 0;
  70811. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70812. +
  70813. + /* 15 second delay per the test spec */
  70814. + dwc_mdelay(15000);
  70815. +
  70816. + /* Drive resume on the root port */
  70817. + hprt0.d32 =
  70818. + dwc_otg_read_hprt0(core_if);
  70819. + hprt0.b.prtsusp = 0;
  70820. + hprt0.b.prtres = 1;
  70821. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70822. + dwc_mdelay(100);
  70823. +
  70824. + /* Clear the resume bit */
  70825. + hprt0.b.prtres = 0;
  70826. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70827. +
  70828. + /* Restore interrupts */
  70829. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70830. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  70831. + /* Save current interrupt mask */
  70832. + gintmsk.d32 =
  70833. + DWC_READ_REG32
  70834. + (&global_regs->gintmsk);
  70835. +
  70836. + /* Disable all interrupts while we muck with
  70837. + * the hardware directly
  70838. + */
  70839. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70840. +
  70841. + /* 15 second delay per the test spec */
  70842. + dwc_mdelay(15000);
  70843. +
  70844. + /* Send the Setup packet */
  70845. + do_setup();
  70846. +
  70847. + /* 15 second delay so nothing else happens for awhile */
  70848. + dwc_mdelay(15000);
  70849. +
  70850. + /* Restore interrupts */
  70851. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70852. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  70853. + /* Save current interrupt mask */
  70854. + gintmsk.d32 =
  70855. + DWC_READ_REG32
  70856. + (&global_regs->gintmsk);
  70857. +
  70858. + /* Disable all interrupts while we muck with
  70859. + * the hardware directly
  70860. + */
  70861. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  70862. +
  70863. + /* Send the Setup packet */
  70864. + do_setup();
  70865. +
  70866. + /* 15 second delay so nothing else happens for awhile */
  70867. + dwc_mdelay(15000);
  70868. +
  70869. + /* Send the In and Ack packets */
  70870. + do_in_ack();
  70871. +
  70872. + /* 15 second delay so nothing else happens for awhile */
  70873. + dwc_mdelay(15000);
  70874. +
  70875. + /* Restore interrupts */
  70876. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  70877. + }
  70878. + }
  70879. + break;
  70880. + }
  70881. +#endif /* DWC_HS_ELECT_TST */
  70882. +
  70883. + case UHF_PORT_INDICATOR:
  70884. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  70885. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  70886. + /* Not supported */
  70887. + break;
  70888. + default:
  70889. + retval = -DWC_E_INVALID;
  70890. + DWC_ERROR("DWC OTG HCD - "
  70891. + "SetPortFeature request %xh "
  70892. + "unknown or unsupported\n", wValue);
  70893. + break;
  70894. + }
  70895. + break;
  70896. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70897. + case UCR_SET_AND_TEST_PORT_FEATURE:
  70898. + if (wValue != UHF_PORT_L1) {
  70899. + goto error;
  70900. + }
  70901. + {
  70902. + int portnum, hird, devaddr, remwake;
  70903. + glpmcfg_data_t lpmcfg;
  70904. + uint32_t time_usecs;
  70905. + gintsts_data_t gintsts;
  70906. + gintmsk_data_t gintmsk;
  70907. +
  70908. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  70909. + goto error;
  70910. + }
  70911. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  70912. + goto error;
  70913. + }
  70914. + /* Check if the port currently is in SLEEP state */
  70915. + lpmcfg.d32 =
  70916. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70917. + if (lpmcfg.b.prt_sleep_sts) {
  70918. + DWC_INFO("Port is already in sleep mode\n");
  70919. + buf[0] = 0; /* Return success */
  70920. + break;
  70921. + }
  70922. +
  70923. + portnum = wIndex & 0xf;
  70924. + hird = (wIndex >> 4) & 0xf;
  70925. + devaddr = (wIndex >> 8) & 0x7f;
  70926. + remwake = (wIndex >> 15);
  70927. +
  70928. + if (portnum != 1) {
  70929. + retval = -DWC_E_INVALID;
  70930. + DWC_WARN
  70931. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  70932. + portnum);
  70933. + break;
  70934. + }
  70935. +
  70936. + DWC_PRINTF
  70937. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  70938. + portnum, hird, devaddr, remwake);
  70939. + /* Disable LPM interrupt */
  70940. + gintmsk.d32 = 0;
  70941. + gintmsk.b.lpmtranrcvd = 1;
  70942. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  70943. + gintmsk.d32, 0);
  70944. +
  70945. + if (dwc_otg_hcd_send_lpm
  70946. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  70947. + retval = -DWC_E_INVALID;
  70948. + break;
  70949. + }
  70950. +
  70951. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  70952. + /* We will consider timeout if time_usecs microseconds pass,
  70953. + * and we don't receive LPM transaction status.
  70954. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  70955. + * core will set lpmtranrcvd bit.
  70956. + */
  70957. + do {
  70958. + gintsts.d32 =
  70959. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  70960. + if (gintsts.b.lpmtranrcvd) {
  70961. + break;
  70962. + }
  70963. + dwc_udelay(1);
  70964. + } while (--time_usecs);
  70965. + /* lpm_int bit will be cleared in LPM interrupt handler */
  70966. +
  70967. + /* Now fill status
  70968. + * 0x00 - Success
  70969. + * 0x10 - NYET
  70970. + * 0x11 - Timeout
  70971. + */
  70972. + if (!gintsts.b.lpmtranrcvd) {
  70973. + buf[0] = 0x3; /* Completion code is Timeout */
  70974. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  70975. + } else {
  70976. + lpmcfg.d32 =
  70977. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  70978. + if (lpmcfg.b.lpm_resp == 0x3) {
  70979. + /* ACK responce from the device */
  70980. + buf[0] = 0x00; /* Success */
  70981. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  70982. + /* NYET responce from the device */
  70983. + buf[0] = 0x2;
  70984. + } else {
  70985. + /* Otherwise responce with Timeout */
  70986. + buf[0] = 0x3;
  70987. + }
  70988. + }
  70989. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  70990. + lpmcfg.b.lpm_resp);
  70991. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  70992. + gintmsk.d32);
  70993. +
  70994. + break;
  70995. + }
  70996. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  70997. + default:
  70998. +error:
  70999. + retval = -DWC_E_INVALID;
  71000. + DWC_WARN("DWC OTG HCD - "
  71001. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  71002. + typeReq, wIndex, wValue);
  71003. + break;
  71004. + }
  71005. +
  71006. + return retval;
  71007. +}
  71008. +
  71009. +#ifdef CONFIG_USB_DWC_OTG_LPM
  71010. +/** Returns index of host channel to perform LPM transaction. */
  71011. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  71012. +{
  71013. + dwc_otg_core_if_t *core_if = hcd->core_if;
  71014. + dwc_hc_t *hc;
  71015. + hcchar_data_t hcchar;
  71016. + gintmsk_data_t gintmsk = {.d32 = 0 };
  71017. +
  71018. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71019. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  71020. + return -1;
  71021. + }
  71022. +
  71023. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  71024. +
  71025. + /* Mask host channel interrupts. */
  71026. + gintmsk.b.hcintr = 1;
  71027. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  71028. +
  71029. + /* Fill fields that core needs for LPM transaction */
  71030. + hcchar.b.devaddr = devaddr;
  71031. + hcchar.b.epnum = 0;
  71032. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  71033. + hcchar.b.mps = 64;
  71034. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  71035. + hcchar.b.epdir = 0; /* OUT */
  71036. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  71037. + hcchar.d32);
  71038. +
  71039. + /* Remove the host channel from the free list. */
  71040. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  71041. +
  71042. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  71043. +
  71044. + return hc->hc_num;
  71045. +}
  71046. +
  71047. +/** Release hc after performing LPM transaction */
  71048. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  71049. +{
  71050. + dwc_hc_t *hc;
  71051. + glpmcfg_data_t lpmcfg;
  71052. + uint8_t hc_num;
  71053. +
  71054. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  71055. + hc_num = lpmcfg.b.lpm_chan_index;
  71056. +
  71057. + hc = hcd->hc_ptr_array[hc_num];
  71058. +
  71059. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  71060. + /* Return host channel to free list */
  71061. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  71062. +}
  71063. +
  71064. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  71065. + uint8_t bRemoteWake)
  71066. +{
  71067. + glpmcfg_data_t lpmcfg;
  71068. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  71069. + int channel;
  71070. +
  71071. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  71072. + if (channel < 0) {
  71073. + return channel;
  71074. + }
  71075. +
  71076. + pcgcctl.b.enbl_sleep_gating = 1;
  71077. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  71078. +
  71079. + /* Read LPM config register */
  71080. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  71081. +
  71082. + /* Program LPM transaction fields */
  71083. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  71084. + lpmcfg.b.hird = hird;
  71085. + lpmcfg.b.hird_thres = 0x1c;
  71086. + lpmcfg.b.lpm_chan_index = channel;
  71087. + lpmcfg.b.en_utmi_sleep = 1;
  71088. + /* Program LPM config register */
  71089. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  71090. +
  71091. + /* Send LPM transaction */
  71092. + lpmcfg.b.send_lpm = 1;
  71093. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  71094. +
  71095. + return 0;
  71096. +}
  71097. +
  71098. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  71099. +
  71100. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  71101. +{
  71102. + int retval;
  71103. +
  71104. + if (port != 1) {
  71105. + return -DWC_E_INVALID;
  71106. + }
  71107. +
  71108. + retval = (hcd->flags.b.port_connect_status_change ||
  71109. + hcd->flags.b.port_reset_change ||
  71110. + hcd->flags.b.port_enable_change ||
  71111. + hcd->flags.b.port_suspend_change ||
  71112. + hcd->flags.b.port_over_current_change);
  71113. +#ifdef DEBUG
  71114. + if (retval) {
  71115. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  71116. + " Root port status changed\n");
  71117. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  71118. + hcd->flags.b.port_connect_status_change);
  71119. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  71120. + hcd->flags.b.port_reset_change);
  71121. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  71122. + hcd->flags.b.port_enable_change);
  71123. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  71124. + hcd->flags.b.port_suspend_change);
  71125. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  71126. + hcd->flags.b.port_over_current_change);
  71127. + }
  71128. +#endif
  71129. + return retval;
  71130. +}
  71131. +
  71132. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  71133. +{
  71134. + hfnum_data_t hfnum;
  71135. + hfnum.d32 =
  71136. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  71137. + hfnum);
  71138. +
  71139. +#ifdef DEBUG_SOF
  71140. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  71141. + hfnum.b.frnum);
  71142. +#endif
  71143. + return hfnum.b.frnum;
  71144. +}
  71145. +
  71146. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  71147. + struct dwc_otg_hcd_function_ops *fops)
  71148. +{
  71149. + int retval = 0;
  71150. +
  71151. + hcd->fops = fops;
  71152. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  71153. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  71154. + dwc_otg_hcd_reinit(hcd);
  71155. + } else {
  71156. + retval = -DWC_E_NO_DEVICE;
  71157. + }
  71158. +
  71159. + return retval;
  71160. +}
  71161. +
  71162. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  71163. +{
  71164. + return hcd->priv;
  71165. +}
  71166. +
  71167. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  71168. +{
  71169. + hcd->priv = priv_data;
  71170. +}
  71171. +
  71172. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  71173. +{
  71174. + return hcd->otg_port;
  71175. +}
  71176. +
  71177. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  71178. +{
  71179. + uint32_t is_b_host;
  71180. + if (hcd->core_if->op_state == B_HOST) {
  71181. + is_b_host = 1;
  71182. + } else {
  71183. + is_b_host = 0;
  71184. + }
  71185. +
  71186. + return is_b_host;
  71187. +}
  71188. +
  71189. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  71190. + int iso_desc_count, int atomic_alloc)
  71191. +{
  71192. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  71193. + uint32_t size;
  71194. +
  71195. + size =
  71196. + sizeof(*dwc_otg_urb) +
  71197. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  71198. + if (atomic_alloc)
  71199. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  71200. + else
  71201. + dwc_otg_urb = DWC_ALLOC(size);
  71202. +
  71203. + if (dwc_otg_urb)
  71204. + dwc_otg_urb->packet_count = iso_desc_count;
  71205. + else {
  71206. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  71207. + "%salloc of %db failed\n",
  71208. + atomic_alloc?"atomic ":"", size);
  71209. + }
  71210. + return dwc_otg_urb;
  71211. +}
  71212. +
  71213. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71214. + uint8_t dev_addr, uint8_t ep_num,
  71215. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  71216. +{
  71217. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  71218. + ep_type, ep_dir, mps);
  71219. +#if 0
  71220. + DWC_PRINTF
  71221. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  71222. + dev_addr, ep_num, ep_dir, ep_type, mps);
  71223. +#endif
  71224. +}
  71225. +
  71226. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71227. + void *urb_handle, void *buf, dwc_dma_t dma,
  71228. + uint32_t buflen, void *setup_packet,
  71229. + dwc_dma_t setup_dma, uint32_t flags,
  71230. + uint16_t interval)
  71231. +{
  71232. + dwc_otg_urb->priv = urb_handle;
  71233. + dwc_otg_urb->buf = buf;
  71234. + dwc_otg_urb->dma = dma;
  71235. + dwc_otg_urb->length = buflen;
  71236. + dwc_otg_urb->setup_packet = setup_packet;
  71237. + dwc_otg_urb->setup_dma = setup_dma;
  71238. + dwc_otg_urb->flags = flags;
  71239. + dwc_otg_urb->interval = interval;
  71240. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  71241. +}
  71242. +
  71243. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71244. +{
  71245. + return dwc_otg_urb->status;
  71246. +}
  71247. +
  71248. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71249. +{
  71250. + return dwc_otg_urb->actual_length;
  71251. +}
  71252. +
  71253. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  71254. +{
  71255. + return dwc_otg_urb->error_count;
  71256. +}
  71257. +
  71258. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71259. + int desc_num, uint32_t offset,
  71260. + uint32_t length)
  71261. +{
  71262. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  71263. + dwc_otg_urb->iso_descs[desc_num].length = length;
  71264. +}
  71265. +
  71266. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  71267. + int desc_num)
  71268. +{
  71269. + return dwc_otg_urb->iso_descs[desc_num].status;
  71270. +}
  71271. +
  71272. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  71273. + dwc_otg_urb, int desc_num)
  71274. +{
  71275. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  71276. +}
  71277. +
  71278. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  71279. +{
  71280. + int allocated = 0;
  71281. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71282. +
  71283. + if (qh) {
  71284. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  71285. + allocated = 1;
  71286. + }
  71287. + }
  71288. + return allocated;
  71289. +}
  71290. +
  71291. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  71292. +{
  71293. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71294. + int freed = 0;
  71295. + DWC_ASSERT(qh, "qh is not allocated\n");
  71296. +
  71297. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  71298. + freed = 1;
  71299. + }
  71300. +
  71301. + return freed;
  71302. +}
  71303. +
  71304. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  71305. +{
  71306. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  71307. + DWC_ASSERT(qh, "qh is not allocated\n");
  71308. + return qh->usecs;
  71309. +}
  71310. +
  71311. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  71312. +{
  71313. +#ifdef DEBUG
  71314. + int num_channels;
  71315. + int i;
  71316. + gnptxsts_data_t np_tx_status;
  71317. + hptxsts_data_t p_tx_status;
  71318. +
  71319. + num_channels = hcd->core_if->core_params->host_channels;
  71320. + DWC_PRINTF("\n");
  71321. + DWC_PRINTF
  71322. + ("************************************************************\n");
  71323. + DWC_PRINTF("HCD State:\n");
  71324. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  71325. + for (i = 0; i < num_channels; i++) {
  71326. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  71327. + DWC_PRINTF(" Channel %d:\n", i);
  71328. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  71329. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  71330. + DWC_PRINTF(" speed: %d\n", hc->speed);
  71331. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  71332. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  71333. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  71334. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  71335. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  71336. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  71337. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  71338. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  71339. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  71340. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  71341. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  71342. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  71343. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  71344. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  71345. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  71346. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  71347. + DWC_PRINTF(" requests: %d\n", hc->requests);
  71348. + DWC_PRINTF(" qh: %p\n", hc->qh);
  71349. + if (hc->xfer_started) {
  71350. + hfnum_data_t hfnum;
  71351. + hcchar_data_t hcchar;
  71352. + hctsiz_data_t hctsiz;
  71353. + hcint_data_t hcint;
  71354. + hcintmsk_data_t hcintmsk;
  71355. + hfnum.d32 =
  71356. + DWC_READ_REG32(&hcd->core_if->
  71357. + host_if->host_global_regs->hfnum);
  71358. + hcchar.d32 =
  71359. + DWC_READ_REG32(&hcd->core_if->host_if->
  71360. + hc_regs[i]->hcchar);
  71361. + hctsiz.d32 =
  71362. + DWC_READ_REG32(&hcd->core_if->host_if->
  71363. + hc_regs[i]->hctsiz);
  71364. + hcint.d32 =
  71365. + DWC_READ_REG32(&hcd->core_if->host_if->
  71366. + hc_regs[i]->hcint);
  71367. + hcintmsk.d32 =
  71368. + DWC_READ_REG32(&hcd->core_if->host_if->
  71369. + hc_regs[i]->hcintmsk);
  71370. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  71371. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  71372. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  71373. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  71374. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  71375. + }
  71376. + if (hc->xfer_started && hc->qh) {
  71377. + dwc_otg_qtd_t *qtd;
  71378. + dwc_otg_hcd_urb_t *urb;
  71379. +
  71380. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  71381. + if (!qtd->in_process)
  71382. + break;
  71383. +
  71384. + urb = qtd->urb;
  71385. + DWC_PRINTF(" URB Info:\n");
  71386. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  71387. + if (urb) {
  71388. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  71389. + dwc_otg_hcd_get_dev_addr(&urb->
  71390. + pipe_info),
  71391. + dwc_otg_hcd_get_ep_num(&urb->
  71392. + pipe_info),
  71393. + dwc_otg_hcd_is_pipe_in(&urb->
  71394. + pipe_info) ?
  71395. + "IN" : "OUT");
  71396. + DWC_PRINTF(" Max packet size: %d\n",
  71397. + dwc_otg_hcd_get_mps(&urb->
  71398. + pipe_info));
  71399. + DWC_PRINTF(" transfer_buffer: %p\n",
  71400. + urb->buf);
  71401. + DWC_PRINTF(" transfer_dma: %p\n",
  71402. + (void *)urb->dma);
  71403. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  71404. + urb->length);
  71405. + DWC_PRINTF(" actual_length: %d\n",
  71406. + urb->actual_length);
  71407. + }
  71408. + }
  71409. + }
  71410. + }
  71411. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  71412. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  71413. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  71414. + np_tx_status.d32 =
  71415. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  71416. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  71417. + np_tx_status.b.nptxqspcavail);
  71418. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  71419. + np_tx_status.b.nptxfspcavail);
  71420. + p_tx_status.d32 =
  71421. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  71422. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  71423. + p_tx_status.b.ptxqspcavail);
  71424. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  71425. + dwc_otg_hcd_dump_frrem(hcd);
  71426. + dwc_otg_dump_global_registers(hcd->core_if);
  71427. + dwc_otg_dump_host_registers(hcd->core_if);
  71428. + DWC_PRINTF
  71429. + ("************************************************************\n");
  71430. + DWC_PRINTF("\n");
  71431. +#endif
  71432. +}
  71433. +
  71434. +#ifdef DEBUG
  71435. +void dwc_print_setup_data(uint8_t * setup)
  71436. +{
  71437. + int i;
  71438. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  71439. + DWC_PRINTF("Setup Data = MSB ");
  71440. + for (i = 7; i >= 0; i--)
  71441. + DWC_PRINTF("%02x ", setup[i]);
  71442. + DWC_PRINTF("\n");
  71443. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  71444. + (setup[0] & 0x80) ? "Device-to-Host" :
  71445. + "Host-to-Device");
  71446. + DWC_PRINTF(" bmRequestType Type = ");
  71447. + switch ((setup[0] & 0x60) >> 5) {
  71448. + case 0:
  71449. + DWC_PRINTF("Standard\n");
  71450. + break;
  71451. + case 1:
  71452. + DWC_PRINTF("Class\n");
  71453. + break;
  71454. + case 2:
  71455. + DWC_PRINTF("Vendor\n");
  71456. + break;
  71457. + case 3:
  71458. + DWC_PRINTF("Reserved\n");
  71459. + break;
  71460. + }
  71461. + DWC_PRINTF(" bmRequestType Recipient = ");
  71462. + switch (setup[0] & 0x1f) {
  71463. + case 0:
  71464. + DWC_PRINTF("Device\n");
  71465. + break;
  71466. + case 1:
  71467. + DWC_PRINTF("Interface\n");
  71468. + break;
  71469. + case 2:
  71470. + DWC_PRINTF("Endpoint\n");
  71471. + break;
  71472. + case 3:
  71473. + DWC_PRINTF("Other\n");
  71474. + break;
  71475. + default:
  71476. + DWC_PRINTF("Reserved\n");
  71477. + break;
  71478. + }
  71479. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  71480. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  71481. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  71482. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  71483. + }
  71484. +}
  71485. +#endif
  71486. +
  71487. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  71488. +{
  71489. +#if 0
  71490. + DWC_PRINTF("Frame remaining at SOF:\n");
  71491. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71492. + hcd->frrem_samples, hcd->frrem_accum,
  71493. + (hcd->frrem_samples > 0) ?
  71494. + hcd->frrem_accum / hcd->frrem_samples : 0);
  71495. +
  71496. + DWC_PRINTF("\n");
  71497. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  71498. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71499. + hcd->core_if->hfnum_7_samples,
  71500. + hcd->core_if->hfnum_7_frrem_accum,
  71501. + (hcd->core_if->hfnum_7_samples >
  71502. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  71503. + hcd->core_if->hfnum_7_samples : 0);
  71504. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  71505. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71506. + hcd->core_if->hfnum_0_samples,
  71507. + hcd->core_if->hfnum_0_frrem_accum,
  71508. + (hcd->core_if->hfnum_0_samples >
  71509. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  71510. + hcd->core_if->hfnum_0_samples : 0);
  71511. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  71512. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71513. + hcd->core_if->hfnum_other_samples,
  71514. + hcd->core_if->hfnum_other_frrem_accum,
  71515. + (hcd->core_if->hfnum_other_samples >
  71516. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  71517. + hcd->core_if->hfnum_other_samples : 0);
  71518. +
  71519. + DWC_PRINTF("\n");
  71520. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  71521. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71522. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  71523. + (hcd->hfnum_7_samples_a > 0) ?
  71524. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  71525. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  71526. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71527. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  71528. + (hcd->hfnum_0_samples_a > 0) ?
  71529. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  71530. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  71531. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71532. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  71533. + (hcd->hfnum_other_samples_a > 0) ?
  71534. + hcd->hfnum_other_frrem_accum_a /
  71535. + hcd->hfnum_other_samples_a : 0);
  71536. +
  71537. + DWC_PRINTF("\n");
  71538. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  71539. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71540. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  71541. + (hcd->hfnum_7_samples_b > 0) ?
  71542. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  71543. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  71544. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71545. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  71546. + (hcd->hfnum_0_samples_b > 0) ?
  71547. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  71548. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  71549. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  71550. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  71551. + (hcd->hfnum_other_samples_b > 0) ?
  71552. + hcd->hfnum_other_frrem_accum_b /
  71553. + hcd->hfnum_other_samples_b : 0);
  71554. +#endif
  71555. +}
  71556. +
  71557. +#endif /* DWC_DEVICE_ONLY */
  71558. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  71559. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  71560. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-02-07 19:57:30.000000000 +0100
  71561. @@ -0,0 +1,1132 @@
  71562. +/*==========================================================================
  71563. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  71564. + * $Revision: #10 $
  71565. + * $Date: 2011/10/20 $
  71566. + * $Change: 1869464 $
  71567. + *
  71568. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  71569. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  71570. + * otherwise expressly agreed to in writing between Synopsys and you.
  71571. + *
  71572. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  71573. + * any End User Software License Agreement or Agreement for Licensed Product
  71574. + * with Synopsys or any supplement thereto. You are permitted to use and
  71575. + * redistribute this Software in source and binary forms, with or without
  71576. + * modification, provided that redistributions of source code must retain this
  71577. + * notice. You may not view, use, disclose, copy or distribute this file or
  71578. + * any information contained herein except pursuant to this license grant from
  71579. + * Synopsys. If you do not agree with this notice, including the disclaimer
  71580. + * below, then you are not authorized to use the Software.
  71581. + *
  71582. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  71583. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  71584. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  71585. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  71586. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  71587. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  71588. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  71589. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  71590. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  71591. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  71592. + * DAMAGE.
  71593. + * ========================================================================== */
  71594. +#ifndef DWC_DEVICE_ONLY
  71595. +
  71596. +/** @file
  71597. + * This file contains Descriptor DMA support implementation for host mode.
  71598. + */
  71599. +
  71600. +#include "dwc_otg_hcd.h"
  71601. +#include "dwc_otg_regs.h"
  71602. +
  71603. +extern bool microframe_schedule;
  71604. +
  71605. +static inline uint8_t frame_list_idx(uint16_t frame)
  71606. +{
  71607. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  71608. +}
  71609. +
  71610. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  71611. +{
  71612. + return (idx + inc) &
  71613. + (((speed ==
  71614. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  71615. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  71616. +}
  71617. +
  71618. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  71619. +{
  71620. + return (idx - inc) &
  71621. + (((speed ==
  71622. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  71623. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  71624. +}
  71625. +
  71626. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  71627. +{
  71628. + return (((qh->ep_type == UE_ISOCHRONOUS)
  71629. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  71630. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  71631. +}
  71632. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  71633. +{
  71634. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  71635. + ? ((qh->interval + 8 - 1) / 8)
  71636. + : qh->interval);
  71637. +}
  71638. +
  71639. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  71640. +{
  71641. + int retval = 0;
  71642. +
  71643. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  71644. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  71645. + &qh->desc_list_dma);
  71646. +
  71647. + if (!qh->desc_list) {
  71648. + retval = -DWC_E_NO_MEMORY;
  71649. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  71650. +
  71651. + }
  71652. +
  71653. + dwc_memset(qh->desc_list, 0x00,
  71654. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  71655. +
  71656. + qh->n_bytes =
  71657. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  71658. +
  71659. + if (!qh->n_bytes) {
  71660. + retval = -DWC_E_NO_MEMORY;
  71661. + DWC_ERROR
  71662. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  71663. + __func__);
  71664. +
  71665. + }
  71666. + return retval;
  71667. +
  71668. +}
  71669. +
  71670. +static void desc_list_free(dwc_otg_qh_t * qh)
  71671. +{
  71672. + if (qh->desc_list) {
  71673. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  71674. + qh->desc_list_dma);
  71675. + qh->desc_list = NULL;
  71676. + }
  71677. +
  71678. + if (qh->n_bytes) {
  71679. + DWC_FREE(qh->n_bytes);
  71680. + qh->n_bytes = NULL;
  71681. + }
  71682. +}
  71683. +
  71684. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  71685. +{
  71686. + int retval = 0;
  71687. + if (hcd->frame_list)
  71688. + return 0;
  71689. +
  71690. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  71691. + &hcd->frame_list_dma);
  71692. + if (!hcd->frame_list) {
  71693. + retval = -DWC_E_NO_MEMORY;
  71694. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  71695. + }
  71696. +
  71697. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  71698. +
  71699. + return retval;
  71700. +}
  71701. +
  71702. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  71703. +{
  71704. + if (!hcd->frame_list)
  71705. + return;
  71706. +
  71707. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  71708. + hcd->frame_list = NULL;
  71709. +}
  71710. +
  71711. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  71712. +{
  71713. +
  71714. + hcfg_data_t hcfg;
  71715. +
  71716. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  71717. +
  71718. + if (hcfg.b.perschedena) {
  71719. + /* already enabled */
  71720. + return;
  71721. + }
  71722. +
  71723. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  71724. + hcd->frame_list_dma);
  71725. +
  71726. + switch (fr_list_en) {
  71727. + case 64:
  71728. + hcfg.b.frlisten = 3;
  71729. + break;
  71730. + case 32:
  71731. + hcfg.b.frlisten = 2;
  71732. + break;
  71733. + case 16:
  71734. + hcfg.b.frlisten = 1;
  71735. + break;
  71736. + case 8:
  71737. + hcfg.b.frlisten = 0;
  71738. + break;
  71739. + default:
  71740. + break;
  71741. + }
  71742. +
  71743. + hcfg.b.perschedena = 1;
  71744. +
  71745. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  71746. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  71747. +
  71748. +}
  71749. +
  71750. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  71751. +{
  71752. + hcfg_data_t hcfg;
  71753. +
  71754. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  71755. +
  71756. + if (!hcfg.b.perschedena) {
  71757. + /* already disabled */
  71758. + return;
  71759. + }
  71760. + hcfg.b.perschedena = 0;
  71761. +
  71762. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  71763. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  71764. +}
  71765. +
  71766. +/*
  71767. + * Activates/Deactivates FrameList entries for the channel
  71768. + * based on endpoint servicing period.
  71769. + */
  71770. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  71771. +{
  71772. + uint16_t i, j, inc;
  71773. + dwc_hc_t *hc = NULL;
  71774. +
  71775. + if (!qh->channel) {
  71776. + DWC_ERROR("qh->channel = %p", qh->channel);
  71777. + return;
  71778. + }
  71779. +
  71780. + if (!hcd) {
  71781. + DWC_ERROR("------hcd = %p", hcd);
  71782. + return;
  71783. + }
  71784. +
  71785. + if (!hcd->frame_list) {
  71786. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  71787. + return;
  71788. + }
  71789. +
  71790. + hc = qh->channel;
  71791. + inc = frame_incr_val(qh);
  71792. + if (qh->ep_type == UE_ISOCHRONOUS)
  71793. + i = frame_list_idx(qh->sched_frame);
  71794. + else
  71795. + i = 0;
  71796. +
  71797. + j = i;
  71798. + do {
  71799. + if (enable)
  71800. + hcd->frame_list[j] |= (1 << hc->hc_num);
  71801. + else
  71802. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  71803. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  71804. + }
  71805. + while (j != i);
  71806. + if (!enable)
  71807. + return;
  71808. + hc->schinfo = 0;
  71809. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  71810. + j = 1;
  71811. + /* TODO - check this */
  71812. + inc = (8 + qh->interval - 1) / qh->interval;
  71813. + for (i = 0; i < inc; i++) {
  71814. + hc->schinfo |= j;
  71815. + j = j << qh->interval;
  71816. + }
  71817. + } else {
  71818. + hc->schinfo = 0xff;
  71819. + }
  71820. +}
  71821. +
  71822. +#if 1
  71823. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  71824. +{
  71825. + int i = 0;
  71826. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  71827. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  71828. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  71829. + if (!(i % 8) && i)
  71830. + DWC_PRINTF("\n");
  71831. + }
  71832. + DWC_PRINTF("\n----\n");
  71833. +
  71834. +}
  71835. +#endif
  71836. +
  71837. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71838. +{
  71839. + dwc_irqflags_t flags;
  71840. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  71841. +
  71842. + dwc_hc_t *hc = qh->channel;
  71843. + if (dwc_qh_is_non_per(qh)) {
  71844. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71845. + if (!microframe_schedule)
  71846. + hcd->non_periodic_channels--;
  71847. + else
  71848. + hcd->available_host_channels++;
  71849. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71850. + } else
  71851. + update_frame_list(hcd, qh, 0);
  71852. +
  71853. + /*
  71854. + * The condition is added to prevent double cleanup try in case of device
  71855. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  71856. + */
  71857. + if (hc->qh) {
  71858. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  71859. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  71860. + hc->qh = NULL;
  71861. + }
  71862. +
  71863. + qh->channel = NULL;
  71864. + qh->ntd = 0;
  71865. +
  71866. + if (qh->desc_list) {
  71867. + dwc_memset(qh->desc_list, 0x00,
  71868. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  71869. + }
  71870. +}
  71871. +
  71872. +/**
  71873. + * Initializes a QH structure's Descriptor DMA related members.
  71874. + * Allocates memory for descriptor list.
  71875. + * On first periodic QH, allocates memory for FrameList
  71876. + * and enables periodic scheduling.
  71877. + *
  71878. + * @param hcd The HCD state structure for the DWC OTG controller.
  71879. + * @param qh The QH to init.
  71880. + *
  71881. + * @return 0 if successful, negative error code otherwise.
  71882. + */
  71883. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71884. +{
  71885. + int retval = 0;
  71886. +
  71887. + if (qh->do_split) {
  71888. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  71889. + return -1;
  71890. + }
  71891. +
  71892. + retval = desc_list_alloc(qh);
  71893. +
  71894. + if ((retval == 0)
  71895. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  71896. + if (!hcd->frame_list) {
  71897. + retval = frame_list_alloc(hcd);
  71898. + /* Enable periodic schedule on first periodic QH */
  71899. + if (retval == 0)
  71900. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  71901. + }
  71902. + }
  71903. +
  71904. + qh->ntd = 0;
  71905. +
  71906. + return retval;
  71907. +}
  71908. +
  71909. +/**
  71910. + * Frees descriptor list memory associated with the QH.
  71911. + * If QH is periodic and the last, frees FrameList memory
  71912. + * and disables periodic scheduling.
  71913. + *
  71914. + * @param hcd The HCD state structure for the DWC OTG controller.
  71915. + * @param qh The QH to init.
  71916. + */
  71917. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  71918. +{
  71919. + desc_list_free(qh);
  71920. +
  71921. + /*
  71922. + * Channel still assigned due to some reasons.
  71923. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  71924. + * ChHalted interrupt to release the channel. Afterwards
  71925. + * when it comes here from endpoint disable routine
  71926. + * channel remains assigned.
  71927. + */
  71928. + if (qh->channel)
  71929. + release_channel_ddma(hcd, qh);
  71930. +
  71931. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  71932. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  71933. +
  71934. + per_sched_disable(hcd);
  71935. + frame_list_free(hcd);
  71936. + }
  71937. +}
  71938. +
  71939. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  71940. +{
  71941. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  71942. + /*
  71943. + * Descriptor set(8 descriptors) index
  71944. + * which is 8-aligned.
  71945. + */
  71946. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  71947. + } else {
  71948. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  71949. + }
  71950. +}
  71951. +
  71952. +/*
  71953. + * Determine starting frame for Isochronous transfer.
  71954. + * Few frames skipped to prevent race condition with HC.
  71955. + */
  71956. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  71957. + uint8_t * skip_frames)
  71958. +{
  71959. + uint16_t frame = 0;
  71960. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  71961. +
  71962. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  71963. +
  71964. + /*
  71965. + * skip_frames is used to limit activated descriptors number
  71966. + * to avoid the situation when HC services the last activated
  71967. + * descriptor firstly.
  71968. + * Example for FS:
  71969. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  71970. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  71971. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  71972. + * list will be fully programmed with Active descriptors and it is possible
  71973. + * case(rare) that the latest descriptor(considering rollback) corresponding
  71974. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  71975. + * up to 11 uframes(16 in the code) may be skipped.
  71976. + */
  71977. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  71978. + /*
  71979. + * Consider uframe counter also, to start xfer asap.
  71980. + * If half of the frame elapsed skip 2 frames otherwise
  71981. + * just 1 frame.
  71982. + * Starting descriptor index must be 8-aligned, so
  71983. + * if the current frame is near to complete the next one
  71984. + * is skipped as well.
  71985. + */
  71986. +
  71987. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  71988. + *skip_frames = 2 * 8;
  71989. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  71990. + } else {
  71991. + *skip_frames = 1 * 8;
  71992. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  71993. + }
  71994. +
  71995. + frame = dwc_full_frame_num(frame);
  71996. + } else {
  71997. + /*
  71998. + * Two frames are skipped for FS - the current and the next.
  71999. + * But for descriptor programming, 1 frame(descriptor) is enough,
  72000. + * see example above.
  72001. + */
  72002. + *skip_frames = 1;
  72003. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  72004. + }
  72005. +
  72006. + return frame;
  72007. +}
  72008. +
  72009. +/*
  72010. + * Calculate initial descriptor index for isochronous transfer
  72011. + * based on scheduled frame.
  72012. + */
  72013. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72014. +{
  72015. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  72016. + uint8_t skip_frames = 0;
  72017. + /*
  72018. + * With current ISOC processing algorithm the channel is being
  72019. + * released when no more QTDs in the list(qh->ntd == 0).
  72020. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  72021. + *
  72022. + * So qh->channel != NULL branch is not used and just not removed from the
  72023. + * source file. It is required for another possible approach which is,
  72024. + * do not disable and release the channel when ISOC session completed,
  72025. + * just move QH to inactive schedule until new QTD arrives.
  72026. + * On new QTD, the QH moved back to 'ready' schedule,
  72027. + * starting frame and therefore starting desc_index are recalculated.
  72028. + * In this case channel is released only on ep_disable.
  72029. + */
  72030. +
  72031. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  72032. + if (qh->channel) {
  72033. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  72034. + /*
  72035. + * Calculate initial descriptor index based on FrameList current bitmap
  72036. + * and servicing period.
  72037. + */
  72038. + fr_idx_tmp = frame_list_idx(frame);
  72039. + fr_idx =
  72040. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  72041. + fr_idx_tmp)
  72042. + % frame_incr_val(qh);
  72043. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  72044. + } else {
  72045. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  72046. + fr_idx = frame_list_idx(qh->sched_frame);
  72047. + }
  72048. +
  72049. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  72050. +
  72051. + return skip_frames;
  72052. +}
  72053. +
  72054. +#define ISOC_URB_GIVEBACK_ASAP
  72055. +
  72056. +#define MAX_ISOC_XFER_SIZE_FS 1023
  72057. +#define MAX_ISOC_XFER_SIZE_HS 3072
  72058. +#define DESCNUM_THRESHOLD 4
  72059. +
  72060. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  72061. + uint8_t skip_frames)
  72062. +{
  72063. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72064. + dwc_otg_qtd_t *qtd;
  72065. + dwc_otg_host_dma_desc_t *dma_desc;
  72066. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  72067. +
  72068. + idx = qh->td_last;
  72069. + inc = qh->interval;
  72070. + n_desc = 0;
  72071. +
  72072. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  72073. + if (skip_frames && !qh->channel)
  72074. + ntd_max = ntd_max - skip_frames / qh->interval;
  72075. +
  72076. + max_xfer_size =
  72077. + (qh->dev_speed ==
  72078. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  72079. + MAX_ISOC_XFER_SIZE_FS;
  72080. +
  72081. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  72082. + while ((qh->ntd < ntd_max)
  72083. + && (qtd->isoc_frame_index_last <
  72084. + qtd->urb->packet_count)) {
  72085. +
  72086. + dma_desc = &qh->desc_list[idx];
  72087. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  72088. +
  72089. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  72090. +
  72091. + if (frame_desc->length > max_xfer_size)
  72092. + qh->n_bytes[idx] = max_xfer_size;
  72093. + else
  72094. + qh->n_bytes[idx] = frame_desc->length;
  72095. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  72096. + dma_desc->status.b_isoc.a = 1;
  72097. + dma_desc->status.b_isoc.sts = 0;
  72098. +
  72099. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  72100. +
  72101. + qh->ntd++;
  72102. +
  72103. + qtd->isoc_frame_index_last++;
  72104. +
  72105. +#ifdef ISOC_URB_GIVEBACK_ASAP
  72106. + /*
  72107. + * Set IOC for each descriptor corresponding to the
  72108. + * last frame of the URB.
  72109. + */
  72110. + if (qtd->isoc_frame_index_last ==
  72111. + qtd->urb->packet_count)
  72112. + dma_desc->status.b_isoc.ioc = 1;
  72113. +
  72114. +#endif
  72115. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  72116. + n_desc++;
  72117. +
  72118. + }
  72119. + qtd->in_process = 1;
  72120. + }
  72121. +
  72122. + qh->td_last = idx;
  72123. +
  72124. +#ifdef ISOC_URB_GIVEBACK_ASAP
  72125. + /* Set IOC for the last descriptor if descriptor list is full */
  72126. + if (qh->ntd == ntd_max) {
  72127. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  72128. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  72129. + }
  72130. +#else
  72131. + /*
  72132. + * Set IOC bit only for one descriptor.
  72133. + * Always try to be ahead of HW processing,
  72134. + * i.e. on IOC generation driver activates next descriptors but
  72135. + * core continues to process descriptors followed the one with IOC set.
  72136. + */
  72137. +
  72138. + if (n_desc > DESCNUM_THRESHOLD) {
  72139. + /*
  72140. + * Move IOC "up". Required even if there is only one QTD
  72141. + * in the list, cause QTDs migth continue to be queued,
  72142. + * but during the activation it was only one queued.
  72143. + * Actually more than one QTD might be in the list if this function called
  72144. + * from XferCompletion - QTDs was queued during HW processing of the previous
  72145. + * descriptor chunk.
  72146. + */
  72147. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  72148. + } else {
  72149. + /*
  72150. + * Set the IOC for the latest descriptor
  72151. + * if either number of descriptor is not greather than threshold
  72152. + * or no more new descriptors activated.
  72153. + */
  72154. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  72155. + }
  72156. +
  72157. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  72158. +#endif
  72159. +}
  72160. +
  72161. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72162. +{
  72163. +
  72164. + dwc_hc_t *hc;
  72165. + dwc_otg_host_dma_desc_t *dma_desc;
  72166. + dwc_otg_qtd_t *qtd;
  72167. + int num_packets, len, n_desc = 0;
  72168. +
  72169. + hc = qh->channel;
  72170. +
  72171. + /*
  72172. + * Start with hc->xfer_buff initialized in
  72173. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  72174. + * this pointer re-assigned to the buffer of the currently processed QTD.
  72175. + * For non-SG request there is always one QTD active.
  72176. + */
  72177. +
  72178. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  72179. +
  72180. + if (n_desc) {
  72181. + /* SG request - more than 1 QTDs */
  72182. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  72183. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  72184. + }
  72185. +
  72186. + qtd->n_desc = 0;
  72187. +
  72188. + do {
  72189. + dma_desc = &qh->desc_list[n_desc];
  72190. + len = hc->xfer_len;
  72191. +
  72192. + if (len > MAX_DMA_DESC_SIZE)
  72193. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  72194. +
  72195. + if (hc->ep_is_in) {
  72196. + if (len > 0) {
  72197. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  72198. + } else {
  72199. + /* Need 1 packet for transfer length of 0. */
  72200. + num_packets = 1;
  72201. + }
  72202. + /* Always program an integral # of max packets for IN transfers. */
  72203. + len = num_packets * hc->max_packet;
  72204. + }
  72205. +
  72206. + dma_desc->status.b.n_bytes = len;
  72207. +
  72208. + qh->n_bytes[n_desc] = len;
  72209. +
  72210. + if ((qh->ep_type == UE_CONTROL)
  72211. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  72212. + dma_desc->status.b.sup = 1; /* Setup Packet */
  72213. +
  72214. + dma_desc->status.b.a = 1; /* Active descriptor */
  72215. + dma_desc->status.b.sts = 0;
  72216. +
  72217. + dma_desc->buf =
  72218. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  72219. +
  72220. + /*
  72221. + * Last descriptor(or single) of IN transfer
  72222. + * with actual size less than MaxPacket.
  72223. + */
  72224. + if (len > hc->xfer_len) {
  72225. + hc->xfer_len = 0;
  72226. + } else {
  72227. + hc->xfer_buff += len;
  72228. + hc->xfer_len -= len;
  72229. + }
  72230. +
  72231. + qtd->n_desc++;
  72232. + n_desc++;
  72233. + }
  72234. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  72235. +
  72236. +
  72237. + qtd->in_process = 1;
  72238. +
  72239. + if (qh->ep_type == UE_CONTROL)
  72240. + break;
  72241. +
  72242. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  72243. + break;
  72244. + }
  72245. +
  72246. + if (n_desc) {
  72247. + /* Request Transfer Complete interrupt for the last descriptor */
  72248. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  72249. + /* End of List indicator */
  72250. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  72251. +
  72252. + hc->ntd = n_desc;
  72253. + }
  72254. +}
  72255. +
  72256. +/**
  72257. + * For Control and Bulk endpoints initializes descriptor list
  72258. + * and starts the transfer.
  72259. + *
  72260. + * For Interrupt and Isochronous endpoints initializes descriptor list
  72261. + * then updates FrameList, marking appropriate entries as active.
  72262. + * In case of Isochronous, the starting descriptor index is calculated based
  72263. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  72264. + * Then starts the transfer via enabling the channel.
  72265. + * For Isochronous endpoint the channel is not halted on XferComplete
  72266. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  72267. + *
  72268. + * @param hcd The HCD state structure for the DWC OTG controller.
  72269. + * @param qh The QH to init.
  72270. + *
  72271. + * @return 0 if successful, negative error code otherwise.
  72272. + */
  72273. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  72274. +{
  72275. + /* Channel is already assigned */
  72276. + dwc_hc_t *hc = qh->channel;
  72277. + uint8_t skip_frames = 0;
  72278. +
  72279. + switch (hc->ep_type) {
  72280. + case DWC_OTG_EP_TYPE_CONTROL:
  72281. + case DWC_OTG_EP_TYPE_BULK:
  72282. + init_non_isoc_dma_desc(hcd, qh);
  72283. +
  72284. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72285. + break;
  72286. + case DWC_OTG_EP_TYPE_INTR:
  72287. + init_non_isoc_dma_desc(hcd, qh);
  72288. +
  72289. + update_frame_list(hcd, qh, 1);
  72290. +
  72291. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72292. + break;
  72293. + case DWC_OTG_EP_TYPE_ISOC:
  72294. +
  72295. + if (!qh->ntd)
  72296. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  72297. +
  72298. + init_isoc_dma_desc(hcd, qh, skip_frames);
  72299. +
  72300. + if (!hc->xfer_started) {
  72301. +
  72302. + update_frame_list(hcd, qh, 1);
  72303. +
  72304. + /*
  72305. + * Always set to max, instead of actual size.
  72306. + * Otherwise ntd will be changed with
  72307. + * channel being enabled. Not recommended.
  72308. + *
  72309. + */
  72310. + hc->ntd = max_desc_num(qh);
  72311. + /* Enable channel only once for ISOC */
  72312. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  72313. + }
  72314. +
  72315. + break;
  72316. + default:
  72317. +
  72318. + break;
  72319. + }
  72320. +}
  72321. +
  72322. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  72323. + dwc_hc_t * hc,
  72324. + dwc_otg_hc_regs_t * hc_regs,
  72325. + dwc_otg_halt_status_e halt_status)
  72326. +{
  72327. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  72328. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  72329. + dwc_otg_qh_t *qh;
  72330. + dwc_otg_host_dma_desc_t *dma_desc;
  72331. + uint16_t idx, remain;
  72332. + uint8_t urb_compl;
  72333. +
  72334. + qh = hc->qh;
  72335. + idx = qh->td_first;
  72336. +
  72337. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72338. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  72339. + qtd->in_process = 0;
  72340. + return;
  72341. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  72342. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  72343. + /*
  72344. + * Channel is halted in these error cases.
  72345. + * Considered as serious issues.
  72346. + * Complete all URBs marking all frames as failed,
  72347. + * irrespective whether some of the descriptors(frames) succeeded or no.
  72348. + * Pass error code to completion routine as well, to
  72349. + * update urb->status, some of class drivers might use it to stop
  72350. + * queing transfer requests.
  72351. + */
  72352. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  72353. + ? (-DWC_E_IO)
  72354. + : (-DWC_E_OVERFLOW);
  72355. +
  72356. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72357. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  72358. + frame_desc = &qtd->urb->iso_descs[idx];
  72359. + frame_desc->status = err;
  72360. + }
  72361. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  72362. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72363. + }
  72364. + return;
  72365. + }
  72366. +
  72367. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72368. +
  72369. + if (!qtd->in_process)
  72370. + break;
  72371. +
  72372. + urb_compl = 0;
  72373. +
  72374. + do {
  72375. +
  72376. + dma_desc = &qh->desc_list[idx];
  72377. +
  72378. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  72379. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  72380. +
  72381. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  72382. + /*
  72383. + * XactError or, unable to complete all the transactions
  72384. + * in the scheduled micro-frame/frame,
  72385. + * both indicated by DMA_DESC_STS_PKTERR.
  72386. + */
  72387. + qtd->urb->error_count++;
  72388. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  72389. + frame_desc->status = -DWC_E_PROTOCOL;
  72390. + } else {
  72391. + /* Success */
  72392. +
  72393. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  72394. + frame_desc->status = 0;
  72395. + }
  72396. +
  72397. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  72398. + /*
  72399. + * urb->status is not used for isoc transfers here.
  72400. + * The individual frame_desc status are used instead.
  72401. + */
  72402. +
  72403. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  72404. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72405. +
  72406. + /*
  72407. + * This check is necessary because urb_dequeue can be called
  72408. + * from urb complete callback(sound driver example).
  72409. + * All pending URBs are dequeued there, so no need for
  72410. + * further processing.
  72411. + */
  72412. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72413. + return;
  72414. + }
  72415. +
  72416. + urb_compl = 1;
  72417. +
  72418. + }
  72419. +
  72420. + qh->ntd--;
  72421. +
  72422. + /* Stop if IOC requested descriptor reached */
  72423. + if (dma_desc->status.b_isoc.ioc) {
  72424. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  72425. + goto stop_scan;
  72426. + }
  72427. +
  72428. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  72429. +
  72430. + if (urb_compl)
  72431. + break;
  72432. + }
  72433. + while (idx != qh->td_first);
  72434. + }
  72435. +stop_scan:
  72436. + qh->td_first = idx;
  72437. +}
  72438. +
  72439. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  72440. + dwc_hc_t * hc,
  72441. + dwc_otg_qtd_t * qtd,
  72442. + dwc_otg_host_dma_desc_t * dma_desc,
  72443. + dwc_otg_halt_status_e halt_status,
  72444. + uint32_t n_bytes, uint8_t * xfer_done)
  72445. +{
  72446. +
  72447. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  72448. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  72449. +
  72450. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  72451. + urb->status = -DWC_E_IO;
  72452. + return 1;
  72453. + }
  72454. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  72455. + switch (halt_status) {
  72456. + case DWC_OTG_HC_XFER_STALL:
  72457. + urb->status = -DWC_E_PIPE;
  72458. + break;
  72459. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  72460. + urb->status = -DWC_E_OVERFLOW;
  72461. + break;
  72462. + case DWC_OTG_HC_XFER_XACT_ERR:
  72463. + urb->status = -DWC_E_PROTOCOL;
  72464. + break;
  72465. + default:
  72466. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  72467. + halt_status);
  72468. + break;
  72469. + }
  72470. + return 1;
  72471. + }
  72472. +
  72473. + if (dma_desc->status.b.a == 1) {
  72474. + DWC_DEBUGPL(DBG_HCDV,
  72475. + "Active descriptor encountered on channel %d\n",
  72476. + hc->hc_num);
  72477. + return 0;
  72478. + }
  72479. +
  72480. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  72481. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  72482. + urb->actual_length += n_bytes - remain;
  72483. + if (remain || urb->actual_length == urb->length) {
  72484. + /*
  72485. + * For Control Data stage do not set urb->status=0 to prevent
  72486. + * URB callback. Set it when Status phase done. See below.
  72487. + */
  72488. + *xfer_done = 1;
  72489. + }
  72490. +
  72491. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  72492. + urb->status = 0;
  72493. + *xfer_done = 1;
  72494. + }
  72495. + /* No handling for SETUP stage */
  72496. + } else {
  72497. + /* BULK and INTR */
  72498. + urb->actual_length += n_bytes - remain;
  72499. + if (remain || urb->actual_length == urb->length) {
  72500. + urb->status = 0;
  72501. + *xfer_done = 1;
  72502. + }
  72503. + }
  72504. +
  72505. + return 0;
  72506. +}
  72507. +
  72508. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  72509. + dwc_hc_t * hc,
  72510. + dwc_otg_hc_regs_t * hc_regs,
  72511. + dwc_otg_halt_status_e halt_status)
  72512. +{
  72513. + dwc_otg_hcd_urb_t *urb = NULL;
  72514. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  72515. + dwc_otg_qh_t *qh;
  72516. + dwc_otg_host_dma_desc_t *dma_desc;
  72517. + uint32_t n_bytes, n_desc, i;
  72518. + uint8_t failed = 0, xfer_done;
  72519. +
  72520. + n_desc = 0;
  72521. +
  72522. + qh = hc->qh;
  72523. +
  72524. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  72525. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  72526. + qtd->in_process = 0;
  72527. + }
  72528. + return;
  72529. + }
  72530. +
  72531. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  72532. +
  72533. + urb = qtd->urb;
  72534. +
  72535. + n_bytes = 0;
  72536. + xfer_done = 0;
  72537. +
  72538. + for (i = 0; i < qtd->n_desc; i++) {
  72539. + dma_desc = &qh->desc_list[n_desc];
  72540. +
  72541. + n_bytes = qh->n_bytes[n_desc];
  72542. +
  72543. + failed =
  72544. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  72545. + dma_desc,
  72546. + halt_status, n_bytes,
  72547. + &xfer_done);
  72548. +
  72549. + if (failed
  72550. + || (xfer_done
  72551. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  72552. +
  72553. + hcd->fops->complete(hcd, urb->priv, urb,
  72554. + urb->status);
  72555. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  72556. +
  72557. + if (failed)
  72558. + goto stop_scan;
  72559. + } else if (qh->ep_type == UE_CONTROL) {
  72560. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  72561. + if (urb->length > 0) {
  72562. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  72563. + } else {
  72564. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  72565. + }
  72566. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  72567. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  72568. + if (xfer_done) {
  72569. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  72570. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  72571. + } else if (i + 1 == qtd->n_desc) {
  72572. + /*
  72573. + * Last descriptor for Control data stage which is
  72574. + * not completed yet.
  72575. + */
  72576. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  72577. + }
  72578. + }
  72579. + }
  72580. +
  72581. + n_desc++;
  72582. + }
  72583. +
  72584. + }
  72585. +
  72586. +stop_scan:
  72587. +
  72588. + if (qh->ep_type != UE_CONTROL) {
  72589. + /*
  72590. + * Resetting the data toggle for bulk
  72591. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  72592. + */
  72593. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  72594. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  72595. + else
  72596. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  72597. + }
  72598. +
  72599. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  72600. + hcint_data_t hcint;
  72601. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72602. + if (hcint.b.nyet) {
  72603. + /*
  72604. + * Got a NYET on the last transaction of the transfer. It
  72605. + * means that the endpoint should be in the PING state at the
  72606. + * beginning of the next transfer.
  72607. + */
  72608. + qh->ping_state = 1;
  72609. + clear_hc_int(hc_regs, nyet);
  72610. + }
  72611. +
  72612. + }
  72613. +
  72614. +}
  72615. +
  72616. +/**
  72617. + * This function is called from interrupt handlers.
  72618. + * Scans the descriptor list, updates URB's status and
  72619. + * calls completion routine for the URB if it's done.
  72620. + * Releases the channel to be used by other transfers.
  72621. + * In case of Isochronous endpoint the channel is not halted until
  72622. + * the end of the session, i.e. QTD list is empty.
  72623. + * If periodic channel released the FrameList is updated accordingly.
  72624. + *
  72625. + * Calls transaction selection routines to activate pending transfers.
  72626. + *
  72627. + * @param hcd The HCD state structure for the DWC OTG controller.
  72628. + * @param hc Host channel, the transfer is completed on.
  72629. + * @param hc_regs Host channel registers.
  72630. + * @param halt_status Reason the channel is being halted,
  72631. + * or just XferComplete for isochronous transfer
  72632. + */
  72633. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  72634. + dwc_hc_t * hc,
  72635. + dwc_otg_hc_regs_t * hc_regs,
  72636. + dwc_otg_halt_status_e halt_status)
  72637. +{
  72638. + uint8_t continue_isoc_xfer = 0;
  72639. + dwc_otg_transaction_type_e tr_type;
  72640. + dwc_otg_qh_t *qh = hc->qh;
  72641. +
  72642. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  72643. +
  72644. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  72645. +
  72646. + /* Release the channel if halted or session completed */
  72647. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  72648. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  72649. +
  72650. + /* Halt the channel if session completed */
  72651. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  72652. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  72653. + }
  72654. +
  72655. + release_channel_ddma(hcd, qh);
  72656. + dwc_otg_hcd_qh_remove(hcd, qh);
  72657. + } else {
  72658. + /* Keep in assigned schedule to continue transfer */
  72659. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  72660. + &qh->qh_list_entry);
  72661. + continue_isoc_xfer = 1;
  72662. +
  72663. + }
  72664. + /** @todo Consider the case when period exceeds FrameList size.
  72665. + * Frame Rollover interrupt should be used.
  72666. + */
  72667. + } else {
  72668. + /* Scan descriptor list to complete the URB(s), then release the channel */
  72669. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  72670. +
  72671. + release_channel_ddma(hcd, qh);
  72672. + dwc_otg_hcd_qh_remove(hcd, qh);
  72673. +
  72674. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  72675. + /* Add back to inactive non-periodic schedule on normal completion */
  72676. + dwc_otg_hcd_qh_add(hcd, qh);
  72677. + }
  72678. +
  72679. + }
  72680. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  72681. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  72682. + if (continue_isoc_xfer) {
  72683. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  72684. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  72685. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  72686. + tr_type = DWC_OTG_TRANSACTION_ALL;
  72687. + }
  72688. + }
  72689. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  72690. + }
  72691. +}
  72692. +
  72693. +#endif /* DWC_DEVICE_ONLY */
  72694. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  72695. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  72696. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-02-07 19:57:30.000000000 +0100
  72697. @@ -0,0 +1,851 @@
  72698. +/* ==========================================================================
  72699. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  72700. + * $Revision: #58 $
  72701. + * $Date: 2011/09/15 $
  72702. + * $Change: 1846647 $
  72703. + *
  72704. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  72705. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  72706. + * otherwise expressly agreed to in writing between Synopsys and you.
  72707. + *
  72708. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  72709. + * any End User Software License Agreement or Agreement for Licensed Product
  72710. + * with Synopsys or any supplement thereto. You are permitted to use and
  72711. + * redistribute this Software in source and binary forms, with or without
  72712. + * modification, provided that redistributions of source code must retain this
  72713. + * notice. You may not view, use, disclose, copy or distribute this file or
  72714. + * any information contained herein except pursuant to this license grant from
  72715. + * Synopsys. If you do not agree with this notice, including the disclaimer
  72716. + * below, then you are not authorized to use the Software.
  72717. + *
  72718. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  72719. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  72720. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  72721. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  72722. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  72723. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  72724. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  72725. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72726. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72727. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  72728. + * DAMAGE.
  72729. + * ========================================================================== */
  72730. +#ifndef DWC_DEVICE_ONLY
  72731. +#ifndef __DWC_HCD_H__
  72732. +#define __DWC_HCD_H__
  72733. +
  72734. +#include "dwc_otg_os_dep.h"
  72735. +#include "usb.h"
  72736. +#include "dwc_otg_hcd_if.h"
  72737. +#include "dwc_otg_core_if.h"
  72738. +#include "dwc_list.h"
  72739. +#include "dwc_otg_cil.h"
  72740. +
  72741. +/**
  72742. + * @file
  72743. + *
  72744. + * This file contains the structures, constants, and interfaces for
  72745. + * the Host Contoller Driver (HCD).
  72746. + *
  72747. + * The Host Controller Driver (HCD) is responsible for translating requests
  72748. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  72749. + * It isolates the USBD from the specifics of the controller by providing an
  72750. + * API to the USBD.
  72751. + */
  72752. +
  72753. +struct dwc_otg_hcd_pipe_info {
  72754. + uint8_t dev_addr;
  72755. + uint8_t ep_num;
  72756. + uint8_t pipe_type;
  72757. + uint8_t pipe_dir;
  72758. + uint16_t mps;
  72759. +};
  72760. +
  72761. +struct dwc_otg_hcd_iso_packet_desc {
  72762. + uint32_t offset;
  72763. + uint32_t length;
  72764. + uint32_t actual_length;
  72765. + uint32_t status;
  72766. +};
  72767. +
  72768. +struct dwc_otg_qtd;
  72769. +
  72770. +struct dwc_otg_hcd_urb {
  72771. + void *priv;
  72772. + struct dwc_otg_qtd *qtd;
  72773. + void *buf;
  72774. + dwc_dma_t dma;
  72775. + void *setup_packet;
  72776. + dwc_dma_t setup_dma;
  72777. + uint32_t length;
  72778. + uint32_t actual_length;
  72779. + uint32_t status;
  72780. + uint32_t error_count;
  72781. + uint32_t packet_count;
  72782. + uint32_t flags;
  72783. + uint16_t interval;
  72784. + struct dwc_otg_hcd_pipe_info pipe_info;
  72785. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  72786. +};
  72787. +
  72788. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  72789. +{
  72790. + return pipe->ep_num;
  72791. +}
  72792. +
  72793. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  72794. + *pipe)
  72795. +{
  72796. + return pipe->pipe_type;
  72797. +}
  72798. +
  72799. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  72800. +{
  72801. + return pipe->mps;
  72802. +}
  72803. +
  72804. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  72805. + *pipe)
  72806. +{
  72807. + return pipe->dev_addr;
  72808. +}
  72809. +
  72810. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  72811. + *pipe)
  72812. +{
  72813. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  72814. +}
  72815. +
  72816. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  72817. + *pipe)
  72818. +{
  72819. + return (pipe->pipe_type == UE_INTERRUPT);
  72820. +}
  72821. +
  72822. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  72823. + *pipe)
  72824. +{
  72825. + return (pipe->pipe_type == UE_BULK);
  72826. +}
  72827. +
  72828. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  72829. + *pipe)
  72830. +{
  72831. + return (pipe->pipe_type == UE_CONTROL);
  72832. +}
  72833. +
  72834. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  72835. +{
  72836. + return (pipe->pipe_dir == UE_DIR_IN);
  72837. +}
  72838. +
  72839. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  72840. + *pipe)
  72841. +{
  72842. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  72843. +}
  72844. +
  72845. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  72846. + uint8_t devaddr, uint8_t ep_num,
  72847. + uint8_t pipe_type, uint8_t pipe_dir,
  72848. + uint16_t mps)
  72849. +{
  72850. + pipe->dev_addr = devaddr;
  72851. + pipe->ep_num = ep_num;
  72852. + pipe->pipe_type = pipe_type;
  72853. + pipe->pipe_dir = pipe_dir;
  72854. + pipe->mps = mps;
  72855. +}
  72856. +
  72857. +/**
  72858. + * Phases for control transfers.
  72859. + */
  72860. +typedef enum dwc_otg_control_phase {
  72861. + DWC_OTG_CONTROL_SETUP,
  72862. + DWC_OTG_CONTROL_DATA,
  72863. + DWC_OTG_CONTROL_STATUS
  72864. +} dwc_otg_control_phase_e;
  72865. +
  72866. +/** Transaction types. */
  72867. +typedef enum dwc_otg_transaction_type {
  72868. + DWC_OTG_TRANSACTION_NONE = 0,
  72869. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  72870. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  72871. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  72872. +} dwc_otg_transaction_type_e;
  72873. +
  72874. +struct dwc_otg_qh;
  72875. +
  72876. +/**
  72877. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  72878. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  72879. + * (of one of these types) submitted to the HCD. The transfer associated with
  72880. + * a QTD may require one or multiple transactions.
  72881. + *
  72882. + * A QTD is linked to a Queue Head, which is entered in either the
  72883. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  72884. + * execution, some or all of its transactions may be executed. After
  72885. + * execution, the state of the QTD is updated. The QTD may be retired if all
  72886. + * its transactions are complete or if an error occurred. Otherwise, it
  72887. + * remains in the schedule so more transactions can be executed later.
  72888. + */
  72889. +typedef struct dwc_otg_qtd {
  72890. + /**
  72891. + * Determines the PID of the next data packet for the data phase of
  72892. + * control transfers. Ignored for other transfer types.<br>
  72893. + * One of the following values:
  72894. + * - DWC_OTG_HC_PID_DATA0
  72895. + * - DWC_OTG_HC_PID_DATA1
  72896. + */
  72897. + uint8_t data_toggle;
  72898. +
  72899. + /** Current phase for control transfers (Setup, Data, or Status). */
  72900. + dwc_otg_control_phase_e control_phase;
  72901. +
  72902. + /** Keep track of the current split type
  72903. + * for FS/LS endpoints on a HS Hub */
  72904. + uint8_t complete_split;
  72905. +
  72906. + /** How many bytes transferred during SSPLIT OUT */
  72907. + uint32_t ssplit_out_xfer_count;
  72908. +
  72909. + /**
  72910. + * Holds the number of bus errors that have occurred for a transaction
  72911. + * within this transfer.
  72912. + */
  72913. + uint8_t error_count;
  72914. +
  72915. + /**
  72916. + * Index of the next frame descriptor for an isochronous transfer. A
  72917. + * frame descriptor describes the buffer position and length of the
  72918. + * data to be transferred in the next scheduled (micro)frame of an
  72919. + * isochronous transfer. It also holds status for that transaction.
  72920. + * The frame index starts at 0.
  72921. + */
  72922. + uint16_t isoc_frame_index;
  72923. +
  72924. + /** Position of the ISOC split on full/low speed */
  72925. + uint8_t isoc_split_pos;
  72926. +
  72927. + /** Position of the ISOC split in the buffer for the current frame */
  72928. + uint16_t isoc_split_offset;
  72929. +
  72930. + /** URB for this transfer */
  72931. + struct dwc_otg_hcd_urb *urb;
  72932. +
  72933. + struct dwc_otg_qh *qh;
  72934. +
  72935. + /** This list of QTDs */
  72936. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  72937. +
  72938. + /** Indicates if this QTD is currently processed by HW. */
  72939. + uint8_t in_process;
  72940. +
  72941. + /** Number of DMA descriptors for this QTD */
  72942. + uint8_t n_desc;
  72943. +
  72944. + /**
  72945. + * Last activated frame(packet) index.
  72946. + * Used in Descriptor DMA mode only.
  72947. + */
  72948. + uint16_t isoc_frame_index_last;
  72949. +
  72950. +} dwc_otg_qtd_t;
  72951. +
  72952. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  72953. +
  72954. +/**
  72955. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  72956. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  72957. + * be entered in either the non-periodic or periodic schedule.
  72958. + */
  72959. +typedef struct dwc_otg_qh {
  72960. + /**
  72961. + * Endpoint type.
  72962. + * One of the following values:
  72963. + * - UE_CONTROL
  72964. + * - UE_BULK
  72965. + * - UE_INTERRUPT
  72966. + * - UE_ISOCHRONOUS
  72967. + */
  72968. + uint8_t ep_type;
  72969. + uint8_t ep_is_in;
  72970. +
  72971. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  72972. + uint16_t maxp;
  72973. +
  72974. + /**
  72975. + * Device speed.
  72976. + * One of the following values:
  72977. + * - DWC_OTG_EP_SPEED_LOW
  72978. + * - DWC_OTG_EP_SPEED_FULL
  72979. + * - DWC_OTG_EP_SPEED_HIGH
  72980. + */
  72981. + uint8_t dev_speed;
  72982. +
  72983. + /**
  72984. + * Determines the PID of the next data packet for non-control
  72985. + * transfers. Ignored for control transfers.<br>
  72986. + * One of the following values:
  72987. + * - DWC_OTG_HC_PID_DATA0
  72988. + * - DWC_OTG_HC_PID_DATA1
  72989. + */
  72990. + uint8_t data_toggle;
  72991. +
  72992. + /** Ping state if 1. */
  72993. + uint8_t ping_state;
  72994. +
  72995. + /**
  72996. + * List of QTDs for this QH.
  72997. + */
  72998. + struct dwc_otg_qtd_list qtd_list;
  72999. +
  73000. + /** Host channel currently processing transfers for this QH. */
  73001. + struct dwc_hc *channel;
  73002. +
  73003. + /** Full/low speed endpoint on high-speed hub requires split. */
  73004. + uint8_t do_split;
  73005. +
  73006. + /** @name Periodic schedule information */
  73007. + /** @{ */
  73008. +
  73009. + /** Bandwidth in microseconds per (micro)frame. */
  73010. + uint16_t usecs;
  73011. +
  73012. + /** Interval between transfers in (micro)frames. */
  73013. + uint16_t interval;
  73014. +
  73015. + /**
  73016. + * (micro)frame to initialize a periodic transfer. The transfer
  73017. + * executes in the following (micro)frame.
  73018. + */
  73019. + uint16_t sched_frame;
  73020. +
  73021. + /*
  73022. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  73023. + */
  73024. + uint16_t nak_frame;
  73025. +
  73026. + /** (micro)frame at which last start split was initialized. */
  73027. + uint16_t start_split_frame;
  73028. +
  73029. + /** @} */
  73030. +
  73031. + /**
  73032. + * Used instead of original buffer if
  73033. + * it(physical address) is not dword-aligned.
  73034. + */
  73035. + uint8_t *dw_align_buf;
  73036. + dwc_dma_t dw_align_buf_dma;
  73037. +
  73038. + /** Entry for QH in either the periodic or non-periodic schedule. */
  73039. + dwc_list_link_t qh_list_entry;
  73040. +
  73041. + /** @name Descriptor DMA support */
  73042. + /** @{ */
  73043. +
  73044. + /** Descriptor List. */
  73045. + dwc_otg_host_dma_desc_t *desc_list;
  73046. +
  73047. + /** Descriptor List physical address. */
  73048. + dwc_dma_t desc_list_dma;
  73049. +
  73050. + /**
  73051. + * Xfer Bytes array.
  73052. + * Each element corresponds to a descriptor and indicates
  73053. + * original XferSize size value for the descriptor.
  73054. + */
  73055. + uint32_t *n_bytes;
  73056. +
  73057. + /** Actual number of transfer descriptors in a list. */
  73058. + uint16_t ntd;
  73059. +
  73060. + /** First activated isochronous transfer descriptor index. */
  73061. + uint8_t td_first;
  73062. + /** Last activated isochronous transfer descriptor index. */
  73063. + uint8_t td_last;
  73064. +
  73065. + /** @} */
  73066. +
  73067. +
  73068. + uint16_t speed;
  73069. + uint16_t frame_usecs[8];
  73070. +
  73071. + uint32_t skip_count;
  73072. +} dwc_otg_qh_t;
  73073. +
  73074. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  73075. +
  73076. +typedef struct urb_tq_entry {
  73077. + struct urb *urb;
  73078. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  73079. +} urb_tq_entry_t;
  73080. +
  73081. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  73082. +
  73083. +/**
  73084. + * This structure holds the state of the HCD, including the non-periodic and
  73085. + * periodic schedules.
  73086. + */
  73087. +struct dwc_otg_hcd {
  73088. + /** The DWC otg device pointer */
  73089. + struct dwc_otg_device *otg_dev;
  73090. + /** DWC OTG Core Interface Layer */
  73091. + dwc_otg_core_if_t *core_if;
  73092. +
  73093. + /** Function HCD driver callbacks */
  73094. + struct dwc_otg_hcd_function_ops *fops;
  73095. +
  73096. + /** Internal DWC HCD Flags */
  73097. + volatile union dwc_otg_hcd_internal_flags {
  73098. + uint32_t d32;
  73099. + struct {
  73100. + unsigned port_connect_status_change:1;
  73101. + unsigned port_connect_status:1;
  73102. + unsigned port_reset_change:1;
  73103. + unsigned port_enable_change:1;
  73104. + unsigned port_suspend_change:1;
  73105. + unsigned port_over_current_change:1;
  73106. + unsigned port_l1_change:1;
  73107. + unsigned reserved:26;
  73108. + } b;
  73109. + } flags;
  73110. +
  73111. + /**
  73112. + * Inactive items in the non-periodic schedule. This is a list of
  73113. + * Queue Heads. Transfers associated with these Queue Heads are not
  73114. + * currently assigned to a host channel.
  73115. + */
  73116. + dwc_list_link_t non_periodic_sched_inactive;
  73117. +
  73118. + /**
  73119. + * Active items in the non-periodic schedule. This is a list of
  73120. + * Queue Heads. Transfers associated with these Queue Heads are
  73121. + * currently assigned to a host channel.
  73122. + */
  73123. + dwc_list_link_t non_periodic_sched_active;
  73124. +
  73125. + /**
  73126. + * Pointer to the next Queue Head to process in the active
  73127. + * non-periodic schedule.
  73128. + */
  73129. + dwc_list_link_t *non_periodic_qh_ptr;
  73130. +
  73131. + /**
  73132. + * Inactive items in the periodic schedule. This is a list of QHs for
  73133. + * periodic transfers that are _not_ scheduled for the next frame.
  73134. + * Each QH in the list has an interval counter that determines when it
  73135. + * needs to be scheduled for execution. This scheduling mechanism
  73136. + * allows only a simple calculation for periodic bandwidth used (i.e.
  73137. + * must assume that all periodic transfers may need to execute in the
  73138. + * same frame). However, it greatly simplifies scheduling and should
  73139. + * be sufficient for the vast majority of OTG hosts, which need to
  73140. + * connect to a small number of peripherals at one time.
  73141. + *
  73142. + * Items move from this list to periodic_sched_ready when the QH
  73143. + * interval counter is 0 at SOF.
  73144. + */
  73145. + dwc_list_link_t periodic_sched_inactive;
  73146. +
  73147. + /**
  73148. + * List of periodic QHs that are ready for execution in the next
  73149. + * frame, but have not yet been assigned to host channels.
  73150. + *
  73151. + * Items move from this list to periodic_sched_assigned as host
  73152. + * channels become available during the current frame.
  73153. + */
  73154. + dwc_list_link_t periodic_sched_ready;
  73155. +
  73156. + /**
  73157. + * List of periodic QHs to be executed in the next frame that are
  73158. + * assigned to host channels.
  73159. + *
  73160. + * Items move from this list to periodic_sched_queued as the
  73161. + * transactions for the QH are queued to the DWC_otg controller.
  73162. + */
  73163. + dwc_list_link_t periodic_sched_assigned;
  73164. +
  73165. + /**
  73166. + * List of periodic QHs that have been queued for execution.
  73167. + *
  73168. + * Items move from this list to either periodic_sched_inactive or
  73169. + * periodic_sched_ready when the channel associated with the transfer
  73170. + * is released. If the interval for the QH is 1, the item moves to
  73171. + * periodic_sched_ready because it must be rescheduled for the next
  73172. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  73173. + */
  73174. + dwc_list_link_t periodic_sched_queued;
  73175. +
  73176. + /**
  73177. + * Total bandwidth claimed so far for periodic transfers. This value
  73178. + * is in microseconds per (micro)frame. The assumption is that all
  73179. + * periodic transfers may occur in the same (micro)frame.
  73180. + */
  73181. + uint16_t periodic_usecs;
  73182. +
  73183. + /**
  73184. + * Total bandwidth claimed so far for all periodic transfers
  73185. + * in a frame.
  73186. + * This will include a mixture of HS and FS transfers.
  73187. + * Units are microseconds per (micro)frame.
  73188. + * We have a budget per frame and have to schedule
  73189. + * transactions accordingly.
  73190. + * Watch out for the fact that things are actually scheduled for the
  73191. + * "next frame".
  73192. + */
  73193. + uint16_t frame_usecs[8];
  73194. +
  73195. +
  73196. + /**
  73197. + * Frame number read from the core at SOF. The value ranges from 0 to
  73198. + * DWC_HFNUM_MAX_FRNUM.
  73199. + */
  73200. + uint16_t frame_number;
  73201. +
  73202. + /**
  73203. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  73204. + */
  73205. + uint16_t periodic_qh_count;
  73206. +
  73207. + /**
  73208. + * Free host channels in the controller. This is a list of
  73209. + * dwc_hc_t items.
  73210. + */
  73211. + struct hc_list free_hc_list;
  73212. + /**
  73213. + * Number of host channels assigned to periodic transfers. Currently
  73214. + * assuming that there is a dedicated host channel for each periodic
  73215. + * transaction and at least one host channel available for
  73216. + * non-periodic transactions.
  73217. + */
  73218. + int periodic_channels; /* microframe_schedule==0 */
  73219. +
  73220. + /**
  73221. + * Number of host channels assigned to non-periodic transfers.
  73222. + */
  73223. + int non_periodic_channels; /* microframe_schedule==0 */
  73224. +
  73225. + /**
  73226. + * Number of host channels assigned to non-periodic transfers.
  73227. + */
  73228. + int available_host_channels;
  73229. +
  73230. + /**
  73231. + * Array of pointers to the host channel descriptors. Allows accessing
  73232. + * a host channel descriptor given the host channel number. This is
  73233. + * useful in interrupt handlers.
  73234. + */
  73235. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  73236. +
  73237. + /**
  73238. + * Buffer to use for any data received during the status phase of a
  73239. + * control transfer. Normally no data is transferred during the status
  73240. + * phase. This buffer is used as a bit bucket.
  73241. + */
  73242. + uint8_t *status_buf;
  73243. +
  73244. + /**
  73245. + * DMA address for status_buf.
  73246. + */
  73247. + dma_addr_t status_buf_dma;
  73248. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  73249. +
  73250. + /**
  73251. + * Connection timer. An OTG host must display a message if the device
  73252. + * does not connect. Started when the VBus power is turned on via
  73253. + * sysfs attribute "buspower".
  73254. + */
  73255. + dwc_timer_t *conn_timer;
  73256. +
  73257. + /* Tasket to do a reset */
  73258. + dwc_tasklet_t *reset_tasklet;
  73259. +
  73260. + dwc_tasklet_t *completion_tasklet;
  73261. + struct urb_list completed_urb_list;
  73262. +
  73263. + /* */
  73264. + dwc_spinlock_t *lock;
  73265. + dwc_spinlock_t *channel_lock;
  73266. + /**
  73267. + * Private data that could be used by OS wrapper.
  73268. + */
  73269. + void *priv;
  73270. +
  73271. + uint8_t otg_port;
  73272. +
  73273. + /** Frame List */
  73274. + uint32_t *frame_list;
  73275. +
  73276. + /** Hub - Port assignment */
  73277. + int hub_port[128];
  73278. +#ifdef FIQ_DEBUG
  73279. + int hub_port_alloc[2048];
  73280. +#endif
  73281. +
  73282. + /** Frame List DMA address */
  73283. + dma_addr_t frame_list_dma;
  73284. +
  73285. +#ifdef DEBUG
  73286. + uint32_t frrem_samples;
  73287. + uint64_t frrem_accum;
  73288. +
  73289. + uint32_t hfnum_7_samples_a;
  73290. + uint64_t hfnum_7_frrem_accum_a;
  73291. + uint32_t hfnum_0_samples_a;
  73292. + uint64_t hfnum_0_frrem_accum_a;
  73293. + uint32_t hfnum_other_samples_a;
  73294. + uint64_t hfnum_other_frrem_accum_a;
  73295. +
  73296. + uint32_t hfnum_7_samples_b;
  73297. + uint64_t hfnum_7_frrem_accum_b;
  73298. + uint32_t hfnum_0_samples_b;
  73299. + uint64_t hfnum_0_frrem_accum_b;
  73300. + uint32_t hfnum_other_samples_b;
  73301. + uint64_t hfnum_other_frrem_accum_b;
  73302. +#endif
  73303. +};
  73304. +
  73305. +/** @name Transaction Execution Functions */
  73306. +/** @{ */
  73307. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  73308. + * hcd);
  73309. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  73310. + dwc_otg_transaction_type_e tr_type);
  73311. +
  73312. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  73313. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  73314. +
  73315. +
  73316. +/** @} */
  73317. +
  73318. +/** @name Interrupt Handler Functions */
  73319. +/** @{ */
  73320. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73321. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73322. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  73323. + dwc_otg_hcd);
  73324. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  73325. + dwc_otg_hcd);
  73326. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  73327. + dwc_otg_hcd);
  73328. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  73329. + dwc_otg_hcd);
  73330. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73331. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  73332. + dwc_otg_hcd);
  73333. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73334. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73335. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  73336. + uint32_t num);
  73337. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73338. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  73339. + dwc_otg_hcd);
  73340. +/** @} */
  73341. +
  73342. +/** @name Schedule Queue Functions */
  73343. +/** @{ */
  73344. +
  73345. +/* Implemented in dwc_otg_hcd_queue.c */
  73346. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  73347. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  73348. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73349. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73350. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73351. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  73352. + int sched_csplit);
  73353. +
  73354. +/** Remove and free a QH */
  73355. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  73356. + dwc_otg_qh_t * qh)
  73357. +{
  73358. + dwc_irqflags_t flags;
  73359. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  73360. + dwc_otg_hcd_qh_remove(hcd, qh);
  73361. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  73362. + dwc_otg_hcd_qh_free(hcd, qh);
  73363. +}
  73364. +
  73365. +/** Allocates memory for a QH structure.
  73366. + * @return Returns the memory allocate or NULL on error. */
  73367. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  73368. +{
  73369. + if (atomic_alloc)
  73370. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  73371. + else
  73372. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  73373. +}
  73374. +
  73375. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  73376. + int atomic_alloc);
  73377. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  73378. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  73379. + dwc_otg_qh_t ** qh, int atomic_alloc);
  73380. +
  73381. +/** Allocates memory for a QTD structure.
  73382. + * @return Returns the memory allocate or NULL on error. */
  73383. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  73384. +{
  73385. + if (atomic_alloc)
  73386. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  73387. + else
  73388. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  73389. +}
  73390. +
  73391. +/** Frees the memory for a QTD structure. QTD should already be removed from
  73392. + * list.
  73393. + * @param qtd QTD to free.*/
  73394. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  73395. +{
  73396. + DWC_FREE(qtd);
  73397. +}
  73398. +
  73399. +/** Removes a QTD from list.
  73400. + * @param hcd HCD instance.
  73401. + * @param qtd QTD to remove from list.
  73402. + * @param qh QTD belongs to.
  73403. + */
  73404. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  73405. + dwc_otg_qtd_t * qtd,
  73406. + dwc_otg_qh_t * qh)
  73407. +{
  73408. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  73409. +}
  73410. +
  73411. +/** Remove and free a QTD
  73412. + * Need to disable IRQ and hold hcd lock while calling this function out of
  73413. + * interrupt servicing chain */
  73414. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  73415. + dwc_otg_qtd_t * qtd,
  73416. + dwc_otg_qh_t * qh)
  73417. +{
  73418. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  73419. + dwc_otg_hcd_qtd_free(qtd);
  73420. +}
  73421. +
  73422. +/** @} */
  73423. +
  73424. +/** @name Descriptor DMA Supporting Functions */
  73425. +/** @{ */
  73426. +
  73427. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73428. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  73429. + dwc_hc_t * hc,
  73430. + dwc_otg_hc_regs_t * hc_regs,
  73431. + dwc_otg_halt_status_e halt_status);
  73432. +
  73433. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73434. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  73435. +
  73436. +/** @} */
  73437. +
  73438. +/** @name Internal Functions */
  73439. +/** @{ */
  73440. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  73441. +/** @} */
  73442. +
  73443. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73444. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  73445. + uint8_t devaddr);
  73446. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  73447. +#endif
  73448. +
  73449. +/** Gets the QH that contains the list_head */
  73450. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  73451. +
  73452. +/** Gets the QTD that contains the list_head */
  73453. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  73454. +
  73455. +/** Check if QH is non-periodic */
  73456. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  73457. + (_qh_ptr_->ep_type == UE_CONTROL))
  73458. +
  73459. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  73460. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  73461. +
  73462. +/** Packet size for any kind of endpoint descriptor */
  73463. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  73464. +
  73465. +/**
  73466. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  73467. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  73468. + * frame number when the max frame number is reached.
  73469. + */
  73470. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  73471. +{
  73472. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  73473. + (DWC_HFNUM_MAX_FRNUM >> 1);
  73474. +}
  73475. +
  73476. +/**
  73477. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  73478. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  73479. + * number when the max frame number is reached.
  73480. + */
  73481. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  73482. +{
  73483. + return (frame1 != frame2) &&
  73484. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  73485. + (DWC_HFNUM_MAX_FRNUM >> 1));
  73486. +}
  73487. +
  73488. +/**
  73489. + * Increments _frame by the amount specified by _inc. The addition is done
  73490. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  73491. + */
  73492. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  73493. +{
  73494. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  73495. +}
  73496. +
  73497. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  73498. +{
  73499. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  73500. +}
  73501. +
  73502. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  73503. +{
  73504. + return frame & 0x7;
  73505. +}
  73506. +
  73507. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  73508. + dwc_otg_hc_regs_t * hc_regs,
  73509. + dwc_otg_qtd_t * qtd);
  73510. +
  73511. +#ifdef DEBUG
  73512. +/**
  73513. + * Macro to sample the remaining PHY clocks left in the current frame. This
  73514. + * may be used during debugging to determine the average time it takes to
  73515. + * execute sections of code. There are two possible sample points, "a" and
  73516. + * "b", so the _letter argument must be one of these values.
  73517. + *
  73518. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  73519. + * example, "cat /sys/devices/lm0/hcd_frrem".
  73520. + */
  73521. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  73522. +{ \
  73523. + hfnum_data_t hfnum; \
  73524. + dwc_otg_qtd_t *qtd; \
  73525. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  73526. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  73527. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  73528. + switch (hfnum.b.frnum & 0x7) { \
  73529. + case 7: \
  73530. + _hcd->hfnum_7_samples_##_letter++; \
  73531. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  73532. + break; \
  73533. + case 0: \
  73534. + _hcd->hfnum_0_samples_##_letter++; \
  73535. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  73536. + break; \
  73537. + default: \
  73538. + _hcd->hfnum_other_samples_##_letter++; \
  73539. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  73540. + break; \
  73541. + } \
  73542. + } \
  73543. +}
  73544. +#else
  73545. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  73546. +#endif
  73547. +#endif
  73548. +#endif /* DWC_DEVICE_ONLY */
  73549. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  73550. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  73551. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-02-07 19:57:30.000000000 +0100
  73552. @@ -0,0 +1,417 @@
  73553. +/* ==========================================================================
  73554. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  73555. + * $Revision: #12 $
  73556. + * $Date: 2011/10/26 $
  73557. + * $Change: 1873028 $
  73558. + *
  73559. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73560. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73561. + * otherwise expressly agreed to in writing between Synopsys and you.
  73562. + *
  73563. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73564. + * any End User Software License Agreement or Agreement for Licensed Product
  73565. + * with Synopsys or any supplement thereto. You are permitted to use and
  73566. + * redistribute this Software in source and binary forms, with or without
  73567. + * modification, provided that redistributions of source code must retain this
  73568. + * notice. You may not view, use, disclose, copy or distribute this file or
  73569. + * any information contained herein except pursuant to this license grant from
  73570. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73571. + * below, then you are not authorized to use the Software.
  73572. + *
  73573. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73574. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73575. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73576. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73577. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73578. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73579. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73580. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73581. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73582. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73583. + * DAMAGE.
  73584. + * ========================================================================== */
  73585. +#ifndef DWC_DEVICE_ONLY
  73586. +#ifndef __DWC_HCD_IF_H__
  73587. +#define __DWC_HCD_IF_H__
  73588. +
  73589. +#include "dwc_otg_core_if.h"
  73590. +
  73591. +/** @file
  73592. + * This file defines DWC_OTG HCD Core API.
  73593. + */
  73594. +
  73595. +struct dwc_otg_hcd;
  73596. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  73597. +
  73598. +struct dwc_otg_hcd_urb;
  73599. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  73600. +
  73601. +/** @name HCD Function Driver Callbacks */
  73602. +/** @{ */
  73603. +
  73604. +/** This function is called whenever core switches to host mode. */
  73605. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  73606. +
  73607. +/** This function is called when device has been disconnected */
  73608. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  73609. +
  73610. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  73611. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  73612. + void *urb_handle,
  73613. + uint32_t * hub_addr,
  73614. + uint32_t * port_addr);
  73615. +/** Via this function HCD core gets device speed */
  73616. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  73617. + void *urb_handle);
  73618. +
  73619. +/** This function is called when urb is completed */
  73620. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  73621. + void *urb_handle,
  73622. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  73623. + int32_t status);
  73624. +
  73625. +/** Via this function HCD core gets b_hnp_enable parameter */
  73626. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  73627. +
  73628. +struct dwc_otg_hcd_function_ops {
  73629. + dwc_otg_hcd_start_cb_t start;
  73630. + dwc_otg_hcd_disconnect_cb_t disconnect;
  73631. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  73632. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  73633. + dwc_otg_hcd_complete_urb_cb_t complete;
  73634. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  73635. +};
  73636. +/** @} */
  73637. +
  73638. +/** @name HCD Core API */
  73639. +/** @{ */
  73640. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  73641. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  73642. +
  73643. +/** This function should be called to initiate HCD Core.
  73644. + *
  73645. + * @param hcd The HCD
  73646. + * @param core_if The DWC_OTG Core
  73647. + *
  73648. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  73649. + * Returns 0 on success
  73650. + */
  73651. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  73652. +
  73653. +/** Frees HCD
  73654. + *
  73655. + * @param hcd The HCD
  73656. + */
  73657. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  73658. +
  73659. +/** This function should be called on every hardware interrupt.
  73660. + *
  73661. + * @param dwc_otg_hcd The HCD
  73662. + *
  73663. + * Returns non zero if interrupt is handled
  73664. + * Return 0 if interrupt is not handled
  73665. + */
  73666. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  73667. +
  73668. +/** This function is used to handle the fast interrupt
  73669. + *
  73670. + */
  73671. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  73672. +
  73673. +/**
  73674. + * Returns private data set by
  73675. + * dwc_otg_hcd_set_priv_data function.
  73676. + *
  73677. + * @param hcd The HCD
  73678. + */
  73679. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  73680. +
  73681. +/**
  73682. + * Set private data.
  73683. + *
  73684. + * @param hcd The HCD
  73685. + * @param priv_data pointer to be stored in private data
  73686. + */
  73687. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  73688. +
  73689. +/**
  73690. + * This function initializes the HCD Core.
  73691. + *
  73692. + * @param hcd The HCD
  73693. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  73694. + *
  73695. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  73696. + * Returns 0 on success
  73697. + */
  73698. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  73699. + struct dwc_otg_hcd_function_ops *fops);
  73700. +
  73701. +/**
  73702. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  73703. + * stopped.
  73704. + *
  73705. + * @param hcd The HCD
  73706. + */
  73707. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  73708. +
  73709. +/**
  73710. + * Handles hub class-specific requests.
  73711. + *
  73712. + * @param dwc_otg_hcd The HCD
  73713. + * @param typeReq Request Type
  73714. + * @param wValue wValue from control request
  73715. + * @param wIndex wIndex from control request
  73716. + * @param buf data buffer
  73717. + * @param wLength data buffer length
  73718. + *
  73719. + * Returns -DWC_E_INVALID if invalid argument is passed
  73720. + * Returns 0 on success
  73721. + */
  73722. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  73723. + uint16_t typeReq, uint16_t wValue,
  73724. + uint16_t wIndex, uint8_t * buf,
  73725. + uint16_t wLength);
  73726. +
  73727. +/**
  73728. + * Returns otg port number.
  73729. + *
  73730. + * @param hcd The HCD
  73731. + */
  73732. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  73733. +
  73734. +/**
  73735. + * Returns OTG version - either 1.3 or 2.0.
  73736. + *
  73737. + * @param core_if The core_if structure pointer
  73738. + */
  73739. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  73740. +
  73741. +/**
  73742. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  73743. + *
  73744. + * @param hcd The HCD
  73745. + */
  73746. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  73747. +
  73748. +/**
  73749. + * Returns current frame number.
  73750. + *
  73751. + * @param hcd The HCD
  73752. + */
  73753. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  73754. +
  73755. +/**
  73756. + * Dumps hcd state.
  73757. + *
  73758. + * @param hcd The HCD
  73759. + */
  73760. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  73761. +
  73762. +/**
  73763. + * Dump the average frame remaining at SOF. This can be used to
  73764. + * determine average interrupt latency. Frame remaining is also shown for
  73765. + * start transfer and two additional sample points.
  73766. + * Currently this function is not implemented.
  73767. + *
  73768. + * @param hcd The HCD
  73769. + */
  73770. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  73771. +
  73772. +/**
  73773. + * Sends LPM transaction to the local device.
  73774. + *
  73775. + * @param hcd The HCD
  73776. + * @param devaddr Device Address
  73777. + * @param hird Host initiated resume duration
  73778. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  73779. + *
  73780. + * Returns negative value if sending LPM transaction was not succeeded.
  73781. + * Returns 0 on success.
  73782. + */
  73783. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  73784. + uint8_t hird, uint8_t bRemoteWake);
  73785. +
  73786. +/* URB interface */
  73787. +
  73788. +/**
  73789. + * Allocates memory for dwc_otg_hcd_urb structure.
  73790. + * Allocated memory should be freed by call of DWC_FREE.
  73791. + *
  73792. + * @param hcd The HCD
  73793. + * @param iso_desc_count Count of ISOC descriptors
  73794. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  73795. + */
  73796. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  73797. + int iso_desc_count,
  73798. + int atomic_alloc);
  73799. +
  73800. +/**
  73801. + * Set pipe information in URB.
  73802. + *
  73803. + * @param hcd_urb DWC_OTG URB
  73804. + * @param devaddr Device Address
  73805. + * @param ep_num Endpoint Number
  73806. + * @param ep_type Endpoint Type
  73807. + * @param ep_dir Endpoint Direction
  73808. + * @param mps Max Packet Size
  73809. + */
  73810. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  73811. + uint8_t devaddr, uint8_t ep_num,
  73812. + uint8_t ep_type, uint8_t ep_dir,
  73813. + uint16_t mps);
  73814. +
  73815. +/* Transfer flags */
  73816. +#define URB_GIVEBACK_ASAP 0x1
  73817. +#define URB_SEND_ZERO_PACKET 0x2
  73818. +
  73819. +/**
  73820. + * Sets dwc_otg_hcd_urb parameters.
  73821. + *
  73822. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  73823. + * @param urb_handle Unique handle for request, this will be passed back
  73824. + * to function driver in completion callback.
  73825. + * @param buf The buffer for the data
  73826. + * @param dma The DMA buffer for the data
  73827. + * @param buflen Transfer length
  73828. + * @param sp Buffer for setup data
  73829. + * @param sp_dma DMA address of setup data buffer
  73830. + * @param flags Transfer flags
  73831. + * @param interval Polling interval for interrupt or isochronous transfers.
  73832. + */
  73833. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  73834. + void *urb_handle, void *buf,
  73835. + dwc_dma_t dma, uint32_t buflen, void *sp,
  73836. + dwc_dma_t sp_dma, uint32_t flags,
  73837. + uint16_t interval);
  73838. +
  73839. +/** Gets status from dwc_otg_hcd_urb
  73840. + *
  73841. + * @param dwc_otg_urb DWC_OTG URB
  73842. + */
  73843. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  73844. +
  73845. +/** Gets actual length from dwc_otg_hcd_urb
  73846. + *
  73847. + * @param dwc_otg_urb DWC_OTG URB
  73848. + */
  73849. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  73850. + dwc_otg_urb);
  73851. +
  73852. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  73853. + *
  73854. + * @param dwc_otg_urb DWC_OTG URB
  73855. + */
  73856. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  73857. + dwc_otg_urb);
  73858. +
  73859. +/** Set ISOC descriptor offset and length
  73860. + *
  73861. + * @param dwc_otg_urb DWC_OTG URB
  73862. + * @param desc_num ISOC descriptor number
  73863. + * @param offset Offset from beginig of buffer.
  73864. + * @param length Transaction length
  73865. + */
  73866. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73867. + int desc_num, uint32_t offset,
  73868. + uint32_t length);
  73869. +
  73870. +/** Get status of ISOC descriptor, specified by desc_num
  73871. + *
  73872. + * @param dwc_otg_urb DWC_OTG URB
  73873. + * @param desc_num ISOC descriptor number
  73874. + */
  73875. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  73876. + dwc_otg_urb, int desc_num);
  73877. +
  73878. +/** Get actual length of ISOC descriptor, specified by desc_num
  73879. + *
  73880. + * @param dwc_otg_urb DWC_OTG URB
  73881. + * @param desc_num ISOC descriptor number
  73882. + */
  73883. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  73884. + dwc_otg_urb,
  73885. + int desc_num);
  73886. +
  73887. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  73888. + *
  73889. + * @param dwc_otg_hcd The HCD
  73890. + * @param dwc_otg_urb DWC_OTG URB
  73891. + * @param ep_handle Out parameter for returning endpoint handle
  73892. + * @param atomic_alloc Flag to do atomic allocation if needed
  73893. + *
  73894. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  73895. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  73896. + * Returns 0 on success.
  73897. + */
  73898. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  73899. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  73900. + void **ep_handle, int atomic_alloc);
  73901. +
  73902. +/** De-queue the specified URB
  73903. + *
  73904. + * @param dwc_otg_hcd The HCD
  73905. + * @param dwc_otg_urb DWC_OTG URB
  73906. + */
  73907. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  73908. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  73909. +
  73910. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  73911. + * Any URBs for the endpoint must already be dequeued.
  73912. + *
  73913. + * @param hcd The HCD
  73914. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  73915. + * @param retry Number of retries if there are queued transfers.
  73916. + *
  73917. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  73918. + * Returns 0 on success
  73919. + */
  73920. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  73921. + int retry);
  73922. +
  73923. +/* Resets the data toggle in qh structure. This function can be called from
  73924. + * usb_clear_halt routine.
  73925. + *
  73926. + * @param hcd The HCD
  73927. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  73928. + *
  73929. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  73930. + * Returns 0 on success
  73931. + */
  73932. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  73933. +
  73934. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  73935. + *
  73936. + * @param hcd The HCD
  73937. + * @param port Port number
  73938. + */
  73939. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  73940. +
  73941. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  73942. + * Only for ISOC and INTERRUPT endpoints.
  73943. + *
  73944. + * @param hcd The HCD
  73945. + * @param ep_handle Endpoint handle
  73946. + */
  73947. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  73948. + void *ep_handle);
  73949. +
  73950. +/** Call this function to check if bandwidth was freed for specified endpoint.
  73951. + *
  73952. + * @param hcd The HCD
  73953. + * @param ep_handle Endpoint handle
  73954. + */
  73955. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  73956. +
  73957. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  73958. + * Only for ISOC and INTERRUPT endpoints.
  73959. + *
  73960. + * @param hcd The HCD
  73961. + * @param ep_handle Endpoint handle
  73962. + */
  73963. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  73964. + void *ep_handle);
  73965. +
  73966. +/** @} */
  73967. +
  73968. +#endif /* __DWC_HCD_IF_H__ */
  73969. +#endif /* DWC_DEVICE_ONLY */
  73970. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  73971. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  73972. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-02-07 19:57:30.000000000 +0100
  73973. @@ -0,0 +1,2741 @@
  73974. +/* ==========================================================================
  73975. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  73976. + * $Revision: #89 $
  73977. + * $Date: 2011/10/20 $
  73978. + * $Change: 1869487 $
  73979. + *
  73980. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73981. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73982. + * otherwise expressly agreed to in writing between Synopsys and you.
  73983. + *
  73984. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73985. + * any End User Software License Agreement or Agreement for Licensed Product
  73986. + * with Synopsys or any supplement thereto. You are permitted to use and
  73987. + * redistribute this Software in source and binary forms, with or without
  73988. + * modification, provided that redistributions of source code must retain this
  73989. + * notice. You may not view, use, disclose, copy or distribute this file or
  73990. + * any information contained herein except pursuant to this license grant from
  73991. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73992. + * below, then you are not authorized to use the Software.
  73993. + *
  73994. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73995. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73996. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73997. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73998. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73999. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74000. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74001. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74002. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74003. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74004. + * DAMAGE.
  74005. + * ========================================================================== */
  74006. +#ifndef DWC_DEVICE_ONLY
  74007. +
  74008. +#include "dwc_otg_hcd.h"
  74009. +#include "dwc_otg_regs.h"
  74010. +#include "dwc_otg_mphi_fix.h"
  74011. +
  74012. +#include <linux/jiffies.h>
  74013. +#include <mach/hardware.h>
  74014. +#include <asm/fiq.h>
  74015. +
  74016. +
  74017. +extern bool microframe_schedule;
  74018. +
  74019. +/** @file
  74020. + * This file contains the implementation of the HCD Interrupt handlers.
  74021. + */
  74022. +
  74023. +/*
  74024. + * Some globals to communicate between the FIQ and INTERRUPT
  74025. + */
  74026. +
  74027. +void * dummy_send;
  74028. +mphi_regs_t c_mphi_regs;
  74029. +volatile void *dwc_regs_base;
  74030. +int fiq_done, int_done;
  74031. +
  74032. +gintsts_data_t gintsts_saved = {.d32 = 0};
  74033. +hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  74034. +hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  74035. +int split_out_xfersize[MAX_EPS_CHANNELS];
  74036. +haint_data_t haint_saved;
  74037. +
  74038. +int g_next_sched_frame, g_np_count, g_np_sent;
  74039. +static int mphi_int_count = 0 ;
  74040. +
  74041. +hcchar_data_t nak_hcchar;
  74042. +hctsiz_data_t nak_hctsiz;
  74043. +hcsplt_data_t nak_hcsplt;
  74044. +int nak_count;
  74045. +
  74046. +int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  74047. +int split_start_frame[MAX_EPS_CHANNELS];
  74048. +int queued_port[MAX_EPS_CHANNELS];
  74049. +
  74050. +#ifdef FIQ_DEBUG
  74051. +char buffer[1000*16];
  74052. +int wptr;
  74053. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  74054. +{
  74055. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  74056. + va_list args;
  74057. + char text[17];
  74058. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  74059. + unsigned long flags;
  74060. +
  74061. + local_irq_save(flags);
  74062. + local_fiq_disable();
  74063. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  74064. + {
  74065. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  74066. + va_start(args, fmt);
  74067. + vsnprintf(text+8, 9, fmt, args);
  74068. + va_end(args);
  74069. +
  74070. + memcpy(buffer + wptr, text, 16);
  74071. + wptr = (wptr + 16) % sizeof(buffer);
  74072. + }
  74073. + local_irq_restore(flags);
  74074. +}
  74075. +#endif
  74076. +
  74077. +void notrace fiq_queue_request(int channel, int odd_frame)
  74078. +{
  74079. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  74080. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  74081. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
  74082. +
  74083. + if(hcsplt.b.spltena == 0)
  74084. + {
  74085. + fiq_print(FIQDBG_ERR, "SPLTENA ");
  74086. + BUG();
  74087. + }
  74088. +
  74089. + if(hcchar.b.epdir == 1)
  74090. + {
  74091. + fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
  74092. + }
  74093. + else
  74094. + {
  74095. + hctsiz.b.xfersize = 0;
  74096. + fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
  74097. + }
  74098. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
  74099. +
  74100. + hcsplt.b.compsplt = 1;
  74101. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
  74102. +
  74103. + // Send the Split complete
  74104. + hcchar.b.chen = 1;
  74105. + hcchar.b.oddfrm = odd_frame ? 1 : 0;
  74106. +
  74107. + // Post this for transmit on the next frame for periodic or this frame for non-periodic
  74108. + fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
  74109. +
  74110. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
  74111. +}
  74112. +
  74113. +static int last_sof = -1;
  74114. +
  74115. +/*
  74116. +** Function to handle the start of frame interrupt, choose whether we need to do anything and
  74117. +** therefore trigger the main interrupt
  74118. +**
  74119. +** returns int != 0 - interrupt has been handled
  74120. +*/
  74121. +int diff;
  74122. +
  74123. +int notrace fiq_sof_handle(hfnum_data_t hfnum)
  74124. +{
  74125. + int handled = 0;
  74126. + int i;
  74127. +
  74128. + // Just check that once we're running we don't miss a SOF
  74129. + /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
  74130. + {
  74131. + fiq_print(FIQDBG_ERR, "LASTSOF ");
  74132. + fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
  74133. + fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
  74134. + BUG();
  74135. + }*/
  74136. +
  74137. + // Only start remembering the last sof when the interrupt has been
  74138. + // enabled (we don't check the mask to come in here...)
  74139. + if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
  74140. + last_sof = hfnum.b.frnum;
  74141. +
  74142. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  74143. + {
  74144. + if(complete_sched[i] != -1)
  74145. + {
  74146. + if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
  74147. + {
  74148. + fiq_queue_request(i, hfnum.b.frnum & 1);
  74149. + complete_sched[i] = -1;
  74150. + }
  74151. + }
  74152. +
  74153. + if(complete_sched[i] != -1)
  74154. + {
  74155. + // This is because we've seen a split complete occur with no start...
  74156. + // most likely because missed the complete 0x3fff frames ago!
  74157. +
  74158. + diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
  74159. + if(diff > 32 && diff < 0x3f00)
  74160. + {
  74161. + fiq_print(FIQDBG_ERR, "SPLTMISS");
  74162. + BUG();
  74163. + }
  74164. + }
  74165. + }
  74166. +
  74167. + if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  74168. + {
  74169. + /*
  74170. + * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
  74171. + * g_next_sched_frame is the next frame we have periodic packets for
  74172. + *
  74173. + * if neither of these are required for this frame then just clear the interrupt
  74174. + */
  74175. + handled = 1;
  74176. +
  74177. + }
  74178. +
  74179. + return handled;
  74180. +}
  74181. +
  74182. +int notrace port_id(hcsplt_data_t hcsplt)
  74183. +{
  74184. + return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
  74185. +}
  74186. +
  74187. +int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
  74188. +{
  74189. + hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  74190. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  74191. + hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
  74192. + hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
  74193. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
  74194. +
  74195. + hcint_saved[channel].d32 |= hcint.d32;
  74196. + hcintmsk_saved[channel].d32 = hcintmsk.d32;
  74197. +
  74198. + if(hcsplt.b.spltena)
  74199. + {
  74200. + fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
  74201. + if(hcint.b.chhltd)
  74202. + {
  74203. + fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
  74204. + fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
  74205. + }
  74206. + if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
  74207. + {
  74208. + queued_port[channel] = 0;
  74209. + fiq_print(FIQDBG_ERR, "CHAN ERR");
  74210. + }
  74211. + if(hcint.b.xfercomp)
  74212. + {
  74213. + // Clear the port allocation and transmit anything also on this port
  74214. + queued_port[channel] = 0;
  74215. + fiq_print(FIQDBG_SCHED, "XFERCOMP");
  74216. + }
  74217. + if(hcint.b.nak)
  74218. + {
  74219. + queued_port[channel] = 0;
  74220. + fiq_print(FIQDBG_SCHED, "NAK");
  74221. + }
  74222. + if(hcint.b.ack && !hcsplt.b.compsplt)
  74223. + {
  74224. + int i;
  74225. +
  74226. + // Do not complete isochronous out transactions
  74227. + if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
  74228. + {
  74229. + queued_port[channel] = 0;
  74230. + fiq_print(FIQDBG_SCHED, "ISOC_OUT");
  74231. + }
  74232. + else
  74233. + {
  74234. + // Make sure we check the port / hub combination that we sent this split on.
  74235. + // Do not queue a second request to the same port
  74236. + for(i = 0; i < MAX_EPS_CHANNELS; i++)
  74237. + {
  74238. + if(port_id(hcsplt) == queued_port[i])
  74239. + {
  74240. + fiq_print(FIQDBG_ERR, "PORTERR ");
  74241. + //BUG();
  74242. + }
  74243. + }
  74244. +
  74245. + split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
  74246. +
  74247. + // Note, the size of an OUT is in the start split phase, not
  74248. + // the complete split
  74249. + split_out_xfersize[channel] = hctsiz.b.xfersize;
  74250. +
  74251. + hcint_saved[channel].b.chhltd = 0;
  74252. + hcint_saved[channel].b.ack = 0;
  74253. +
  74254. + queued_port[channel] = port_id(hcsplt);
  74255. +
  74256. + if(hcchar.b.eptype & 1)
  74257. + {
  74258. + // Send the periodic complete in the same oddness frame as the ACK went...
  74259. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  74260. + // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  74261. + }
  74262. + else
  74263. + {
  74264. + // Schedule the split complete to occur later
  74265. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
  74266. + fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  74267. + }
  74268. + }
  74269. + }
  74270. + if(hcint.b.nyet)
  74271. + {
  74272. + fiq_print(FIQDBG_ERR, "NYETERR1");
  74273. + //BUG();
  74274. + // Can transmit a split complete up to uframe .0 of the next frame
  74275. + if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
  74276. + {
  74277. + // Send it next frame
  74278. + if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
  74279. + {
  74280. + fiq_print(FIQDBG_SCHED, "NYT:SEND");
  74281. + fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  74282. + }
  74283. + else
  74284. + {
  74285. + // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
  74286. + complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  74287. + fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  74288. + }
  74289. + hcint_saved[channel].b.chhltd = 0;
  74290. + hcint_saved[channel].b.nyet = 0;
  74291. + }
  74292. + else
  74293. + {
  74294. + queued_port[channel] = 0;
  74295. + fiq_print(FIQDBG_ERR, "NYETERR2");
  74296. + //BUG();
  74297. + }
  74298. + }
  74299. + }
  74300. + else
  74301. + {
  74302. + /*
  74303. + * If we have any of NAK, ACK, Datatlgerr active on a
  74304. + * non-split channel, the sole reason is to reset error
  74305. + * counts for a previously broken transaction. The FIQ
  74306. + * will thrash on NAK IN and ACK OUT in particular so
  74307. + * handle it "once" and allow the IRQ to do the rest.
  74308. + */
  74309. + hcint.d32 &= hcintmsk.d32;
  74310. + if(hcint.b.nak)
  74311. + {
  74312. + hcintmsk.b.nak = 0;
  74313. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  74314. + }
  74315. + if (hcint.b.ack)
  74316. + {
  74317. + hcintmsk.b.ack = 0;
  74318. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  74319. + }
  74320. + }
  74321. +
  74322. + // Clear the interrupt, this will also clear the HAINT bit
  74323. + FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
  74324. + return hcint_saved[channel].d32 == 0;
  74325. +}
  74326. +
  74327. +gintsts_data_t gintsts;
  74328. +gintmsk_data_t gintmsk;
  74329. +// triggered: The set of interrupts that were triggered
  74330. +// handled: The set of interrupts that have been handled (no IRQ is
  74331. +// required)
  74332. +// keep: The set of interrupts we want to keep unmasked even though we
  74333. +// want to trigger an IRQ to handle it (SOF and HCINTR)
  74334. +gintsts_data_t triggered, handled, keep;
  74335. +hfnum_data_t hfnum;
  74336. +
  74337. +void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
  74338. +{
  74339. +
  74340. + /* entry takes care to store registers we will be treading on here */
  74341. + asm __volatile__ (
  74342. + "mov ip, sp ;"
  74343. + /* stash FIQ and normal regs */
  74344. + "stmdb sp!, {r0-r12, lr};"
  74345. + /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
  74346. + "sub fp, ip, #512 ;"
  74347. + );
  74348. +
  74349. + // Cannot put local variables at the beginning of the function
  74350. + // because otherwise 'C' will play with the stack pointer. any locals
  74351. + // need to be inside the following block
  74352. + do
  74353. + {
  74354. + fiq_done++;
  74355. + gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
  74356. + gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
  74357. + hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
  74358. + triggered.d32 = gintsts.d32 & gintmsk.d32;
  74359. + handled.d32 = 0;
  74360. + keep.d32 = 0;
  74361. + fiq_print(FIQDBG_INT, "FIQ ");
  74362. + fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
  74363. + fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
  74364. + if(gintsts.d32)
  74365. + {
  74366. + // If port enabled
  74367. + if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
  74368. + {
  74369. + if(gintsts.b.sofintr)
  74370. + {
  74371. + if(fiq_sof_handle(hfnum))
  74372. + {
  74373. + handled.b.sofintr = 1; /* Handled in FIQ */
  74374. + }
  74375. + else
  74376. + {
  74377. + /* Keer interrupt unmasked */
  74378. + keep.b.sofintr = 1;
  74379. + }
  74380. + {
  74381. + // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
  74382. + // a start of frame interrupt
  74383. + gintsts_data_t gintsts = { .b.sofintr = 1 };
  74384. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  74385. + }
  74386. + }
  74387. +
  74388. + if(fiq_split_enable && gintsts.b.hcintr)
  74389. + {
  74390. + int i;
  74391. + haint_data_t haint;
  74392. + haintmsk_data_t haintmsk;
  74393. +
  74394. + haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
  74395. + haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
  74396. + haint.d32 &= haintmsk.d32;
  74397. + haint_saved.d32 |= haint.d32;
  74398. +
  74399. + fiq_print(FIQDBG_INT, "hcintr");
  74400. + fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
  74401. +
  74402. + // Go through each channel that has an enabled interrupt
  74403. + for(i = 0; i < 16; i++)
  74404. + if((haint.d32 >> i) & 1)
  74405. + if(fiq_hcintr_handle(i, hfnum))
  74406. + haint_saved.d32 &= ~(1 << i); /* this was handled */
  74407. +
  74408. + /* If we've handled all host channel interrupts then don't trigger the interrupt */
  74409. + if(haint_saved.d32 == 0)
  74410. + {
  74411. + handled.b.hcintr = 1;
  74412. + }
  74413. + else
  74414. + {
  74415. + /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
  74416. + keep.b.hcintr = 1;
  74417. + }
  74418. +
  74419. + {
  74420. + gintsts_data_t gintsts = { .b.hcintr = 1 };
  74421. +
  74422. + // Always clear the channel interrupt
  74423. + FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  74424. + }
  74425. + }
  74426. + }
  74427. + else
  74428. + {
  74429. + last_sof = -1;
  74430. + }
  74431. + }
  74432. +
  74433. + // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
  74434. + gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
  74435. + // Save those that were triggered but not handled
  74436. + gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
  74437. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  74438. +
  74439. + // Clear and save any unhandled interrupts and trigger the interrupt
  74440. + if(gintsts_saved.d32)
  74441. + {
  74442. + /* To enable the MPHI interrupt (INT 32)
  74443. + */
  74444. + FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
  74445. + FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
  74446. +
  74447. + mphi_int_count++;
  74448. + }
  74449. + }
  74450. + while(0);
  74451. +
  74452. + mb();
  74453. +
  74454. + /* exit back to normal mode restoring everything */
  74455. + asm __volatile__ (
  74456. + /* return FIQ regs back to pristine state
  74457. + * and get normal regs back
  74458. + */
  74459. + "ldmia sp!, {r0-r12, lr};"
  74460. +
  74461. + /* return */
  74462. + "subs pc, lr, #4;"
  74463. + );
  74464. +}
  74465. +
  74466. +/** This function handles interrupts for the HCD. */
  74467. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74468. +{
  74469. + int retval = 0;
  74470. + static int last_time;
  74471. +
  74472. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  74473. + gintsts_data_t gintsts;
  74474. + gintmsk_data_t gintmsk;
  74475. + hfnum_data_t hfnum;
  74476. +
  74477. +#ifdef DEBUG
  74478. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  74479. +
  74480. +#endif
  74481. +
  74482. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  74483. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  74484. +
  74485. + /* Exit from ISR if core is hibernated */
  74486. + if (core_if->hibernation_suspend == 1) {
  74487. + goto exit_handler_routine;
  74488. + }
  74489. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  74490. + /* Check if HOST Mode */
  74491. + if (dwc_otg_is_host_mode(core_if)) {
  74492. + local_fiq_disable();
  74493. + gintmsk.d32 |= gintsts_saved.d32;
  74494. + gintsts.d32 |= gintsts_saved.d32;
  74495. + gintsts_saved.d32 = 0;
  74496. + local_fiq_enable();
  74497. + if (!gintsts.d32) {
  74498. + goto exit_handler_routine;
  74499. + }
  74500. + gintsts.d32 &= gintmsk.d32;
  74501. +
  74502. +#ifdef DEBUG
  74503. + // We should be OK doing this because the common interrupts should already have been serviced
  74504. + /* Don't print debug message in the interrupt handler on SOF */
  74505. +#ifndef DEBUG_SOF
  74506. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74507. +#endif
  74508. + DWC_DEBUGPL(DBG_HCDI, "\n");
  74509. +#endif
  74510. +
  74511. +#ifdef DEBUG
  74512. +#ifndef DEBUG_SOF
  74513. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74514. +#endif
  74515. + DWC_DEBUGPL(DBG_HCDI,
  74516. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  74517. + gintsts.d32, core_if);
  74518. +#endif
  74519. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  74520. + if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  74521. + {
  74522. + /* Note, we should never get here if the FIQ is doing it's job properly*/
  74523. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  74524. + }
  74525. + else if (gintsts.b.sofintr) {
  74526. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  74527. + }
  74528. +
  74529. + if (gintsts.b.rxstsqlvl) {
  74530. + retval |=
  74531. + dwc_otg_hcd_handle_rx_status_q_level_intr
  74532. + (dwc_otg_hcd);
  74533. + }
  74534. + if (gintsts.b.nptxfempty) {
  74535. + retval |=
  74536. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  74537. + (dwc_otg_hcd);
  74538. + }
  74539. + if (gintsts.b.i2cintr) {
  74540. + /** @todo Implement i2cintr handler. */
  74541. + }
  74542. + if (gintsts.b.portintr) {
  74543. +
  74544. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  74545. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  74546. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  74547. + }
  74548. + if (gintsts.b.hcintr) {
  74549. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  74550. + }
  74551. + if (gintsts.b.ptxfempty) {
  74552. + retval |=
  74553. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  74554. + (dwc_otg_hcd);
  74555. + }
  74556. +#ifdef DEBUG
  74557. +#ifndef DEBUG_SOF
  74558. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74559. +#endif
  74560. + {
  74561. + DWC_DEBUGPL(DBG_HCDI,
  74562. + "DWC OTG HCD Finished Servicing Interrupts\n");
  74563. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  74564. + DWC_READ_REG32(&global_regs->gintsts));
  74565. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  74566. + DWC_READ_REG32(&global_regs->gintmsk));
  74567. + }
  74568. +#endif
  74569. +
  74570. +#ifdef DEBUG
  74571. +#ifndef DEBUG_SOF
  74572. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  74573. +#endif
  74574. + DWC_DEBUGPL(DBG_HCDI, "\n");
  74575. +#endif
  74576. +
  74577. + }
  74578. +
  74579. +exit_handler_routine:
  74580. +
  74581. + if (fiq_fix_enable)
  74582. + {
  74583. + local_fiq_disable();
  74584. + // Make sure that we don't clear the interrupt if we've still got pending work to do
  74585. + if(gintsts_saved.d32 == 0)
  74586. + {
  74587. + /* Clear the MPHI interrupt */
  74588. + DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
  74589. + if (mphi_int_count >= 60)
  74590. + {
  74591. + DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
  74592. + while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
  74593. + ;
  74594. + DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
  74595. + mphi_int_count = 0;
  74596. + }
  74597. + int_done++;
  74598. + }
  74599. +
  74600. + // Unmask handled interrupts
  74601. + FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  74602. + //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
  74603. +
  74604. + local_fiq_enable();
  74605. +
  74606. + if((jiffies / HZ) > last_time)
  74607. + {
  74608. + /* Once a second output the fiq and irq numbers, useful for debug */
  74609. + last_time = jiffies / HZ;
  74610. + DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
  74611. + }
  74612. + }
  74613. +
  74614. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  74615. + return retval;
  74616. +}
  74617. +
  74618. +#ifdef DWC_TRACK_MISSED_SOFS
  74619. +
  74620. +#warning Compiling code to track missed SOFs
  74621. +#define FRAME_NUM_ARRAY_SIZE 1000
  74622. +/**
  74623. + * This function is for debug only.
  74624. + */
  74625. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  74626. +{
  74627. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  74628. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  74629. + static int frame_num_idx = 0;
  74630. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  74631. + static int dumped_frame_num_array = 0;
  74632. +
  74633. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  74634. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  74635. + curr_frame_number) {
  74636. + frame_num_array[frame_num_idx] = curr_frame_number;
  74637. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  74638. + }
  74639. + } else if (!dumped_frame_num_array) {
  74640. + int i;
  74641. + DWC_PRINTF("Frame Last Frame\n");
  74642. + DWC_PRINTF("----- ----------\n");
  74643. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  74644. + DWC_PRINTF("0x%04x 0x%04x\n",
  74645. + frame_num_array[i], last_frame_num_array[i]);
  74646. + }
  74647. + dumped_frame_num_array = 1;
  74648. + }
  74649. + last_frame_num = curr_frame_number;
  74650. +}
  74651. +#endif
  74652. +
  74653. +/**
  74654. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  74655. + * transactions may be queued to the DWC_otg controller for the current
  74656. + * (micro)frame. Periodic transactions may be queued to the controller for the
  74657. + * next (micro)frame.
  74658. + */
  74659. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  74660. +{
  74661. + hfnum_data_t hfnum;
  74662. + dwc_list_link_t *qh_entry;
  74663. + dwc_otg_qh_t *qh;
  74664. + dwc_otg_transaction_type_e tr_type;
  74665. + int did_something = 0;
  74666. + int32_t next_sched_frame = -1;
  74667. +
  74668. + hfnum.d32 =
  74669. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  74670. +
  74671. +#ifdef DEBUG_SOF
  74672. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  74673. +#endif
  74674. + hcd->frame_number = hfnum.b.frnum;
  74675. +
  74676. +#ifdef DEBUG
  74677. + hcd->frrem_accum += hfnum.b.frrem;
  74678. + hcd->frrem_samples++;
  74679. +#endif
  74680. +
  74681. +#ifdef DWC_TRACK_MISSED_SOFS
  74682. + track_missed_sofs(hcd->frame_number);
  74683. +#endif
  74684. + /* Determine whether any periodic QHs should be executed. */
  74685. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  74686. + while (qh_entry != &hcd->periodic_sched_inactive) {
  74687. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  74688. + qh_entry = qh_entry->next;
  74689. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  74690. +
  74691. + /*
  74692. + * Move QH to the ready list to be executed next
  74693. + * (micro)frame.
  74694. + */
  74695. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  74696. + &qh->qh_list_entry);
  74697. +
  74698. + did_something = 1;
  74699. + }
  74700. + else
  74701. + {
  74702. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  74703. + {
  74704. + next_sched_frame = qh->sched_frame;
  74705. + }
  74706. + }
  74707. + }
  74708. +
  74709. + g_next_sched_frame = next_sched_frame;
  74710. +
  74711. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  74712. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  74713. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  74714. + did_something = 1;
  74715. + }
  74716. +
  74717. + /* Clear interrupt */
  74718. + gintsts.b.sofintr = 1;
  74719. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  74720. +
  74721. + return 1;
  74722. +}
  74723. +
  74724. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  74725. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  74726. + * memory if the DWC_otg controller is operating in Slave mode. */
  74727. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74728. +{
  74729. + host_grxsts_data_t grxsts;
  74730. + dwc_hc_t *hc = NULL;
  74731. +
  74732. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  74733. +
  74734. + grxsts.d32 =
  74735. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  74736. +
  74737. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  74738. + if (!hc) {
  74739. + DWC_ERROR("Unable to get corresponding channel\n");
  74740. + return 0;
  74741. + }
  74742. +
  74743. + /* Packet Status */
  74744. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  74745. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  74746. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  74747. + hc->data_pid_start);
  74748. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  74749. +
  74750. + switch (grxsts.b.pktsts) {
  74751. + case DWC_GRXSTS_PKTSTS_IN:
  74752. + /* Read the data into the host buffer. */
  74753. + if (grxsts.b.bcnt > 0) {
  74754. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  74755. + hc->xfer_buff, grxsts.b.bcnt);
  74756. +
  74757. + /* Update the HC fields for the next packet received. */
  74758. + hc->xfer_count += grxsts.b.bcnt;
  74759. + hc->xfer_buff += grxsts.b.bcnt;
  74760. + }
  74761. +
  74762. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  74763. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  74764. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  74765. + /* Handled in interrupt, just ignore data */
  74766. + break;
  74767. + default:
  74768. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  74769. + grxsts.b.pktsts);
  74770. + break;
  74771. + }
  74772. +
  74773. + return 1;
  74774. +}
  74775. +
  74776. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  74777. + * data packets may be written to the FIFO for OUT transfers. More requests
  74778. + * may be written to the non-periodic request queue for IN transfers. This
  74779. + * interrupt is enabled only in Slave mode. */
  74780. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74781. +{
  74782. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  74783. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  74784. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  74785. + return 1;
  74786. +}
  74787. +
  74788. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  74789. + * packets may be written to the FIFO for OUT transfers. More requests may be
  74790. + * written to the periodic request queue for IN transfers. This interrupt is
  74791. + * enabled only in Slave mode. */
  74792. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74793. +{
  74794. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  74795. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  74796. + DWC_OTG_TRANSACTION_PERIODIC);
  74797. + return 1;
  74798. +}
  74799. +
  74800. +/** There are multiple conditions that can cause a port interrupt. This function
  74801. + * determines which interrupt conditions have occurred and handles them
  74802. + * appropriately. */
  74803. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74804. +{
  74805. + int retval = 0;
  74806. + hprt0_data_t hprt0;
  74807. + hprt0_data_t hprt0_modify;
  74808. +
  74809. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74810. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74811. +
  74812. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  74813. + * GINTSTS */
  74814. +
  74815. + hprt0_modify.b.prtena = 0;
  74816. + hprt0_modify.b.prtconndet = 0;
  74817. + hprt0_modify.b.prtenchng = 0;
  74818. + hprt0_modify.b.prtovrcurrchng = 0;
  74819. +
  74820. + /* Port Connect Detected
  74821. + * Set flag and clear if detected */
  74822. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  74823. + // Dont modify port status if we are in hibernation state
  74824. + hprt0_modify.b.prtconndet = 1;
  74825. + hprt0_modify.b.prtenchng = 1;
  74826. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  74827. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  74828. + return retval;
  74829. + }
  74830. +
  74831. + if (hprt0.b.prtconndet) {
  74832. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  74833. + if (dwc_otg_hcd->core_if->adp_enable &&
  74834. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  74835. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  74836. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  74837. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  74838. + /* TODO - check if this is required, as
  74839. + * host initialization was already performed
  74840. + * after initial ADP probing
  74841. + */
  74842. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  74843. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  74844. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  74845. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  74846. + } else {
  74847. +
  74848. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  74849. + "Port Connect Detected--\n", hprt0.d32);
  74850. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  74851. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  74852. + hprt0_modify.b.prtconndet = 1;
  74853. +
  74854. + /* B-Device has connected, Delete the connection timer. */
  74855. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  74856. + }
  74857. + /* The Hub driver asserts a reset when it sees port connect
  74858. + * status change flag */
  74859. + retval |= 1;
  74860. + }
  74861. +
  74862. + /* Port Enable Changed
  74863. + * Clear if detected - Set internal flag if disabled */
  74864. + if (hprt0.b.prtenchng) {
  74865. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  74866. + "Port Enable Changed--\n", hprt0.d32);
  74867. + hprt0_modify.b.prtenchng = 1;
  74868. + if (hprt0.b.prtena == 1) {
  74869. + hfir_data_t hfir;
  74870. + int do_reset = 0;
  74871. + dwc_otg_core_params_t *params =
  74872. + dwc_otg_hcd->core_if->core_params;
  74873. + dwc_otg_core_global_regs_t *global_regs =
  74874. + dwc_otg_hcd->core_if->core_global_regs;
  74875. + dwc_otg_host_if_t *host_if =
  74876. + dwc_otg_hcd->core_if->host_if;
  74877. +
  74878. + /* Every time when port enables calculate
  74879. + * HFIR.FrInterval
  74880. + */
  74881. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  74882. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  74883. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  74884. +
  74885. + /* Check if we need to adjust the PHY clock speed for
  74886. + * low power and adjust it */
  74887. + if (params->host_support_fs_ls_low_power) {
  74888. + gusbcfg_data_t usbcfg;
  74889. +
  74890. + usbcfg.d32 =
  74891. + DWC_READ_REG32(&global_regs->gusbcfg);
  74892. +
  74893. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  74894. + || hprt0.b.prtspd ==
  74895. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  74896. + /*
  74897. + * Low power
  74898. + */
  74899. + hcfg_data_t hcfg;
  74900. + if (usbcfg.b.phylpwrclksel == 0) {
  74901. + /* Set PHY low power clock select for FS/LS devices */
  74902. + usbcfg.b.phylpwrclksel = 1;
  74903. + DWC_WRITE_REG32
  74904. + (&global_regs->gusbcfg,
  74905. + usbcfg.d32);
  74906. + do_reset = 1;
  74907. + }
  74908. +
  74909. + hcfg.d32 =
  74910. + DWC_READ_REG32
  74911. + (&host_if->host_global_regs->hcfg);
  74912. +
  74913. + if (hprt0.b.prtspd ==
  74914. + DWC_HPRT0_PRTSPD_LOW_SPEED
  74915. + && params->host_ls_low_power_phy_clk
  74916. + ==
  74917. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  74918. + {
  74919. + /* 6 MHZ */
  74920. + DWC_DEBUGPL(DBG_CIL,
  74921. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  74922. + if (hcfg.b.fslspclksel !=
  74923. + DWC_HCFG_6_MHZ) {
  74924. + hcfg.b.fslspclksel =
  74925. + DWC_HCFG_6_MHZ;
  74926. + DWC_WRITE_REG32
  74927. + (&host_if->host_global_regs->hcfg,
  74928. + hcfg.d32);
  74929. + do_reset = 1;
  74930. + }
  74931. + } else {
  74932. + /* 48 MHZ */
  74933. + DWC_DEBUGPL(DBG_CIL,
  74934. + "FS_PHY programming HCFG to 48 MHz ()\n");
  74935. + if (hcfg.b.fslspclksel !=
  74936. + DWC_HCFG_48_MHZ) {
  74937. + hcfg.b.fslspclksel =
  74938. + DWC_HCFG_48_MHZ;
  74939. + DWC_WRITE_REG32
  74940. + (&host_if->host_global_regs->hcfg,
  74941. + hcfg.d32);
  74942. + do_reset = 1;
  74943. + }
  74944. + }
  74945. + } else {
  74946. + /*
  74947. + * Not low power
  74948. + */
  74949. + if (usbcfg.b.phylpwrclksel == 1) {
  74950. + usbcfg.b.phylpwrclksel = 0;
  74951. + DWC_WRITE_REG32
  74952. + (&global_regs->gusbcfg,
  74953. + usbcfg.d32);
  74954. + do_reset = 1;
  74955. + }
  74956. + }
  74957. +
  74958. + if (do_reset) {
  74959. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  74960. + }
  74961. + }
  74962. +
  74963. + if (!do_reset) {
  74964. + /* Port has been enabled set the reset change flag */
  74965. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  74966. + }
  74967. + } else {
  74968. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  74969. + }
  74970. + retval |= 1;
  74971. + }
  74972. +
  74973. + /** Overcurrent Change Interrupt */
  74974. + if (hprt0.b.prtovrcurrchng) {
  74975. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  74976. + "Port Overcurrent Changed--\n", hprt0.d32);
  74977. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  74978. + hprt0_modify.b.prtovrcurrchng = 1;
  74979. + retval |= 1;
  74980. + }
  74981. +
  74982. + /* Clear Port Interrupts */
  74983. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  74984. +
  74985. + return retval;
  74986. +}
  74987. +
  74988. +/** This interrupt indicates that one or more host channels has a pending
  74989. + * interrupt. There are multiple conditions that can cause each host channel
  74990. + * interrupt. This function determines which conditions have occurred for each
  74991. + * host channel interrupt and handles them appropriately. */
  74992. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  74993. +{
  74994. + int i;
  74995. + int retval = 0;
  74996. + haint_data_t haint;
  74997. +
  74998. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  74999. + * GINTSTS */
  75000. +
  75001. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  75002. +
  75003. + // Overwrite with saved interrupts from fiq handler
  75004. + if(fiq_split_enable)
  75005. + {
  75006. + local_fiq_disable();
  75007. + haint.d32 = haint_saved.d32;
  75008. + haint_saved.d32 = 0;
  75009. + local_fiq_enable();
  75010. + }
  75011. +
  75012. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  75013. + if (haint.b2.chint & (1 << i)) {
  75014. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  75015. + }
  75016. + }
  75017. +
  75018. + return retval;
  75019. +}
  75020. +
  75021. +/**
  75022. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  75023. + * holds the reason for the halt.
  75024. + *
  75025. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  75026. + * *short_read is set to 1 upon return if less than the requested
  75027. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  75028. + * return. short_read may also be NULL on entry, in which case it remains
  75029. + * unchanged.
  75030. + */
  75031. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  75032. + dwc_otg_hc_regs_t * hc_regs,
  75033. + dwc_otg_qtd_t * qtd,
  75034. + dwc_otg_halt_status_e halt_status,
  75035. + int *short_read)
  75036. +{
  75037. + hctsiz_data_t hctsiz;
  75038. + uint32_t length;
  75039. +
  75040. + if (short_read != NULL) {
  75041. + *short_read = 0;
  75042. + }
  75043. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75044. +
  75045. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  75046. + if (hc->ep_is_in) {
  75047. + length = hc->xfer_len - hctsiz.b.xfersize;
  75048. + if (short_read != NULL) {
  75049. + *short_read = (hctsiz.b.xfersize != 0);
  75050. + }
  75051. + } else if (hc->qh->do_split) {
  75052. + if(fiq_split_enable)
  75053. + length = split_out_xfersize[hc->hc_num];
  75054. + else
  75055. + length = qtd->ssplit_out_xfer_count;
  75056. + } else {
  75057. + length = hc->xfer_len;
  75058. + }
  75059. + } else {
  75060. + /*
  75061. + * Must use the hctsiz.pktcnt field to determine how much data
  75062. + * has been transferred. This field reflects the number of
  75063. + * packets that have been transferred via the USB. This is
  75064. + * always an integral number of packets if the transfer was
  75065. + * halted before its normal completion. (Can't use the
  75066. + * hctsiz.xfersize field because that reflects the number of
  75067. + * bytes transferred via the AHB, not the USB).
  75068. + */
  75069. + length =
  75070. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  75071. + }
  75072. +
  75073. + return length;
  75074. +}
  75075. +
  75076. +/**
  75077. + * Updates the state of the URB after a Transfer Complete interrupt on the
  75078. + * host channel. Updates the actual_length field of the URB based on the
  75079. + * number of bytes transferred via the host channel. Sets the URB status
  75080. + * if the data transfer is finished.
  75081. + *
  75082. + * @return 1 if the data transfer specified by the URB is completely finished,
  75083. + * 0 otherwise.
  75084. + */
  75085. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  75086. + dwc_otg_hc_regs_t * hc_regs,
  75087. + dwc_otg_hcd_urb_t * urb,
  75088. + dwc_otg_qtd_t * qtd)
  75089. +{
  75090. + int xfer_done = 0;
  75091. + int short_read = 0;
  75092. +
  75093. + int xfer_length;
  75094. +
  75095. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  75096. + DWC_OTG_HC_XFER_COMPLETE,
  75097. + &short_read);
  75098. +
  75099. + /* non DWORD-aligned buffer case handling. */
  75100. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  75101. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  75102. + xfer_length);
  75103. + }
  75104. +
  75105. + urb->actual_length += xfer_length;
  75106. +
  75107. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  75108. + (urb->flags & URB_SEND_ZERO_PACKET)
  75109. + && (urb->actual_length == urb->length)
  75110. + && !(urb->length % hc->max_packet)) {
  75111. + xfer_done = 0;
  75112. + } else if (short_read || urb->actual_length >= urb->length) {
  75113. + xfer_done = 1;
  75114. + urb->status = 0;
  75115. + }
  75116. +
  75117. +#ifdef DEBUG
  75118. + {
  75119. + hctsiz_data_t hctsiz;
  75120. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75121. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  75122. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  75123. + hc->hc_num);
  75124. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  75125. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  75126. + hctsiz.b.xfersize);
  75127. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  75128. + urb->length);
  75129. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  75130. + urb->actual_length);
  75131. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  75132. + short_read, xfer_done);
  75133. + }
  75134. +#endif
  75135. +
  75136. + return xfer_done;
  75137. +}
  75138. +
  75139. +/*
  75140. + * Save the starting data toggle for the next transfer. The data toggle is
  75141. + * saved in the QH for non-control transfers and it's saved in the QTD for
  75142. + * control transfers.
  75143. + */
  75144. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  75145. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  75146. +{
  75147. + hctsiz_data_t hctsiz;
  75148. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75149. +
  75150. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  75151. + dwc_otg_qh_t *qh = hc->qh;
  75152. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  75153. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  75154. + } else {
  75155. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  75156. + }
  75157. + } else {
  75158. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  75159. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  75160. + } else {
  75161. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  75162. + }
  75163. + }
  75164. +}
  75165. +
  75166. +/**
  75167. + * Updates the state of an Isochronous URB when the transfer is stopped for
  75168. + * any reason. The fields of the current entry in the frame descriptor array
  75169. + * are set based on the transfer state and the input _halt_status. Completes
  75170. + * the Isochronous URB if all the URB frames have been completed.
  75171. + *
  75172. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  75173. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  75174. + */
  75175. +static dwc_otg_halt_status_e
  75176. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  75177. + dwc_hc_t * hc,
  75178. + dwc_otg_hc_regs_t * hc_regs,
  75179. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  75180. +{
  75181. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75182. + dwc_otg_halt_status_e ret_val = halt_status;
  75183. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75184. +
  75185. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  75186. + switch (halt_status) {
  75187. + case DWC_OTG_HC_XFER_COMPLETE:
  75188. + frame_desc->status = 0;
  75189. + frame_desc->actual_length =
  75190. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  75191. +
  75192. + /* non DWORD-aligned buffer case handling. */
  75193. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  75194. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  75195. + hc->qh->dw_align_buf, frame_desc->actual_length);
  75196. + }
  75197. +
  75198. + break;
  75199. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  75200. + urb->error_count++;
  75201. + if (hc->ep_is_in) {
  75202. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  75203. + } else {
  75204. + frame_desc->status = -DWC_E_COMMUNICATION;
  75205. + }
  75206. + frame_desc->actual_length = 0;
  75207. + break;
  75208. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75209. + urb->error_count++;
  75210. + frame_desc->status = -DWC_E_OVERFLOW;
  75211. + /* Don't need to update actual_length in this case. */
  75212. + break;
  75213. + case DWC_OTG_HC_XFER_XACT_ERR:
  75214. + urb->error_count++;
  75215. + frame_desc->status = -DWC_E_PROTOCOL;
  75216. + frame_desc->actual_length =
  75217. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  75218. +
  75219. + /* non DWORD-aligned buffer case handling. */
  75220. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  75221. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  75222. + hc->qh->dw_align_buf, frame_desc->actual_length);
  75223. + }
  75224. + /* Skip whole frame */
  75225. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  75226. + hc->ep_is_in && hcd->core_if->dma_enable) {
  75227. + qtd->complete_split = 0;
  75228. + qtd->isoc_split_offset = 0;
  75229. + }
  75230. +
  75231. + break;
  75232. + default:
  75233. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  75234. + break;
  75235. + }
  75236. + if (++qtd->isoc_frame_index == urb->packet_count) {
  75237. + /*
  75238. + * urb->status is not used for isoc transfers.
  75239. + * The individual frame_desc statuses are used instead.
  75240. + */
  75241. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  75242. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  75243. + } else {
  75244. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  75245. + }
  75246. + return ret_val;
  75247. +}
  75248. +
  75249. +/**
  75250. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  75251. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  75252. + * still linked to the QH, the QH is added to the end of the inactive
  75253. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  75254. + * schedule if no more QTDs are linked to the QH.
  75255. + */
  75256. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  75257. +{
  75258. + int continue_split = 0;
  75259. + dwc_otg_qtd_t *qtd;
  75260. +
  75261. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  75262. +
  75263. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  75264. +
  75265. + if (qtd->complete_split) {
  75266. + continue_split = 1;
  75267. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  75268. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  75269. + continue_split = 1;
  75270. + }
  75271. +
  75272. + if (free_qtd) {
  75273. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  75274. + continue_split = 0;
  75275. + }
  75276. +
  75277. + qh->channel = NULL;
  75278. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  75279. +}
  75280. +
  75281. +/**
  75282. + * Releases a host channel for use by other transfers. Attempts to select and
  75283. + * queue more transactions since at least one host channel is available.
  75284. + *
  75285. + * @param hcd The HCD state structure.
  75286. + * @param hc The host channel to release.
  75287. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  75288. + * if the transfer is complete or an error has occurred.
  75289. + * @param halt_status Reason the channel is being released. This status
  75290. + * determines the actions taken by this function.
  75291. + */
  75292. +static void release_channel(dwc_otg_hcd_t * hcd,
  75293. + dwc_hc_t * hc,
  75294. + dwc_otg_qtd_t * qtd,
  75295. + dwc_otg_halt_status_e halt_status)
  75296. +{
  75297. + dwc_otg_transaction_type_e tr_type;
  75298. + int free_qtd;
  75299. + dwc_irqflags_t flags;
  75300. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  75301. +#ifdef FIQ_DEBUG
  75302. + int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
  75303. +#endif
  75304. + int hog_port = 0;
  75305. +
  75306. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  75307. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  75308. +
  75309. + if(fiq_split_enable && hc->do_split) {
  75310. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  75311. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  75312. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  75313. + hog_port = 1;
  75314. + }
  75315. + }
  75316. + }
  75317. +
  75318. + switch (halt_status) {
  75319. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  75320. + free_qtd = 1;
  75321. + break;
  75322. + case DWC_OTG_HC_XFER_AHB_ERR:
  75323. + case DWC_OTG_HC_XFER_STALL:
  75324. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  75325. + free_qtd = 1;
  75326. + break;
  75327. + case DWC_OTG_HC_XFER_XACT_ERR:
  75328. + if (qtd->error_count >= 3) {
  75329. + DWC_DEBUGPL(DBG_HCDV,
  75330. + " Complete URB with transaction error\n");
  75331. + free_qtd = 1;
  75332. + qtd->urb->status = -DWC_E_PROTOCOL;
  75333. + hcd->fops->complete(hcd, qtd->urb->priv,
  75334. + qtd->urb, -DWC_E_PROTOCOL);
  75335. + } else {
  75336. + free_qtd = 0;
  75337. + }
  75338. + break;
  75339. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  75340. + /*
  75341. + * The QTD has already been removed and the QH has been
  75342. + * deactivated. Don't want to do anything except release the
  75343. + * host channel and try to queue more transfers.
  75344. + */
  75345. + goto cleanup;
  75346. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  75347. + free_qtd = 0;
  75348. + break;
  75349. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  75350. + DWC_DEBUGPL(DBG_HCDV,
  75351. + " Complete URB with I/O error\n");
  75352. + free_qtd = 1;
  75353. + qtd->urb->status = -DWC_E_IO;
  75354. + hcd->fops->complete(hcd, qtd->urb->priv,
  75355. + qtd->urb, -DWC_E_IO);
  75356. + break;
  75357. + default:
  75358. + free_qtd = 0;
  75359. + break;
  75360. + }
  75361. +
  75362. + deactivate_qh(hcd, hc->qh, free_qtd);
  75363. +
  75364. +cleanup:
  75365. + /*
  75366. + * Release the host channel for use by other transfers. The cleanup
  75367. + * function clears the channel interrupt enables and conditions, so
  75368. + * there's no need to clear the Channel Halted interrupt separately.
  75369. + */
  75370. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  75371. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  75372. +
  75373. + if (!microframe_schedule) {
  75374. + switch (hc->ep_type) {
  75375. + case DWC_OTG_EP_TYPE_CONTROL:
  75376. + case DWC_OTG_EP_TYPE_BULK:
  75377. + hcd->non_periodic_channels--;
  75378. + break;
  75379. +
  75380. + default:
  75381. + /*
  75382. + * Don't release reservations for periodic channels here.
  75383. + * That's done when a periodic transfer is descheduled (i.e.
  75384. + * when the QH is removed from the periodic schedule).
  75385. + */
  75386. + break;
  75387. + }
  75388. + } else {
  75389. +
  75390. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  75391. + hcd->available_host_channels++;
  75392. + fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
  75393. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  75394. + }
  75395. +
  75396. + if(fiq_split_enable && hc->do_split)
  75397. + {
  75398. + if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
  75399. + {
  75400. + fiq_print(FIQDBG_ERR, "PRTNOTAL");
  75401. + //BUG();
  75402. + }
  75403. + if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
  75404. + hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
  75405. + hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
  75406. +#ifdef FIQ_DEBUG
  75407. + hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
  75408. +#endif
  75409. + fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
  75410. + }
  75411. + }
  75412. +
  75413. + /* Try to queue more transfers now that there's a free channel. */
  75414. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  75415. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  75416. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  75417. + }
  75418. +}
  75419. +
  75420. +/**
  75421. + * Halts a host channel. If the channel cannot be halted immediately because
  75422. + * the request queue is full, this function ensures that the FIFO empty
  75423. + * interrupt for the appropriate queue is enabled so that the halt request can
  75424. + * be queued when there is space in the request queue.
  75425. + *
  75426. + * This function may also be called in DMA mode. In that case, the channel is
  75427. + * simply released since the core always halts the channel automatically in
  75428. + * DMA mode.
  75429. + */
  75430. +static void halt_channel(dwc_otg_hcd_t * hcd,
  75431. + dwc_hc_t * hc,
  75432. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  75433. +{
  75434. + if (hcd->core_if->dma_enable) {
  75435. + release_channel(hcd, hc, qtd, halt_status);
  75436. + return;
  75437. + }
  75438. +
  75439. + /* Slave mode processing... */
  75440. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  75441. +
  75442. + if (hc->halt_on_queue) {
  75443. + gintmsk_data_t gintmsk = {.d32 = 0 };
  75444. + dwc_otg_core_global_regs_t *global_regs;
  75445. + global_regs = hcd->core_if->core_global_regs;
  75446. +
  75447. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  75448. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  75449. + /*
  75450. + * Make sure the Non-periodic Tx FIFO empty interrupt
  75451. + * is enabled so that the non-periodic schedule will
  75452. + * be processed.
  75453. + */
  75454. + gintmsk.b.nptxfempty = 1;
  75455. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  75456. + } else {
  75457. + /*
  75458. + * Move the QH from the periodic queued schedule to
  75459. + * the periodic assigned schedule. This allows the
  75460. + * halt to be queued when the periodic schedule is
  75461. + * processed.
  75462. + */
  75463. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  75464. + &hc->qh->qh_list_entry);
  75465. +
  75466. + /*
  75467. + * Make sure the Periodic Tx FIFO Empty interrupt is
  75468. + * enabled so that the periodic schedule will be
  75469. + * processed.
  75470. + */
  75471. + gintmsk.b.ptxfempty = 1;
  75472. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  75473. + }
  75474. + }
  75475. +}
  75476. +
  75477. +/**
  75478. + * Performs common cleanup for non-periodic transfers after a Transfer
  75479. + * Complete interrupt. This function should be called after any endpoint type
  75480. + * specific handling is finished to release the host channel.
  75481. + */
  75482. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  75483. + dwc_hc_t * hc,
  75484. + dwc_otg_hc_regs_t * hc_regs,
  75485. + dwc_otg_qtd_t * qtd,
  75486. + dwc_otg_halt_status_e halt_status)
  75487. +{
  75488. + hcint_data_t hcint;
  75489. +
  75490. + qtd->error_count = 0;
  75491. +
  75492. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  75493. + if (hcint.b.nyet) {
  75494. + /*
  75495. + * Got a NYET on the last transaction of the transfer. This
  75496. + * means that the endpoint should be in the PING state at the
  75497. + * beginning of the next transfer.
  75498. + */
  75499. + hc->qh->ping_state = 1;
  75500. + clear_hc_int(hc_regs, nyet);
  75501. + }
  75502. +
  75503. + /*
  75504. + * Always halt and release the host channel to make it available for
  75505. + * more transfers. There may still be more phases for a control
  75506. + * transfer or more data packets for a bulk transfer at this point,
  75507. + * but the host channel is still halted. A channel will be reassigned
  75508. + * to the transfer when the non-periodic schedule is processed after
  75509. + * the channel is released. This allows transactions to be queued
  75510. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  75511. + * Tx FIFO Empty interrupt if necessary.
  75512. + */
  75513. + if (hc->ep_is_in) {
  75514. + /*
  75515. + * IN transfers in Slave mode require an explicit disable to
  75516. + * halt the channel. (In DMA mode, this call simply releases
  75517. + * the channel.)
  75518. + */
  75519. + halt_channel(hcd, hc, qtd, halt_status);
  75520. + } else {
  75521. + /*
  75522. + * The channel is automatically disabled by the core for OUT
  75523. + * transfers in Slave mode.
  75524. + */
  75525. + release_channel(hcd, hc, qtd, halt_status);
  75526. + }
  75527. +}
  75528. +
  75529. +/**
  75530. + * Performs common cleanup for periodic transfers after a Transfer Complete
  75531. + * interrupt. This function should be called after any endpoint type specific
  75532. + * handling is finished to release the host channel.
  75533. + */
  75534. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  75535. + dwc_hc_t * hc,
  75536. + dwc_otg_hc_regs_t * hc_regs,
  75537. + dwc_otg_qtd_t * qtd,
  75538. + dwc_otg_halt_status_e halt_status)
  75539. +{
  75540. + hctsiz_data_t hctsiz;
  75541. + qtd->error_count = 0;
  75542. +
  75543. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75544. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  75545. + /* Core halts channel in these cases. */
  75546. + release_channel(hcd, hc, qtd, halt_status);
  75547. + } else {
  75548. + /* Flush any outstanding requests from the Tx queue. */
  75549. + halt_channel(hcd, hc, qtd, halt_status);
  75550. + }
  75551. +}
  75552. +
  75553. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  75554. + dwc_hc_t * hc,
  75555. + dwc_otg_hc_regs_t * hc_regs,
  75556. + dwc_otg_qtd_t * qtd)
  75557. +{
  75558. + uint32_t len;
  75559. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  75560. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  75561. +
  75562. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  75563. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  75564. +
  75565. + if (!len) {
  75566. + qtd->complete_split = 0;
  75567. + qtd->isoc_split_offset = 0;
  75568. + return 0;
  75569. + }
  75570. + frame_desc->actual_length += len;
  75571. +
  75572. + if (hc->align_buff && len)
  75573. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  75574. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  75575. + qtd->isoc_split_offset += len;
  75576. +
  75577. + if (frame_desc->length == frame_desc->actual_length) {
  75578. + frame_desc->status = 0;
  75579. + qtd->isoc_frame_index++;
  75580. + qtd->complete_split = 0;
  75581. + qtd->isoc_split_offset = 0;
  75582. + }
  75583. +
  75584. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  75585. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  75586. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  75587. + } else {
  75588. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  75589. + }
  75590. +
  75591. + return 1; /* Indicates that channel released */
  75592. +}
  75593. +
  75594. +/**
  75595. + * Handles a host channel Transfer Complete interrupt. This handler may be
  75596. + * called in either DMA mode or Slave mode.
  75597. + */
  75598. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  75599. + dwc_hc_t * hc,
  75600. + dwc_otg_hc_regs_t * hc_regs,
  75601. + dwc_otg_qtd_t * qtd)
  75602. +{
  75603. + int urb_xfer_done;
  75604. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75605. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75606. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  75607. +
  75608. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75609. + "Transfer Complete--\n", hc->hc_num);
  75610. +
  75611. + if (hcd->core_if->dma_desc_enable) {
  75612. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  75613. + if (pipe_type == UE_ISOCHRONOUS) {
  75614. + /* Do not disable the interrupt, just clear it */
  75615. + clear_hc_int(hc_regs, xfercomp);
  75616. + return 1;
  75617. + }
  75618. + goto handle_xfercomp_done;
  75619. + }
  75620. +
  75621. + /*
  75622. + * Handle xfer complete on CSPLIT.
  75623. + */
  75624. +
  75625. + if (hc->qh->do_split) {
  75626. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  75627. + && hcd->core_if->dma_enable) {
  75628. + if (qtd->complete_split
  75629. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  75630. + qtd))
  75631. + goto handle_xfercomp_done;
  75632. + } else {
  75633. + qtd->complete_split = 0;
  75634. + }
  75635. + }
  75636. +
  75637. + /* Update the QTD and URB states. */
  75638. + switch (pipe_type) {
  75639. + case UE_CONTROL:
  75640. + switch (qtd->control_phase) {
  75641. + case DWC_OTG_CONTROL_SETUP:
  75642. + if (urb->length > 0) {
  75643. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  75644. + } else {
  75645. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  75646. + }
  75647. + DWC_DEBUGPL(DBG_HCDV,
  75648. + " Control setup transaction done\n");
  75649. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75650. + break;
  75651. + case DWC_OTG_CONTROL_DATA:{
  75652. + urb_xfer_done =
  75653. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  75654. + qtd);
  75655. + if (urb_xfer_done) {
  75656. + qtd->control_phase =
  75657. + DWC_OTG_CONTROL_STATUS;
  75658. + DWC_DEBUGPL(DBG_HCDV,
  75659. + " Control data transfer done\n");
  75660. + } else {
  75661. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75662. + }
  75663. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75664. + break;
  75665. + }
  75666. + case DWC_OTG_CONTROL_STATUS:
  75667. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  75668. + if (urb->status == -DWC_E_IN_PROGRESS) {
  75669. + urb->status = 0;
  75670. + }
  75671. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  75672. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  75673. + break;
  75674. + }
  75675. +
  75676. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75677. + break;
  75678. + case UE_BULK:
  75679. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  75680. + urb_xfer_done =
  75681. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  75682. + if (urb_xfer_done) {
  75683. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  75684. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  75685. + } else {
  75686. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75687. + }
  75688. +
  75689. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75690. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75691. + break;
  75692. + case UE_INTERRUPT:
  75693. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  75694. + urb_xfer_done =
  75695. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  75696. +
  75697. + /*
  75698. + * Interrupt URB is done on the first transfer complete
  75699. + * interrupt.
  75700. + */
  75701. + if (urb_xfer_done) {
  75702. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  75703. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  75704. + } else {
  75705. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  75706. + }
  75707. +
  75708. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75709. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75710. + break;
  75711. + case UE_ISOCHRONOUS:
  75712. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  75713. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  75714. + halt_status =
  75715. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  75716. + DWC_OTG_HC_XFER_COMPLETE);
  75717. + }
  75718. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  75719. + break;
  75720. + }
  75721. +
  75722. +handle_xfercomp_done:
  75723. + disable_hc_int(hc_regs, xfercompl);
  75724. +
  75725. + return 1;
  75726. +}
  75727. +
  75728. +/**
  75729. + * Handles a host channel STALL interrupt. This handler may be called in
  75730. + * either DMA mode or Slave mode.
  75731. + */
  75732. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  75733. + dwc_hc_t * hc,
  75734. + dwc_otg_hc_regs_t * hc_regs,
  75735. + dwc_otg_qtd_t * qtd)
  75736. +{
  75737. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  75738. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  75739. +
  75740. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  75741. + "STALL Received--\n", hc->hc_num);
  75742. +
  75743. + if (hcd->core_if->dma_desc_enable) {
  75744. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  75745. + goto handle_stall_done;
  75746. + }
  75747. +
  75748. + if (pipe_type == UE_CONTROL) {
  75749. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  75750. + }
  75751. +
  75752. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  75753. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  75754. + /*
  75755. + * USB protocol requires resetting the data toggle for bulk
  75756. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  75757. + * setup command is issued to the endpoint. Anticipate the
  75758. + * CLEAR_FEATURE command since a STALL has occurred and reset
  75759. + * the data toggle now.
  75760. + */
  75761. + hc->qh->data_toggle = 0;
  75762. + }
  75763. +
  75764. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  75765. +
  75766. +handle_stall_done:
  75767. + disable_hc_int(hc_regs, stall);
  75768. +
  75769. + return 1;
  75770. +}
  75771. +
  75772. +/*
  75773. + * Updates the state of the URB when a transfer has been stopped due to an
  75774. + * abnormal condition before the transfer completes. Modifies the
  75775. + * actual_length field of the URB to reflect the number of bytes that have
  75776. + * actually been transferred via the host channel.
  75777. + */
  75778. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  75779. + dwc_otg_hc_regs_t * hc_regs,
  75780. + dwc_otg_hcd_urb_t * urb,
  75781. + dwc_otg_qtd_t * qtd,
  75782. + dwc_otg_halt_status_e halt_status)
  75783. +{
  75784. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  75785. + halt_status, NULL);
  75786. + /* non DWORD-aligned buffer case handling. */
  75787. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  75788. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  75789. + bytes_transferred);
  75790. + }
  75791. +
  75792. + urb->actual_length += bytes_transferred;
  75793. +
  75794. +#ifdef DEBUG
  75795. + {
  75796. + hctsiz_data_t hctsiz;
  75797. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  75798. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  75799. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  75800. + hc->hc_num);
  75801. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  75802. + hc->start_pkt_count);
  75803. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  75804. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  75805. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  75806. + bytes_transferred);
  75807. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  75808. + urb->actual_length);
  75809. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  75810. + urb->length);
  75811. + }
  75812. +#endif
  75813. +}
  75814. +
  75815. +/**
  75816. + * Handles a host channel NAK interrupt. This handler may be called in either
  75817. + * DMA mode or Slave mode.
  75818. + */
  75819. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  75820. + dwc_hc_t * hc,
  75821. + dwc_otg_hc_regs_t * hc_regs,
  75822. + dwc_otg_qtd_t * qtd)
  75823. +{
  75824. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75825. + "NAK Received--\n", hc->hc_num);
  75826. +
  75827. + /*
  75828. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  75829. + * the beginning of the next frame
  75830. + */
  75831. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75832. + case UE_BULK:
  75833. + case UE_CONTROL:
  75834. + if (nak_holdoff_enable)
  75835. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  75836. + }
  75837. +
  75838. + /*
  75839. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  75840. + * interrupt. Re-start the SSPLIT transfer.
  75841. + */
  75842. + if (hc->do_split) {
  75843. + if (hc->complete_split) {
  75844. + qtd->error_count = 0;
  75845. + }
  75846. + qtd->complete_split = 0;
  75847. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75848. + goto handle_nak_done;
  75849. + }
  75850. +
  75851. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  75852. + case UE_CONTROL:
  75853. + case UE_BULK:
  75854. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  75855. + /*
  75856. + * NAK interrupts are enabled on bulk/control IN
  75857. + * transfers in DMA mode for the sole purpose of
  75858. + * resetting the error count after a transaction error
  75859. + * occurs. The core will continue transferring data.
  75860. + * Disable other interrupts unmasked for the same
  75861. + * reason.
  75862. + */
  75863. + disable_hc_int(hc_regs, datatglerr);
  75864. + disable_hc_int(hc_regs, ack);
  75865. + qtd->error_count = 0;
  75866. + goto handle_nak_done;
  75867. + }
  75868. +
  75869. + /*
  75870. + * NAK interrupts normally occur during OUT transfers in DMA
  75871. + * or Slave mode. For IN transfers, more requests will be
  75872. + * queued as request queue space is available.
  75873. + */
  75874. + qtd->error_count = 0;
  75875. +
  75876. + if (!hc->qh->ping_state) {
  75877. + update_urb_state_xfer_intr(hc, hc_regs,
  75878. + qtd->urb, qtd,
  75879. + DWC_OTG_HC_XFER_NAK);
  75880. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  75881. +
  75882. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  75883. + hc->qh->ping_state = 1;
  75884. + }
  75885. +
  75886. + /*
  75887. + * Halt the channel so the transfer can be re-started from
  75888. + * the appropriate point or the PING protocol will
  75889. + * start/continue.
  75890. + */
  75891. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75892. + break;
  75893. + case UE_INTERRUPT:
  75894. + qtd->error_count = 0;
  75895. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  75896. + break;
  75897. + case UE_ISOCHRONOUS:
  75898. + /* Should never get called for isochronous transfers. */
  75899. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  75900. + break;
  75901. + }
  75902. +
  75903. +handle_nak_done:
  75904. + disable_hc_int(hc_regs, nak);
  75905. +
  75906. + return 1;
  75907. +}
  75908. +
  75909. +/**
  75910. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  75911. + * performing the PING protocol in Slave mode, when errors occur during
  75912. + * either Slave mode or DMA mode, and during Start Split transactions.
  75913. + */
  75914. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  75915. + dwc_hc_t * hc,
  75916. + dwc_otg_hc_regs_t * hc_regs,
  75917. + dwc_otg_qtd_t * qtd)
  75918. +{
  75919. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  75920. + "ACK Received--\n", hc->hc_num);
  75921. +
  75922. + if (hc->do_split) {
  75923. + /*
  75924. + * Handle ACK on SSPLIT.
  75925. + * ACK should not occur in CSPLIT.
  75926. + */
  75927. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  75928. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  75929. + }
  75930. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  75931. + /* Don't need complete for isochronous out transfers. */
  75932. + qtd->complete_split = 1;
  75933. + }
  75934. +
  75935. + /* ISOC OUT */
  75936. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  75937. + switch (hc->xact_pos) {
  75938. + case DWC_HCSPLIT_XACTPOS_ALL:
  75939. + break;
  75940. + case DWC_HCSPLIT_XACTPOS_END:
  75941. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  75942. + qtd->isoc_split_offset = 0;
  75943. + break;
  75944. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  75945. + case DWC_HCSPLIT_XACTPOS_MID:
  75946. + /*
  75947. + * For BEGIN or MID, calculate the length for
  75948. + * the next microframe to determine the correct
  75949. + * SSPLIT token, either MID or END.
  75950. + */
  75951. + {
  75952. + struct dwc_otg_hcd_iso_packet_desc
  75953. + *frame_desc;
  75954. +
  75955. + frame_desc =
  75956. + &qtd->urb->
  75957. + iso_descs[qtd->isoc_frame_index];
  75958. + qtd->isoc_split_offset += 188;
  75959. +
  75960. + if ((frame_desc->length -
  75961. + qtd->isoc_split_offset) <= 188) {
  75962. + qtd->isoc_split_pos =
  75963. + DWC_HCSPLIT_XACTPOS_END;
  75964. + } else {
  75965. + qtd->isoc_split_pos =
  75966. + DWC_HCSPLIT_XACTPOS_MID;
  75967. + }
  75968. +
  75969. + }
  75970. + break;
  75971. + }
  75972. + } else {
  75973. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  75974. + }
  75975. + } else {
  75976. + /*
  75977. + * An unmasked ACK on a non-split DMA transaction is
  75978. + * for the sole purpose of resetting error counts. Disable other
  75979. + * interrupts unmasked for the same reason.
  75980. + */
  75981. + if(hcd->core_if->dma_enable) {
  75982. + disable_hc_int(hc_regs, datatglerr);
  75983. + disable_hc_int(hc_regs, nak);
  75984. + }
  75985. + qtd->error_count = 0;
  75986. +
  75987. + if (hc->qh->ping_state) {
  75988. + hc->qh->ping_state = 0;
  75989. + /*
  75990. + * Halt the channel so the transfer can be re-started
  75991. + * from the appropriate point. This only happens in
  75992. + * Slave mode. In DMA mode, the ping_state is cleared
  75993. + * when the transfer is started because the core
  75994. + * automatically executes the PING, then the transfer.
  75995. + */
  75996. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  75997. + }
  75998. + }
  75999. +
  76000. + /*
  76001. + * If the ACK occurred when _not_ in the PING state, let the channel
  76002. + * continue transferring data after clearing the error count.
  76003. + */
  76004. +
  76005. + disable_hc_int(hc_regs, ack);
  76006. +
  76007. + return 1;
  76008. +}
  76009. +
  76010. +/**
  76011. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  76012. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  76013. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  76014. + * handled in the xfercomp interrupt handler, not here. This handler may be
  76015. + * called in either DMA mode or Slave mode.
  76016. + */
  76017. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  76018. + dwc_hc_t * hc,
  76019. + dwc_otg_hc_regs_t * hc_regs,
  76020. + dwc_otg_qtd_t * qtd)
  76021. +{
  76022. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76023. + "NYET Received--\n", hc->hc_num);
  76024. +
  76025. + /*
  76026. + * NYET on CSPLIT
  76027. + * re-do the CSPLIT immediately on non-periodic
  76028. + */
  76029. + if (hc->do_split && hc->complete_split) {
  76030. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  76031. + && hcd->core_if->dma_enable) {
  76032. + qtd->complete_split = 0;
  76033. + qtd->isoc_split_offset = 0;
  76034. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  76035. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  76036. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  76037. + }
  76038. + else
  76039. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  76040. + goto handle_nyet_done;
  76041. + }
  76042. +
  76043. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  76044. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76045. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  76046. +
  76047. + // With the FIQ running we only ever see the failed NYET
  76048. + if (dwc_full_frame_num(frnum) !=
  76049. + dwc_full_frame_num(hc->qh->sched_frame) ||
  76050. + fiq_split_enable) {
  76051. + /*
  76052. + * No longer in the same full speed frame.
  76053. + * Treat this as a transaction error.
  76054. + */
  76055. +#if 0
  76056. + /** @todo Fix system performance so this can
  76057. + * be treated as an error. Right now complete
  76058. + * splits cannot be scheduled precisely enough
  76059. + * due to other system activity, so this error
  76060. + * occurs regularly in Slave mode.
  76061. + */
  76062. + qtd->error_count++;
  76063. +#endif
  76064. + qtd->complete_split = 0;
  76065. + halt_channel(hcd, hc, qtd,
  76066. + DWC_OTG_HC_XFER_XACT_ERR);
  76067. + /** @todo add support for isoc release */
  76068. + goto handle_nyet_done;
  76069. + }
  76070. + }
  76071. +
  76072. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  76073. + goto handle_nyet_done;
  76074. + }
  76075. +
  76076. + hc->qh->ping_state = 1;
  76077. + qtd->error_count = 0;
  76078. +
  76079. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  76080. + DWC_OTG_HC_XFER_NYET);
  76081. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76082. +
  76083. + /*
  76084. + * Halt the channel and re-start the transfer so the PING
  76085. + * protocol will start.
  76086. + */
  76087. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  76088. +
  76089. +handle_nyet_done:
  76090. + disable_hc_int(hc_regs, nyet);
  76091. + return 1;
  76092. +}
  76093. +
  76094. +/**
  76095. + * Handles a host channel babble interrupt. This handler may be called in
  76096. + * either DMA mode or Slave mode.
  76097. + */
  76098. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  76099. + dwc_hc_t * hc,
  76100. + dwc_otg_hc_regs_t * hc_regs,
  76101. + dwc_otg_qtd_t * qtd)
  76102. +{
  76103. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76104. + "Babble Error--\n", hc->hc_num);
  76105. +
  76106. + if (hcd->core_if->dma_desc_enable) {
  76107. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76108. + DWC_OTG_HC_XFER_BABBLE_ERR);
  76109. + goto handle_babble_done;
  76110. + }
  76111. +
  76112. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  76113. + hcd->fops->complete(hcd, qtd->urb->priv,
  76114. + qtd->urb, -DWC_E_OVERFLOW);
  76115. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  76116. + } else {
  76117. + dwc_otg_halt_status_e halt_status;
  76118. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76119. + DWC_OTG_HC_XFER_BABBLE_ERR);
  76120. + halt_channel(hcd, hc, qtd, halt_status);
  76121. + }
  76122. +
  76123. +handle_babble_done:
  76124. + disable_hc_int(hc_regs, bblerr);
  76125. + return 1;
  76126. +}
  76127. +
  76128. +/**
  76129. + * Handles a host channel AHB error interrupt. This handler is only called in
  76130. + * DMA mode.
  76131. + */
  76132. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  76133. + dwc_hc_t * hc,
  76134. + dwc_otg_hc_regs_t * hc_regs,
  76135. + dwc_otg_qtd_t * qtd)
  76136. +{
  76137. + hcchar_data_t hcchar;
  76138. + hcsplt_data_t hcsplt;
  76139. + hctsiz_data_t hctsiz;
  76140. + uint32_t hcdma;
  76141. + char *pipetype, *speed;
  76142. +
  76143. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  76144. +
  76145. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76146. + "AHB Error--\n", hc->hc_num);
  76147. +
  76148. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76149. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  76150. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76151. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  76152. +
  76153. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  76154. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  76155. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  76156. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  76157. + DWC_ERROR(" Device address: %d\n",
  76158. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  76159. + DWC_ERROR(" Endpoint: %d, %s\n",
  76160. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  76161. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  76162. +
  76163. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  76164. + case UE_CONTROL:
  76165. + pipetype = "CONTROL";
  76166. + break;
  76167. + case UE_BULK:
  76168. + pipetype = "BULK";
  76169. + break;
  76170. + case UE_INTERRUPT:
  76171. + pipetype = "INTERRUPT";
  76172. + break;
  76173. + case UE_ISOCHRONOUS:
  76174. + pipetype = "ISOCHRONOUS";
  76175. + break;
  76176. + default:
  76177. + pipetype = "UNKNOWN";
  76178. + break;
  76179. + }
  76180. +
  76181. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  76182. +
  76183. + switch (hc->speed) {
  76184. + case DWC_OTG_EP_SPEED_HIGH:
  76185. + speed = "HIGH";
  76186. + break;
  76187. + case DWC_OTG_EP_SPEED_FULL:
  76188. + speed = "FULL";
  76189. + break;
  76190. + case DWC_OTG_EP_SPEED_LOW:
  76191. + speed = "LOW";
  76192. + break;
  76193. + default:
  76194. + speed = "UNKNOWN";
  76195. + break;
  76196. + };
  76197. +
  76198. + DWC_ERROR(" Speed: %s\n", speed);
  76199. +
  76200. + DWC_ERROR(" Max packet size: %d\n",
  76201. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  76202. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  76203. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  76204. + urb->buf, (void *)urb->dma);
  76205. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  76206. + urb->setup_packet, (void *)urb->setup_dma);
  76207. + DWC_ERROR(" Interval: %d\n", urb->interval);
  76208. +
  76209. + /* Core haltes the channel for Descriptor DMA mode */
  76210. + if (hcd->core_if->dma_desc_enable) {
  76211. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76212. + DWC_OTG_HC_XFER_AHB_ERR);
  76213. + goto handle_ahberr_done;
  76214. + }
  76215. +
  76216. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  76217. +
  76218. + /*
  76219. + * Force a channel halt. Don't call halt_channel because that won't
  76220. + * write to the HCCHARn register in DMA mode to force the halt.
  76221. + */
  76222. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  76223. +handle_ahberr_done:
  76224. + disable_hc_int(hc_regs, ahberr);
  76225. + return 1;
  76226. +}
  76227. +
  76228. +/**
  76229. + * Handles a host channel transaction error interrupt. This handler may be
  76230. + * called in either DMA mode or Slave mode.
  76231. + */
  76232. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  76233. + dwc_hc_t * hc,
  76234. + dwc_otg_hc_regs_t * hc_regs,
  76235. + dwc_otg_qtd_t * qtd)
  76236. +{
  76237. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76238. + "Transaction Error--\n", hc->hc_num);
  76239. +
  76240. + if (hcd->core_if->dma_desc_enable) {
  76241. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76242. + DWC_OTG_HC_XFER_XACT_ERR);
  76243. + goto handle_xacterr_done;
  76244. + }
  76245. +
  76246. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76247. + case UE_CONTROL:
  76248. + case UE_BULK:
  76249. + qtd->error_count++;
  76250. + if (!hc->qh->ping_state) {
  76251. +
  76252. + update_urb_state_xfer_intr(hc, hc_regs,
  76253. + qtd->urb, qtd,
  76254. + DWC_OTG_HC_XFER_XACT_ERR);
  76255. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76256. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  76257. + hc->qh->ping_state = 1;
  76258. + }
  76259. + }
  76260. +
  76261. + /*
  76262. + * Halt the channel so the transfer can be re-started from
  76263. + * the appropriate point or the PING protocol will start.
  76264. + */
  76265. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76266. + break;
  76267. + case UE_INTERRUPT:
  76268. + qtd->error_count++;
  76269. + if (hc->do_split && hc->complete_split) {
  76270. + qtd->complete_split = 0;
  76271. + }
  76272. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76273. + break;
  76274. + case UE_ISOCHRONOUS:
  76275. + {
  76276. + dwc_otg_halt_status_e halt_status;
  76277. + halt_status =
  76278. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76279. + DWC_OTG_HC_XFER_XACT_ERR);
  76280. +
  76281. + halt_channel(hcd, hc, qtd, halt_status);
  76282. + }
  76283. + break;
  76284. + }
  76285. +handle_xacterr_done:
  76286. + disable_hc_int(hc_regs, xacterr);
  76287. +
  76288. + return 1;
  76289. +}
  76290. +
  76291. +/**
  76292. + * Handles a host channel frame overrun interrupt. This handler may be called
  76293. + * in either DMA mode or Slave mode.
  76294. + */
  76295. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  76296. + dwc_hc_t * hc,
  76297. + dwc_otg_hc_regs_t * hc_regs,
  76298. + dwc_otg_qtd_t * qtd)
  76299. +{
  76300. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76301. + "Frame Overrun--\n", hc->hc_num);
  76302. +
  76303. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  76304. + case UE_CONTROL:
  76305. + case UE_BULK:
  76306. + break;
  76307. + case UE_INTERRUPT:
  76308. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  76309. + break;
  76310. + case UE_ISOCHRONOUS:
  76311. + {
  76312. + dwc_otg_halt_status_e halt_status;
  76313. + halt_status =
  76314. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  76315. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  76316. +
  76317. + halt_channel(hcd, hc, qtd, halt_status);
  76318. + }
  76319. + break;
  76320. + }
  76321. +
  76322. + disable_hc_int(hc_regs, frmovrun);
  76323. +
  76324. + return 1;
  76325. +}
  76326. +
  76327. +/**
  76328. + * Handles a host channel data toggle error interrupt. This handler may be
  76329. + * called in either DMA mode or Slave mode.
  76330. + */
  76331. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  76332. + dwc_hc_t * hc,
  76333. + dwc_otg_hc_regs_t * hc_regs,
  76334. + dwc_otg_qtd_t * qtd)
  76335. +{
  76336. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76337. + "Data Toggle Error on %s transfer--\n",
  76338. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  76339. +
  76340. + /* Data toggles on split transactions cause the hc to halt.
  76341. + * restart transfer */
  76342. + if(hc->qh->do_split)
  76343. + {
  76344. + qtd->error_count++;
  76345. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76346. + update_urb_state_xfer_intr(hc, hc_regs,
  76347. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76348. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76349. + } else if (hc->ep_is_in) {
  76350. + /* An unmasked data toggle error on a non-split DMA transaction is
  76351. + * for the sole purpose of resetting error counts. Disable other
  76352. + * interrupts unmasked for the same reason.
  76353. + */
  76354. + if(hcd->core_if->dma_enable) {
  76355. + disable_hc_int(hc_regs, ack);
  76356. + disable_hc_int(hc_regs, nak);
  76357. + }
  76358. + qtd->error_count = 0;
  76359. + }
  76360. +
  76361. + disable_hc_int(hc_regs, datatglerr);
  76362. +
  76363. + return 1;
  76364. +}
  76365. +
  76366. +#ifdef DEBUG
  76367. +/**
  76368. + * This function is for debug only. It checks that a valid halt status is set
  76369. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  76370. + * taken and a warning is issued.
  76371. + * @return 1 if halt status is ok, 0 otherwise.
  76372. + */
  76373. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  76374. + dwc_hc_t * hc,
  76375. + dwc_otg_hc_regs_t * hc_regs,
  76376. + dwc_otg_qtd_t * qtd)
  76377. +{
  76378. + hcchar_data_t hcchar;
  76379. + hctsiz_data_t hctsiz;
  76380. + hcint_data_t hcint;
  76381. + hcintmsk_data_t hcintmsk;
  76382. + hcsplt_data_t hcsplt;
  76383. +
  76384. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  76385. + /*
  76386. + * This code is here only as a check. This condition should
  76387. + * never happen. Ignore the halt if it does occur.
  76388. + */
  76389. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76390. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76391. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76392. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  76393. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  76394. + DWC_WARN
  76395. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  76396. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  76397. + "hcint 0x%08x, hcintmsk 0x%08x, "
  76398. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  76399. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  76400. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  76401. +
  76402. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  76403. + __func__, hc->hc_num);
  76404. + DWC_WARN("\n");
  76405. + clear_hc_int(hc_regs, chhltd);
  76406. + return 0;
  76407. + }
  76408. +
  76409. + /*
  76410. + * This code is here only as a check. hcchar.chdis should
  76411. + * never be set when the halt interrupt occurs. Halt the
  76412. + * channel again if it does occur.
  76413. + */
  76414. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  76415. + if (hcchar.b.chdis) {
  76416. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  76417. + "hcchar 0x%08x, trying to halt again\n",
  76418. + __func__, hcchar.d32);
  76419. + clear_hc_int(hc_regs, chhltd);
  76420. + hc->halt_pending = 0;
  76421. + halt_channel(hcd, hc, qtd, hc->halt_status);
  76422. + return 0;
  76423. + }
  76424. +
  76425. + return 1;
  76426. +}
  76427. +#endif
  76428. +
  76429. +/**
  76430. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  76431. + * determines the reason the channel halted and proceeds accordingly.
  76432. + */
  76433. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  76434. + dwc_hc_t * hc,
  76435. + dwc_otg_hc_regs_t * hc_regs,
  76436. + dwc_otg_qtd_t * qtd,
  76437. + hcint_data_t hcint,
  76438. + hcintmsk_data_t hcintmsk)
  76439. +{
  76440. + int out_nak_enh = 0;
  76441. +
  76442. + /* For core with OUT NAK enhancement, the flow for high-
  76443. + * speed CONTROL/BULK OUT is handled a little differently.
  76444. + */
  76445. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  76446. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  76447. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  76448. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  76449. + out_nak_enh = 1;
  76450. + }
  76451. + }
  76452. +
  76453. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  76454. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  76455. + && !hcd->core_if->dma_desc_enable)) {
  76456. + /*
  76457. + * Just release the channel. A dequeue can happen on a
  76458. + * transfer timeout. In the case of an AHB Error, the channel
  76459. + * was forced to halt because there's no way to gracefully
  76460. + * recover.
  76461. + */
  76462. + if (hcd->core_if->dma_desc_enable)
  76463. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  76464. + hc->halt_status);
  76465. + else
  76466. + release_channel(hcd, hc, qtd, hc->halt_status);
  76467. + return;
  76468. + }
  76469. +
  76470. + /* Read the HCINTn register to determine the cause for the halt. */
  76471. + if(!fiq_split_enable)
  76472. + {
  76473. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76474. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  76475. + }
  76476. +
  76477. + if (hcint.b.xfercomp) {
  76478. + /** @todo This is here because of a possible hardware bug. Spec
  76479. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  76480. + * interrupt w/ACK bit set should occur, but I only see the
  76481. + * XFERCOMP bit, even with it masked out. This is a workaround
  76482. + * for that behavior. Should fix this when hardware is fixed.
  76483. + */
  76484. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  76485. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  76486. + }
  76487. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  76488. + } else if (hcint.b.stall) {
  76489. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  76490. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  76491. + if (out_nak_enh) {
  76492. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  76493. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  76494. + qtd->error_count = 0;
  76495. + } else {
  76496. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  76497. + }
  76498. + }
  76499. +
  76500. + /*
  76501. + * Must handle xacterr before nak or ack. Could get a xacterr
  76502. + * at the same time as either of these on a BULK/CONTROL OUT
  76503. + * that started with a PING. The xacterr takes precedence.
  76504. + */
  76505. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  76506. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  76507. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  76508. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  76509. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  76510. + } else if (hcint.b.bblerr) {
  76511. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  76512. + } else if (hcint.b.frmovrun) {
  76513. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  76514. + } else if (hcint.b.datatglerr) {
  76515. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  76516. + } else if (!out_nak_enh) {
  76517. + if (hcint.b.nyet) {
  76518. + /*
  76519. + * Must handle nyet before nak or ack. Could get a nyet at the
  76520. + * same time as either of those on a BULK/CONTROL OUT that
  76521. + * started with a PING. The nyet takes precedence.
  76522. + */
  76523. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  76524. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  76525. + /*
  76526. + * If nak is not masked, it's because a non-split IN transfer
  76527. + * is in an error state. In that case, the nak is handled by
  76528. + * the nak interrupt handler, not here. Handle nak here for
  76529. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  76530. + * rewinding the buffer pointer.
  76531. + */
  76532. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  76533. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  76534. + /*
  76535. + * If ack is not masked, it's because a non-split IN transfer
  76536. + * is in an error state. In that case, the ack is handled by
  76537. + * the ack interrupt handler, not here. Handle ack here for
  76538. + * split transfers. Start splits halt on ACK.
  76539. + */
  76540. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  76541. + } else {
  76542. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  76543. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  76544. + /*
  76545. + * A periodic transfer halted with no other channel
  76546. + * interrupts set. Assume it was halted by the core
  76547. + * because it could not be completed in its scheduled
  76548. + * (micro)frame.
  76549. + */
  76550. +#ifdef DEBUG
  76551. + DWC_PRINTF
  76552. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  76553. + __func__, hc->hc_num);
  76554. +#endif
  76555. + halt_channel(hcd, hc, qtd,
  76556. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  76557. + } else {
  76558. + DWC_ERROR
  76559. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  76560. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  76561. + __func__, hc->hc_num, hcint.d32,
  76562. + DWC_READ_REG32(&hcd->
  76563. + core_if->core_global_regs->
  76564. + gintsts));
  76565. + /* Failthrough: use 3-strikes rule */
  76566. + qtd->error_count++;
  76567. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76568. + update_urb_state_xfer_intr(hc, hc_regs,
  76569. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76570. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76571. + }
  76572. +
  76573. + }
  76574. + } else {
  76575. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  76576. + hcint.d32);
  76577. + /* Failthrough: use 3-strikes rule */
  76578. + qtd->error_count++;
  76579. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  76580. + update_urb_state_xfer_intr(hc, hc_regs,
  76581. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76582. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  76583. + }
  76584. +}
  76585. +
  76586. +/**
  76587. + * Handles a host channel Channel Halted interrupt.
  76588. + *
  76589. + * In slave mode, this handler is called only when the driver specifically
  76590. + * requests a halt. This occurs during handling other host channel interrupts
  76591. + * (e.g. nak, xacterr, stall, nyet, etc.).
  76592. + *
  76593. + * In DMA mode, this is the interrupt that occurs when the core has finished
  76594. + * processing a transfer on a channel. Other host channel interrupts (except
  76595. + * ahberr) are disabled in DMA mode.
  76596. + */
  76597. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  76598. + dwc_hc_t * hc,
  76599. + dwc_otg_hc_regs_t * hc_regs,
  76600. + dwc_otg_qtd_t * qtd,
  76601. + hcint_data_t hcint,
  76602. + hcintmsk_data_t hcintmsk)
  76603. +{
  76604. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  76605. + "Channel Halted--\n", hc->hc_num);
  76606. +
  76607. + if (hcd->core_if->dma_enable) {
  76608. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
  76609. + } else {
  76610. +#ifdef DEBUG
  76611. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  76612. + return 1;
  76613. + }
  76614. +#endif
  76615. + release_channel(hcd, hc, qtd, hc->halt_status);
  76616. + }
  76617. +
  76618. + return 1;
  76619. +}
  76620. +
  76621. +/** Handles interrupt for a specific Host Channel */
  76622. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  76623. +{
  76624. + int retval = 0;
  76625. + hcint_data_t hcint, hcint_orig;
  76626. + hcintmsk_data_t hcintmsk;
  76627. + dwc_hc_t *hc;
  76628. + dwc_otg_hc_regs_t *hc_regs;
  76629. + dwc_otg_qtd_t *qtd;
  76630. +
  76631. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  76632. +
  76633. + hc = dwc_otg_hcd->hc_ptr_array[num];
  76634. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  76635. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  76636. + /* We are responding to a channel disable. Driver
  76637. + * state is cleared - our qtd has gone away.
  76638. + */
  76639. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  76640. + return 1;
  76641. + }
  76642. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  76643. +
  76644. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  76645. + hcint_orig = hcint;
  76646. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  76647. + DWC_DEBUGPL(DBG_HCDV,
  76648. + " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  76649. + hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
  76650. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  76651. +
  76652. + if(fiq_split_enable)
  76653. + {
  76654. + // replace with the saved interrupts from the fiq handler
  76655. + local_fiq_disable();
  76656. + hcint_orig.d32 = hcint_saved[num].d32;
  76657. + hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
  76658. + hcint_saved[num].d32 = 0;
  76659. + local_fiq_enable();
  76660. + }
  76661. +
  76662. + if (!dwc_otg_hcd->core_if->dma_enable) {
  76663. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  76664. + hcint.b.chhltd = 0;
  76665. + }
  76666. + }
  76667. +
  76668. + if (hcint.b.xfercomp) {
  76669. + retval |=
  76670. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76671. + /*
  76672. + * If NYET occurred at same time as Xfer Complete, the NYET is
  76673. + * handled by the Xfer Complete interrupt handler. Don't want
  76674. + * to call the NYET interrupt handler in this case.
  76675. + */
  76676. + hcint.b.nyet = 0;
  76677. + }
  76678. + if (hcint.b.chhltd) {
  76679. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
  76680. + }
  76681. + if (hcint.b.ahberr) {
  76682. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76683. + }
  76684. + if (hcint.b.stall) {
  76685. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76686. + }
  76687. + if (hcint.b.nak) {
  76688. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76689. + }
  76690. + if (hcint.b.ack) {
  76691. + if(!hcint.b.chhltd)
  76692. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76693. + }
  76694. + if (hcint.b.nyet) {
  76695. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76696. + }
  76697. + if (hcint.b.xacterr) {
  76698. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76699. + }
  76700. + if (hcint.b.bblerr) {
  76701. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76702. + }
  76703. + if (hcint.b.frmovrun) {
  76704. + retval |=
  76705. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76706. + }
  76707. + if (hcint.b.datatglerr) {
  76708. + retval |=
  76709. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  76710. + }
  76711. +
  76712. + return retval;
  76713. +}
  76714. +#endif /* DWC_DEVICE_ONLY */
  76715. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  76716. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  76717. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-02-07 19:57:30.000000000 +0100
  76718. @@ -0,0 +1,972 @@
  76719. +
  76720. +/* ==========================================================================
  76721. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  76722. + * $Revision: #20 $
  76723. + * $Date: 2011/10/26 $
  76724. + * $Change: 1872981 $
  76725. + *
  76726. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76727. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76728. + * otherwise expressly agreed to in writing between Synopsys and you.
  76729. + *
  76730. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76731. + * any End User Software License Agreement or Agreement for Licensed Product
  76732. + * with Synopsys or any supplement thereto. You are permitted to use and
  76733. + * redistribute this Software in source and binary forms, with or without
  76734. + * modification, provided that redistributions of source code must retain this
  76735. + * notice. You may not view, use, disclose, copy or distribute this file or
  76736. + * any information contained herein except pursuant to this license grant from
  76737. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76738. + * below, then you are not authorized to use the Software.
  76739. + *
  76740. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76741. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76742. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76743. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76744. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76745. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76746. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76747. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76748. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76749. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76750. + * DAMAGE.
  76751. + * ========================================================================== */
  76752. +#ifndef DWC_DEVICE_ONLY
  76753. +
  76754. +/**
  76755. + * @file
  76756. + *
  76757. + * This file contains the implementation of the HCD. In Linux, the HCD
  76758. + * implements the hc_driver API.
  76759. + */
  76760. +#include <linux/kernel.h>
  76761. +#include <linux/module.h>
  76762. +#include <linux/moduleparam.h>
  76763. +#include <linux/init.h>
  76764. +#include <linux/device.h>
  76765. +#include <linux/errno.h>
  76766. +#include <linux/list.h>
  76767. +#include <linux/interrupt.h>
  76768. +#include <linux/string.h>
  76769. +#include <linux/dma-mapping.h>
  76770. +#include <linux/version.h>
  76771. +#include <asm/io.h>
  76772. +#include <asm/fiq.h>
  76773. +#include <linux/usb.h>
  76774. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  76775. +#include <../drivers/usb/core/hcd.h>
  76776. +#else
  76777. +#include <linux/usb/hcd.h>
  76778. +#endif
  76779. +
  76780. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  76781. +#define USB_URB_EP_LINKING 1
  76782. +#else
  76783. +#define USB_URB_EP_LINKING 0
  76784. +#endif
  76785. +
  76786. +#include "dwc_otg_hcd_if.h"
  76787. +#include "dwc_otg_dbg.h"
  76788. +#include "dwc_otg_driver.h"
  76789. +#include "dwc_otg_hcd.h"
  76790. +#include "dwc_otg_mphi_fix.h"
  76791. +
  76792. +/**
  76793. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  76794. + * qualified with its direction (possible 32 endpoints per device).
  76795. + */
  76796. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  76797. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  76798. +
  76799. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  76800. +
  76801. +extern bool fiq_fix_enable;
  76802. +
  76803. +/** @name Linux HC Driver API Functions */
  76804. +/** @{ */
  76805. +/* manage i/o requests, device state */
  76806. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  76807. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76808. + struct usb_host_endpoint *ep,
  76809. +#endif
  76810. + struct urb *urb, gfp_t mem_flags);
  76811. +
  76812. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  76813. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  76814. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  76815. +#endif
  76816. +#else /* kernels at or post 2.6.30 */
  76817. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  76818. + struct urb *urb, int status);
  76819. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  76820. +
  76821. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  76822. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  76823. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  76824. +#endif
  76825. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  76826. +extern int hcd_start(struct usb_hcd *hcd);
  76827. +extern void hcd_stop(struct usb_hcd *hcd);
  76828. +static int get_frame_number(struct usb_hcd *hcd);
  76829. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  76830. +extern int hub_control(struct usb_hcd *hcd,
  76831. + u16 typeReq,
  76832. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  76833. +
  76834. +struct wrapper_priv_data {
  76835. + dwc_otg_hcd_t *dwc_otg_hcd;
  76836. +};
  76837. +
  76838. +/** @} */
  76839. +
  76840. +static struct hc_driver dwc_otg_hc_driver = {
  76841. +
  76842. + .description = dwc_otg_hcd_name,
  76843. + .product_desc = "DWC OTG Controller",
  76844. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  76845. +
  76846. + .irq = dwc_otg_hcd_irq,
  76847. +
  76848. + .flags = HCD_MEMORY | HCD_USB2,
  76849. +
  76850. + //.reset =
  76851. + .start = hcd_start,
  76852. + //.suspend =
  76853. + //.resume =
  76854. + .stop = hcd_stop,
  76855. +
  76856. + .urb_enqueue = dwc_otg_urb_enqueue,
  76857. + .urb_dequeue = dwc_otg_urb_dequeue,
  76858. + .endpoint_disable = endpoint_disable,
  76859. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  76860. + .endpoint_reset = endpoint_reset,
  76861. +#endif
  76862. + .get_frame_number = get_frame_number,
  76863. +
  76864. + .hub_status_data = hub_status_data,
  76865. + .hub_control = hub_control,
  76866. + //.bus_suspend =
  76867. + //.bus_resume =
  76868. +};
  76869. +
  76870. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  76871. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  76872. +{
  76873. + struct wrapper_priv_data *p;
  76874. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  76875. + return p->dwc_otg_hcd;
  76876. +}
  76877. +
  76878. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  76879. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  76880. +{
  76881. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  76882. +}
  76883. +
  76884. +/** Gets the usb_host_endpoint associated with an URB. */
  76885. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  76886. +{
  76887. + struct usb_device *dev = urb->dev;
  76888. + int ep_num = usb_pipeendpoint(urb->pipe);
  76889. +
  76890. + if (usb_pipein(urb->pipe))
  76891. + return dev->ep_in[ep_num];
  76892. + else
  76893. + return dev->ep_out[ep_num];
  76894. +}
  76895. +
  76896. +static int _disconnect(dwc_otg_hcd_t * hcd)
  76897. +{
  76898. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76899. +
  76900. + usb_hcd->self.is_b_host = 0;
  76901. + return 0;
  76902. +}
  76903. +
  76904. +static int _start(dwc_otg_hcd_t * hcd)
  76905. +{
  76906. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76907. +
  76908. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  76909. + hcd_start(usb_hcd);
  76910. +
  76911. + return 0;
  76912. +}
  76913. +
  76914. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  76915. + uint32_t * port_addr)
  76916. +{
  76917. + struct urb *urb = (struct urb *)urb_handle;
  76918. + struct usb_bus *bus;
  76919. +#if 1 //GRAYG - temporary
  76920. + if (NULL == urb_handle)
  76921. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  76922. + if (NULL == urb->dev)
  76923. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  76924. + if (NULL == port_addr)
  76925. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  76926. +#endif
  76927. + if (urb->dev->tt) {
  76928. + if (NULL == urb->dev->tt->hub) {
  76929. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  76930. + __func__); //GRAYG
  76931. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  76932. + *hub_addr = 0; //GRAYG
  76933. + // we probably shouldn't have a transaction translator if
  76934. + // there's no associated hub?
  76935. + } else {
  76936. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  76937. + if (urb->dev->tt->hub == bus->root_hub)
  76938. + *hub_addr = 0;
  76939. + else
  76940. + *hub_addr = urb->dev->tt->hub->devnum;
  76941. + }
  76942. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  76943. + } else {
  76944. + *hub_addr = 0;
  76945. + *port_addr = urb->dev->ttport;
  76946. + }
  76947. + return 0;
  76948. +}
  76949. +
  76950. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  76951. +{
  76952. + struct urb *urb = (struct urb *)urb_handle;
  76953. + return urb->dev->speed;
  76954. +}
  76955. +
  76956. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  76957. +{
  76958. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  76959. + return usb_hcd->self.b_hnp_enable;
  76960. +}
  76961. +
  76962. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  76963. + struct urb *urb)
  76964. +{
  76965. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  76966. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76967. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  76968. + } else {
  76969. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  76970. + }
  76971. +}
  76972. +
  76973. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  76974. + struct urb *urb)
  76975. +{
  76976. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  76977. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  76978. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  76979. + } else {
  76980. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  76981. + }
  76982. +}
  76983. +
  76984. +/**
  76985. + * Sets the final status of an URB and returns it to the device driver. Any
  76986. + * required cleanup of the URB is performed. The HCD lock should be held on
  76987. + * entry.
  76988. + */
  76989. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  76990. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  76991. +{
  76992. + struct urb *urb = (struct urb *)urb_handle;
  76993. + urb_tq_entry_t *new_entry;
  76994. + int rc = 0;
  76995. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  76996. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  76997. + __func__, urb, usb_pipedevice(urb->pipe),
  76998. + usb_pipeendpoint(urb->pipe),
  76999. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  77000. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77001. + int i;
  77002. + for (i = 0; i < urb->number_of_packets; i++) {
  77003. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  77004. + i, urb->iso_frame_desc[i].status);
  77005. + }
  77006. + }
  77007. + }
  77008. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  77009. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  77010. + /* Convert status value. */
  77011. + switch (status) {
  77012. + case -DWC_E_PROTOCOL:
  77013. + status = -EPROTO;
  77014. + break;
  77015. + case -DWC_E_IN_PROGRESS:
  77016. + status = -EINPROGRESS;
  77017. + break;
  77018. + case -DWC_E_PIPE:
  77019. + status = -EPIPE;
  77020. + break;
  77021. + case -DWC_E_IO:
  77022. + status = -EIO;
  77023. + break;
  77024. + case -DWC_E_TIMEOUT:
  77025. + status = -ETIMEDOUT;
  77026. + break;
  77027. + case -DWC_E_OVERFLOW:
  77028. + status = -EOVERFLOW;
  77029. + break;
  77030. + case -DWC_E_SHUTDOWN:
  77031. + status = -ESHUTDOWN;
  77032. + break;
  77033. + default:
  77034. + if (status) {
  77035. + DWC_PRINTF("Uknown urb status %d\n", status);
  77036. +
  77037. + }
  77038. + }
  77039. +
  77040. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77041. + int i;
  77042. +
  77043. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  77044. + for (i = 0; i < urb->number_of_packets; ++i) {
  77045. + urb->iso_frame_desc[i].actual_length =
  77046. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  77047. + (dwc_otg_urb, i);
  77048. + urb->iso_frame_desc[i].status =
  77049. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  77050. + }
  77051. + }
  77052. +
  77053. + urb->status = status;
  77054. + urb->hcpriv = NULL;
  77055. + if (!status) {
  77056. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  77057. + (urb->actual_length < urb->transfer_buffer_length)) {
  77058. + urb->status = -EREMOTEIO;
  77059. + }
  77060. + }
  77061. +
  77062. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  77063. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  77064. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  77065. + if (ep) {
  77066. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  77067. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  77068. + ep->hcpriv),
  77069. + urb);
  77070. + }
  77071. + }
  77072. +
  77073. + DWC_FREE(dwc_otg_urb);
  77074. + if (!new_entry) {
  77075. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  77076. + urb->status = -EPROTO;
  77077. + /* don't schedule the tasklet -
  77078. + * directly return the packet here with error. */
  77079. +#if USB_URB_EP_LINKING
  77080. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  77081. +#endif
  77082. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77083. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  77084. +#else
  77085. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  77086. +#endif
  77087. + } else {
  77088. + new_entry->urb = urb;
  77089. +#if USB_URB_EP_LINKING
  77090. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  77091. + if(0 == rc) {
  77092. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  77093. + }
  77094. +#endif
  77095. + if(0 == rc) {
  77096. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  77097. + urb_tq_entries);
  77098. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  77099. + }
  77100. + }
  77101. + return 0;
  77102. +}
  77103. +
  77104. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  77105. + .start = _start,
  77106. + .disconnect = _disconnect,
  77107. + .hub_info = _hub_info,
  77108. + .speed = _speed,
  77109. + .complete = _complete,
  77110. + .get_b_hnp_enable = _get_b_hnp_enable,
  77111. +};
  77112. +
  77113. +static struct fiq_handler fh = {
  77114. + .name = "usb_fiq",
  77115. +};
  77116. +struct fiq_stack_s {
  77117. + int magic1;
  77118. + uint8_t stack[2048];
  77119. + int magic2;
  77120. +} fiq_stack;
  77121. +
  77122. +extern mphi_regs_t c_mphi_regs;
  77123. +/**
  77124. + * Initializes the HCD. This function allocates memory for and initializes the
  77125. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  77126. + * USB bus with the core and calls the hc_driver->start() function. It returns
  77127. + * a negative error on failure.
  77128. + */
  77129. +int hcd_init(dwc_bus_dev_t *_dev)
  77130. +{
  77131. + struct usb_hcd *hcd = NULL;
  77132. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  77133. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  77134. + int retval = 0;
  77135. + u64 dmamask;
  77136. + struct pt_regs regs;
  77137. +
  77138. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  77139. +
  77140. + /* Set device flags indicating whether the HCD supports DMA. */
  77141. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  77142. + dmamask = DMA_BIT_MASK(32);
  77143. + else
  77144. + dmamask = 0;
  77145. +
  77146. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  77147. + dma_set_mask(&_dev->dev, dmamask);
  77148. + dma_set_coherent_mask(&_dev->dev, dmamask);
  77149. +#elif defined(PCI_INTERFACE)
  77150. + pci_set_dma_mask(_dev, dmamask);
  77151. + pci_set_consistent_dma_mask(_dev, dmamask);
  77152. +#endif
  77153. +
  77154. + if (fiq_fix_enable)
  77155. + {
  77156. + // Set up fiq
  77157. + claim_fiq(&fh);
  77158. + set_fiq_handler(__FIQ_Branch, 4);
  77159. + memset(&regs,0,sizeof(regs));
  77160. + regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
  77161. + regs.ARM_r9 = (long)0;
  77162. + regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
  77163. + set_fiq_regs(&regs);
  77164. + fiq_stack.magic1 = 0xdeadbeef;
  77165. + fiq_stack.magic2 = 0xaa995566;
  77166. + }
  77167. +
  77168. + /*
  77169. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  77170. + * Initialize the base HCD.
  77171. + */
  77172. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  77173. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  77174. +#else
  77175. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  77176. + hcd->has_tt = 1;
  77177. +// hcd->uses_new_polling = 1;
  77178. +// hcd->poll_rh = 0;
  77179. +#endif
  77180. + if (!hcd) {
  77181. + retval = -ENOMEM;
  77182. + goto error1;
  77183. + }
  77184. +
  77185. + hcd->regs = otg_dev->os_dep.base;
  77186. +
  77187. + if (fiq_fix_enable)
  77188. + {
  77189. + volatile extern void *dwc_regs_base;
  77190. +
  77191. + //Set the mphi periph to the required registers
  77192. + c_mphi_regs.base = otg_dev->os_dep.mphi_base;
  77193. + c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  77194. + c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  77195. + c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  77196. + c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  77197. +
  77198. + dwc_regs_base = otg_dev->os_dep.base;
  77199. +
  77200. + //Enable mphi peripheral
  77201. + writel((1<<31),c_mphi_regs.ctrl);
  77202. +#ifdef DEBUG
  77203. + if (readl(c_mphi_regs.ctrl) & 0x80000000)
  77204. + DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
  77205. + else
  77206. + DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
  77207. +#endif
  77208. + // Enable FIQ interrupt from USB peripheral
  77209. + enable_fiq(INTERRUPT_VC_USB);
  77210. + }
  77211. + /* Initialize the DWC OTG HCD. */
  77212. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  77213. + if (!dwc_otg_hcd) {
  77214. + goto error2;
  77215. + }
  77216. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  77217. + dwc_otg_hcd;
  77218. + otg_dev->hcd = dwc_otg_hcd;
  77219. +
  77220. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  77221. + goto error2;
  77222. + }
  77223. +
  77224. + otg_dev->hcd->otg_dev = otg_dev;
  77225. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  77226. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  77227. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  77228. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  77229. +#endif
  77230. + /* Don't support SG list at this point */
  77231. + hcd->self.sg_tablesize = 0;
  77232. +#endif
  77233. + /*
  77234. + * Finish generic HCD initialization and start the HCD. This function
  77235. + * allocates the DMA buffer pool, registers the USB bus, requests the
  77236. + * IRQ line, and calls hcd_start method.
  77237. + */
  77238. +#ifdef PLATFORM_INTERFACE
  77239. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  77240. +#else
  77241. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  77242. +#endif
  77243. + if (retval < 0) {
  77244. + goto error2;
  77245. + }
  77246. +
  77247. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  77248. + return 0;
  77249. +
  77250. +error2:
  77251. + usb_put_hcd(hcd);
  77252. +error1:
  77253. + return retval;
  77254. +}
  77255. +
  77256. +/**
  77257. + * Removes the HCD.
  77258. + * Frees memory and resources associated with the HCD and deregisters the bus.
  77259. + */
  77260. +void hcd_remove(dwc_bus_dev_t *_dev)
  77261. +{
  77262. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  77263. + dwc_otg_hcd_t *dwc_otg_hcd;
  77264. + struct usb_hcd *hcd;
  77265. +
  77266. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  77267. +
  77268. + if (!otg_dev) {
  77269. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  77270. + return;
  77271. + }
  77272. +
  77273. + dwc_otg_hcd = otg_dev->hcd;
  77274. +
  77275. + if (!dwc_otg_hcd) {
  77276. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  77277. + return;
  77278. + }
  77279. +
  77280. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  77281. +
  77282. + if (!hcd) {
  77283. + DWC_DEBUGPL(DBG_ANY,
  77284. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  77285. + __func__);
  77286. + return;
  77287. + }
  77288. + usb_remove_hcd(hcd);
  77289. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  77290. + dwc_otg_hcd_remove(dwc_otg_hcd);
  77291. + usb_put_hcd(hcd);
  77292. +}
  77293. +
  77294. +/* =========================================================================
  77295. + * Linux HC Driver Functions
  77296. + * ========================================================================= */
  77297. +
  77298. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  77299. + * mode operation. Activates the root port. Returns 0 on success and a negative
  77300. + * error code on failure. */
  77301. +int hcd_start(struct usb_hcd *hcd)
  77302. +{
  77303. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77304. + struct usb_bus *bus;
  77305. +
  77306. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  77307. + bus = hcd_to_bus(hcd);
  77308. +
  77309. + hcd->state = HC_STATE_RUNNING;
  77310. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  77311. + return 0;
  77312. + }
  77313. +
  77314. + /* Initialize and connect root hub if one is not already attached */
  77315. + if (bus->root_hub) {
  77316. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  77317. + /* Inform the HUB driver to resume. */
  77318. + usb_hcd_resume_root_hub(hcd);
  77319. + }
  77320. +
  77321. + return 0;
  77322. +}
  77323. +
  77324. +/**
  77325. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  77326. + * stopped.
  77327. + */
  77328. +void hcd_stop(struct usb_hcd *hcd)
  77329. +{
  77330. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77331. +
  77332. + dwc_otg_hcd_stop(dwc_otg_hcd);
  77333. +}
  77334. +
  77335. +/** Returns the current frame number. */
  77336. +static int get_frame_number(struct usb_hcd *hcd)
  77337. +{
  77338. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77339. +
  77340. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  77341. +}
  77342. +
  77343. +#ifdef DEBUG
  77344. +static void dump_urb_info(struct urb *urb, char *fn_name)
  77345. +{
  77346. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  77347. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  77348. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  77349. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  77350. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  77351. + char *pipetype;
  77352. + switch (usb_pipetype(urb->pipe)) {
  77353. +case PIPE_CONTROL:
  77354. +pipetype = "CONTROL"; break; case PIPE_BULK:
  77355. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  77356. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  77357. +pipetype = "ISOCHRONOUS"; break; default:
  77358. + pipetype = "UNKNOWN"; break;};
  77359. + pipetype;}
  77360. + )) ;
  77361. + DWC_PRINTF(" Speed: %s\n", ( {
  77362. + char *speed; switch (urb->dev->speed) {
  77363. +case USB_SPEED_HIGH:
  77364. +speed = "HIGH"; break; case USB_SPEED_FULL:
  77365. +speed = "FULL"; break; case USB_SPEED_LOW:
  77366. +speed = "LOW"; break; default:
  77367. + speed = "UNKNOWN"; break;};
  77368. + speed;}
  77369. + )) ;
  77370. + DWC_PRINTF(" Max packet size: %d\n",
  77371. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  77372. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  77373. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  77374. + urb->transfer_buffer, (void *)urb->transfer_dma);
  77375. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  77376. + urb->setup_packet, (void *)urb->setup_dma);
  77377. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  77378. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  77379. + int i;
  77380. + for (i = 0; i < urb->number_of_packets; i++) {
  77381. + DWC_PRINTF(" ISO Desc %d:\n", i);
  77382. + DWC_PRINTF(" offset: %d, length %d\n",
  77383. + urb->iso_frame_desc[i].offset,
  77384. + urb->iso_frame_desc[i].length);
  77385. + }
  77386. + }
  77387. +}
  77388. +#endif
  77389. +
  77390. +/** Starts processing a USB transfer request specified by a USB Request Block
  77391. + * (URB). mem_flags indicates the type of memory allocation to use while
  77392. + * processing this URB. */
  77393. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  77394. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77395. + struct usb_host_endpoint *ep,
  77396. +#endif
  77397. + struct urb *urb, gfp_t mem_flags)
  77398. +{
  77399. + int retval = 0;
  77400. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  77401. + struct usb_host_endpoint *ep = urb->ep;
  77402. +#endif
  77403. + dwc_irqflags_t irqflags;
  77404. + void **ref_ep_hcpriv = &ep->hcpriv;
  77405. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77406. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  77407. + int i;
  77408. + int alloc_bandwidth = 0;
  77409. + uint8_t ep_type = 0;
  77410. + uint32_t flags = 0;
  77411. + void *buf;
  77412. +
  77413. +#ifdef DEBUG
  77414. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77415. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  77416. + }
  77417. +#endif
  77418. +
  77419. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  77420. + return -EINVAL;
  77421. +
  77422. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  77423. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  77424. + if (!dwc_otg_hcd_is_bandwidth_allocated
  77425. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  77426. + alloc_bandwidth = 1;
  77427. + }
  77428. + }
  77429. +
  77430. + switch (usb_pipetype(urb->pipe)) {
  77431. + case PIPE_CONTROL:
  77432. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  77433. + break;
  77434. + case PIPE_ISOCHRONOUS:
  77435. + ep_type = USB_ENDPOINT_XFER_ISOC;
  77436. + break;
  77437. + case PIPE_BULK:
  77438. + ep_type = USB_ENDPOINT_XFER_BULK;
  77439. + break;
  77440. + case PIPE_INTERRUPT:
  77441. + ep_type = USB_ENDPOINT_XFER_INT;
  77442. + break;
  77443. + default:
  77444. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  77445. + }
  77446. +
  77447. + /* # of packets is often 0 - do we really need to call this then? */
  77448. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  77449. + urb->number_of_packets,
  77450. + mem_flags == GFP_ATOMIC ? 1 : 0);
  77451. +
  77452. + if(dwc_otg_urb == NULL)
  77453. + return -ENOMEM;
  77454. +
  77455. + if (!dwc_otg_urb && urb->number_of_packets)
  77456. + return -ENOMEM;
  77457. +
  77458. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  77459. + usb_pipeendpoint(urb->pipe), ep_type,
  77460. + usb_pipein(urb->pipe),
  77461. + usb_maxpacket(urb->dev, urb->pipe,
  77462. + !(usb_pipein(urb->pipe))));
  77463. +
  77464. + buf = urb->transfer_buffer;
  77465. + if (hcd->self.uses_dma) {
  77466. + /*
  77467. + * Calculate virtual address from physical address,
  77468. + * because some class driver may not fill transfer_buffer.
  77469. + * In Buffer DMA mode virual address is used,
  77470. + * when handling non DWORD aligned buffers.
  77471. + */
  77472. + //buf = phys_to_virt(urb->transfer_dma);
  77473. + // DMA addresses are bus addresses not physical addresses!
  77474. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  77475. + }
  77476. +
  77477. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  77478. + flags |= URB_GIVEBACK_ASAP;
  77479. + if (urb->transfer_flags & URB_ZERO_PACKET)
  77480. + flags |= URB_SEND_ZERO_PACKET;
  77481. +
  77482. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  77483. + urb->transfer_dma,
  77484. + urb->transfer_buffer_length,
  77485. + urb->setup_packet,
  77486. + urb->setup_dma, flags, urb->interval);
  77487. +
  77488. + for (i = 0; i < urb->number_of_packets; ++i) {
  77489. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  77490. + urb->
  77491. + iso_frame_desc[i].offset,
  77492. + urb->
  77493. + iso_frame_desc[i].length);
  77494. + }
  77495. +
  77496. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  77497. + urb->hcpriv = dwc_otg_urb;
  77498. +#if USB_URB_EP_LINKING
  77499. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  77500. + if (0 == retval)
  77501. +#endif
  77502. + {
  77503. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  77504. + /*(dwc_otg_qh_t **)*/
  77505. + ref_ep_hcpriv, 1);
  77506. + if (0 == retval) {
  77507. + if (alloc_bandwidth) {
  77508. + allocate_bus_bandwidth(hcd,
  77509. + dwc_otg_hcd_get_ep_bandwidth(
  77510. + dwc_otg_hcd, *ref_ep_hcpriv),
  77511. + urb);
  77512. + }
  77513. + } else {
  77514. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  77515. +#if USB_URB_EP_LINKING
  77516. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  77517. +#endif
  77518. + DWC_FREE(dwc_otg_urb);
  77519. + urb->hcpriv = NULL;
  77520. + if (retval == -DWC_E_NO_DEVICE)
  77521. + retval = -ENODEV;
  77522. + }
  77523. + }
  77524. +#if USB_URB_EP_LINKING
  77525. + else
  77526. + {
  77527. + DWC_FREE(dwc_otg_urb);
  77528. + urb->hcpriv = NULL;
  77529. + }
  77530. +#endif
  77531. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  77532. + return retval;
  77533. +}
  77534. +
  77535. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  77536. + * success. */
  77537. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77538. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  77539. +#else
  77540. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  77541. +#endif
  77542. +{
  77543. + dwc_irqflags_t flags;
  77544. + dwc_otg_hcd_t *dwc_otg_hcd;
  77545. + int rc;
  77546. +
  77547. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  77548. +
  77549. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77550. +
  77551. +#ifdef DEBUG
  77552. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77553. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  77554. + }
  77555. +#endif
  77556. +
  77557. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  77558. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  77559. + if (0 == rc) {
  77560. + if(urb->hcpriv != NULL) {
  77561. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  77562. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  77563. +
  77564. + DWC_FREE(urb->hcpriv);
  77565. + urb->hcpriv = NULL;
  77566. + }
  77567. + }
  77568. +
  77569. + if (0 == rc) {
  77570. + /* Higher layer software sets URB status. */
  77571. +#if USB_URB_EP_LINKING
  77572. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  77573. +#endif
  77574. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  77575. +
  77576. +
  77577. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  77578. + usb_hcd_giveback_urb(hcd, urb);
  77579. +#else
  77580. + usb_hcd_giveback_urb(hcd, urb, status);
  77581. +#endif
  77582. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  77583. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  77584. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  77585. + }
  77586. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  77587. + } else {
  77588. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  77589. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  77590. + rc);
  77591. + }
  77592. +
  77593. + return rc;
  77594. +}
  77595. +
  77596. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  77597. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  77598. + * must already be dequeued. */
  77599. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  77600. +{
  77601. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77602. +
  77603. + DWC_DEBUGPL(DBG_HCD,
  77604. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  77605. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  77606. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  77607. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  77608. + ep->hcpriv = NULL;
  77609. +}
  77610. +
  77611. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  77612. +/* Resets endpoint specific parameter values, in current version used to reset
  77613. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  77614. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  77615. +{
  77616. + dwc_irqflags_t flags;
  77617. + struct usb_device *udev = NULL;
  77618. + int epnum = usb_endpoint_num(&ep->desc);
  77619. + int is_out = usb_endpoint_dir_out(&ep->desc);
  77620. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  77621. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77622. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  77623. +
  77624. + if (dev)
  77625. + udev = to_usb_device(dev);
  77626. + else
  77627. + return;
  77628. +
  77629. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  77630. +
  77631. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  77632. + usb_settoggle(udev, epnum, is_out, 0);
  77633. + if (is_control)
  77634. + usb_settoggle(udev, epnum, !is_out, 0);
  77635. +
  77636. + if (ep->hcpriv) {
  77637. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  77638. + }
  77639. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  77640. +}
  77641. +#endif
  77642. +
  77643. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  77644. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  77645. + * interrupt.
  77646. + *
  77647. + * This function is called by the USB core when an interrupt occurs */
  77648. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  77649. +{
  77650. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77651. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  77652. + if (retval != 0) {
  77653. + S3C2410X_CLEAR_EINTPEND();
  77654. + }
  77655. + return IRQ_RETVAL(retval);
  77656. +}
  77657. +
  77658. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  77659. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  77660. + * is the status change indicator for the single root port. Returns 1 if either
  77661. + * change indicator is 1, otherwise returns 0. */
  77662. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  77663. +{
  77664. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  77665. +
  77666. + buf[0] = 0;
  77667. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  77668. +
  77669. + return (buf[0] != 0);
  77670. +}
  77671. +
  77672. +/** Handles hub class-specific requests. */
  77673. +int hub_control(struct usb_hcd *hcd,
  77674. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  77675. +{
  77676. + int retval;
  77677. +
  77678. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  77679. + typeReq, wValue, wIndex, buf, wLength);
  77680. +
  77681. + switch (retval) {
  77682. + case -DWC_E_INVALID:
  77683. + retval = -EINVAL;
  77684. + break;
  77685. + }
  77686. +
  77687. + return retval;
  77688. +}
  77689. +
  77690. +#endif /* DWC_DEVICE_ONLY */
  77691. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  77692. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  77693. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-02-07 19:57:30.000000000 +0100
  77694. @@ -0,0 +1,959 @@
  77695. +/* ==========================================================================
  77696. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  77697. + * $Revision: #44 $
  77698. + * $Date: 2011/10/26 $
  77699. + * $Change: 1873028 $
  77700. + *
  77701. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  77702. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  77703. + * otherwise expressly agreed to in writing between Synopsys and you.
  77704. + *
  77705. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  77706. + * any End User Software License Agreement or Agreement for Licensed Product
  77707. + * with Synopsys or any supplement thereto. You are permitted to use and
  77708. + * redistribute this Software in source and binary forms, with or without
  77709. + * modification, provided that redistributions of source code must retain this
  77710. + * notice. You may not view, use, disclose, copy or distribute this file or
  77711. + * any information contained herein except pursuant to this license grant from
  77712. + * Synopsys. If you do not agree with this notice, including the disclaimer
  77713. + * below, then you are not authorized to use the Software.
  77714. + *
  77715. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  77716. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77717. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77718. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  77719. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  77720. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  77721. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  77722. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  77723. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  77724. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  77725. + * DAMAGE.
  77726. + * ========================================================================== */
  77727. +#ifndef DWC_DEVICE_ONLY
  77728. +
  77729. +/**
  77730. + * @file
  77731. + *
  77732. + * This file contains the functions to manage Queue Heads and Queue
  77733. + * Transfer Descriptors.
  77734. + */
  77735. +
  77736. +#include "dwc_otg_hcd.h"
  77737. +#include "dwc_otg_regs.h"
  77738. +#include "dwc_otg_mphi_fix.h"
  77739. +
  77740. +extern bool microframe_schedule;
  77741. +
  77742. +/**
  77743. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  77744. + * removed from a list. QTD list should already be empty if called from URB
  77745. + * Dequeue.
  77746. + *
  77747. + * @param hcd HCD instance.
  77748. + * @param qh The QH to free.
  77749. + */
  77750. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  77751. +{
  77752. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  77753. +
  77754. + /* Free each QTD in the QTD list */
  77755. + DWC_SPINLOCK(hcd->lock);
  77756. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  77757. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  77758. + dwc_otg_hcd_qtd_free(qtd);
  77759. + }
  77760. +
  77761. + if (hcd->core_if->dma_desc_enable) {
  77762. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  77763. + } else if (qh->dw_align_buf) {
  77764. + uint32_t buf_size;
  77765. + if (qh->ep_type == UE_ISOCHRONOUS) {
  77766. + buf_size = 4096;
  77767. + } else {
  77768. + buf_size = hcd->core_if->core_params->max_transfer_size;
  77769. + }
  77770. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  77771. + }
  77772. +
  77773. + DWC_FREE(qh);
  77774. + DWC_SPINUNLOCK(hcd->lock);
  77775. + return;
  77776. +}
  77777. +
  77778. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  77779. +#define HS_HOST_DELAY 5 /* nanoseconds */
  77780. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  77781. +#define HUB_LS_SETUP 333 /* nanoseconds */
  77782. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  77783. + /* convert & round nanoseconds to microseconds */
  77784. +
  77785. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  77786. +{
  77787. + unsigned long retval;
  77788. +
  77789. + switch (speed) {
  77790. + case USB_SPEED_HIGH:
  77791. + if (is_isoc) {
  77792. + retval =
  77793. + ((38 * 8 * 2083) +
  77794. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  77795. + HS_HOST_DELAY;
  77796. + } else {
  77797. + retval =
  77798. + ((55 * 8 * 2083) +
  77799. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  77800. + HS_HOST_DELAY;
  77801. + }
  77802. + break;
  77803. + case USB_SPEED_FULL:
  77804. + if (is_isoc) {
  77805. + retval =
  77806. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  77807. + if (is_in) {
  77808. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  77809. + } else {
  77810. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  77811. + }
  77812. + } else {
  77813. + retval =
  77814. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  77815. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  77816. + }
  77817. + break;
  77818. + case USB_SPEED_LOW:
  77819. + if (is_in) {
  77820. + retval =
  77821. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  77822. + 1000;
  77823. + retval =
  77824. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  77825. + retval;
  77826. + } else {
  77827. + retval =
  77828. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  77829. + 1000;
  77830. + retval =
  77831. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  77832. + retval;
  77833. + }
  77834. + break;
  77835. + default:
  77836. + DWC_WARN("Unknown device speed\n");
  77837. + retval = -1;
  77838. + }
  77839. +
  77840. + return NS_TO_US(retval);
  77841. +}
  77842. +
  77843. +/**
  77844. + * Initializes a QH structure.
  77845. + *
  77846. + * @param hcd The HCD state structure for the DWC OTG controller.
  77847. + * @param qh The QH to init.
  77848. + * @param urb Holds the information about the device/endpoint that we need
  77849. + * to initialize the QH.
  77850. + */
  77851. +#define SCHEDULE_SLOP 10
  77852. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  77853. +{
  77854. + char *speed, *type;
  77855. + int dev_speed;
  77856. + uint32_t hub_addr, hub_port;
  77857. +
  77858. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  77859. +
  77860. + /* Initialize QH */
  77861. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77862. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  77863. +
  77864. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  77865. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  77866. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  77867. + DWC_LIST_INIT(&qh->qh_list_entry);
  77868. + qh->channel = NULL;
  77869. +
  77870. + /* FS/LS Enpoint on HS Hub
  77871. + * NOT virtual root hub */
  77872. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  77873. +
  77874. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  77875. + qh->do_split = 0;
  77876. + if (microframe_schedule)
  77877. + qh->speed = dev_speed;
  77878. +
  77879. + qh->nak_frame = 0xffff;
  77880. +
  77881. + if (((dev_speed == USB_SPEED_LOW) ||
  77882. + (dev_speed == USB_SPEED_FULL)) &&
  77883. + (hub_addr != 0 && hub_addr != 1)) {
  77884. + DWC_DEBUGPL(DBG_HCD,
  77885. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  77886. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  77887. + hub_port);
  77888. + qh->do_split = 1;
  77889. + qh->skip_count = 0;
  77890. + }
  77891. +
  77892. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  77893. + /* Compute scheduling parameters once and save them. */
  77894. + hprt0_data_t hprt;
  77895. +
  77896. + /** @todo Account for split transfers in the bus time. */
  77897. + int bytecount =
  77898. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  77899. +
  77900. + qh->usecs =
  77901. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  77902. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  77903. + bytecount);
  77904. + /* Start in a slightly future (micro)frame. */
  77905. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  77906. + SCHEDULE_SLOP);
  77907. + qh->interval = urb->interval;
  77908. +
  77909. +#if 0
  77910. + /* Increase interrupt polling rate for debugging. */
  77911. + if (qh->ep_type == UE_INTERRUPT) {
  77912. + qh->interval = 8;
  77913. + }
  77914. +#endif
  77915. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  77916. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  77917. + ((dev_speed == USB_SPEED_LOW) ||
  77918. + (dev_speed == USB_SPEED_FULL))) {
  77919. + qh->interval *= 8;
  77920. + qh->sched_frame |= 0x7;
  77921. + qh->start_split_frame = qh->sched_frame;
  77922. + }
  77923. +
  77924. + }
  77925. +
  77926. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  77927. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  77928. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  77929. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  77930. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  77931. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  77932. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  77933. + switch (dev_speed) {
  77934. + case USB_SPEED_LOW:
  77935. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  77936. + speed = "low";
  77937. + break;
  77938. + case USB_SPEED_FULL:
  77939. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  77940. + speed = "full";
  77941. + break;
  77942. + case USB_SPEED_HIGH:
  77943. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  77944. + speed = "high";
  77945. + break;
  77946. + default:
  77947. + speed = "?";
  77948. + break;
  77949. + }
  77950. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  77951. +
  77952. + switch (qh->ep_type) {
  77953. + case UE_ISOCHRONOUS:
  77954. + type = "isochronous";
  77955. + break;
  77956. + case UE_INTERRUPT:
  77957. + type = "interrupt";
  77958. + break;
  77959. + case UE_CONTROL:
  77960. + type = "control";
  77961. + break;
  77962. + case UE_BULK:
  77963. + type = "bulk";
  77964. + break;
  77965. + default:
  77966. + type = "?";
  77967. + break;
  77968. + }
  77969. +
  77970. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  77971. +
  77972. +#ifdef DEBUG
  77973. + if (qh->ep_type == UE_INTERRUPT) {
  77974. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  77975. + qh->usecs);
  77976. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  77977. + qh->interval);
  77978. + }
  77979. +#endif
  77980. +
  77981. +}
  77982. +
  77983. +/**
  77984. + * This function allocates and initializes a QH.
  77985. + *
  77986. + * @param hcd The HCD state structure for the DWC OTG controller.
  77987. + * @param urb Holds the information about the device/endpoint that we need
  77988. + * to initialize the QH.
  77989. + * @param atomic_alloc Flag to do atomic allocation if needed
  77990. + *
  77991. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  77992. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  77993. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  77994. +{
  77995. + dwc_otg_qh_t *qh;
  77996. +
  77997. + /* Allocate memory */
  77998. + /** @todo add memflags argument */
  77999. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  78000. + if (qh == NULL) {
  78001. + DWC_ERROR("qh allocation failed");
  78002. + return NULL;
  78003. + }
  78004. +
  78005. + qh_init(hcd, qh, urb);
  78006. +
  78007. + if (hcd->core_if->dma_desc_enable
  78008. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  78009. + dwc_otg_hcd_qh_free(hcd, qh);
  78010. + return NULL;
  78011. + }
  78012. +
  78013. + return qh;
  78014. +}
  78015. +
  78016. +/* microframe_schedule=0 start */
  78017. +
  78018. +/**
  78019. + * Checks that a channel is available for a periodic transfer.
  78020. + *
  78021. + * @return 0 if successful, negative error code otherise.
  78022. + */
  78023. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  78024. +{
  78025. + /*
  78026. + * Currently assuming that there is a dedicated host channnel for each
  78027. + * periodic transaction plus at least one host channel for
  78028. + * non-periodic transactions.
  78029. + */
  78030. + int status;
  78031. + int num_channels;
  78032. +
  78033. + num_channels = hcd->core_if->core_params->host_channels;
  78034. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  78035. + && (hcd->periodic_channels < num_channels - 1)) {
  78036. + status = 0;
  78037. + } else {
  78038. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  78039. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  78040. + status = -DWC_E_NO_SPACE;
  78041. + }
  78042. +
  78043. + return status;
  78044. +}
  78045. +
  78046. +/**
  78047. + * Checks that there is sufficient bandwidth for the specified QH in the
  78048. + * periodic schedule. For simplicity, this calculation assumes that all the
  78049. + * transfers in the periodic schedule may occur in the same (micro)frame.
  78050. + *
  78051. + * @param hcd The HCD state structure for the DWC OTG controller.
  78052. + * @param qh QH containing periodic bandwidth required.
  78053. + *
  78054. + * @return 0 if successful, negative error code otherwise.
  78055. + */
  78056. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78057. +{
  78058. + int status;
  78059. + int16_t max_claimed_usecs;
  78060. +
  78061. + status = 0;
  78062. +
  78063. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  78064. + /*
  78065. + * High speed mode.
  78066. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  78067. + */
  78068. +
  78069. + max_claimed_usecs = 100 - qh->usecs;
  78070. + } else {
  78071. + /*
  78072. + * Full speed mode.
  78073. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  78074. + */
  78075. + max_claimed_usecs = 900 - qh->usecs;
  78076. + }
  78077. +
  78078. + if (hcd->periodic_usecs > max_claimed_usecs) {
  78079. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  78080. + status = -DWC_E_NO_SPACE;
  78081. + }
  78082. +
  78083. + return status;
  78084. +}
  78085. +
  78086. +/* microframe_schedule=0 end */
  78087. +
  78088. +/**
  78089. + * Microframe scheduler
  78090. + * track the total use in hcd->frame_usecs
  78091. + * keep each qh use in qh->frame_usecs
  78092. + * when surrendering the qh then donate the time back
  78093. + */
  78094. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  78095. +
  78096. +/*
  78097. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  78098. + */
  78099. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  78100. +{
  78101. + int i;
  78102. + for (i=0; i<8; i++) {
  78103. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  78104. + }
  78105. + return 0;
  78106. +}
  78107. +
  78108. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78109. +{
  78110. + int i;
  78111. + unsigned short utime;
  78112. + int t_left;
  78113. + int ret;
  78114. + int done;
  78115. +
  78116. + ret = -1;
  78117. + utime = _qh->usecs;
  78118. + t_left = utime;
  78119. + i = 0;
  78120. + done = 0;
  78121. + while (done == 0) {
  78122. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  78123. + if (utime <= _hcd->frame_usecs[i]) {
  78124. + _hcd->frame_usecs[i] -= utime;
  78125. + _qh->frame_usecs[i] += utime;
  78126. + t_left -= utime;
  78127. + ret = i;
  78128. + done = 1;
  78129. + return ret;
  78130. + } else {
  78131. + i++;
  78132. + if (i == 8) {
  78133. + done = 1;
  78134. + ret = -1;
  78135. + }
  78136. + }
  78137. + }
  78138. + return ret;
  78139. + }
  78140. +
  78141. +/*
  78142. + * use this for FS apps that can span multiple uframes
  78143. + */
  78144. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78145. +{
  78146. + int i;
  78147. + int j;
  78148. + unsigned short utime;
  78149. + int t_left;
  78150. + int ret;
  78151. + int done;
  78152. + unsigned short xtime;
  78153. +
  78154. + ret = -1;
  78155. + utime = _qh->usecs;
  78156. + t_left = utime;
  78157. + i = 0;
  78158. + done = 0;
  78159. +loop:
  78160. + while (done == 0) {
  78161. + if(_hcd->frame_usecs[i] <= 0) {
  78162. + i++;
  78163. + if (i == 8) {
  78164. + done = 1;
  78165. + ret = -1;
  78166. + }
  78167. + goto loop;
  78168. + }
  78169. +
  78170. + /*
  78171. + * we need n consecutive slots
  78172. + * so use j as a start slot j plus j+1 must be enough time (for now)
  78173. + */
  78174. + xtime= _hcd->frame_usecs[i];
  78175. + for (j = i+1 ; j < 8 ; j++ ) {
  78176. + /*
  78177. + * if we add this frame remaining time to xtime we may
  78178. + * be OK, if not we need to test j for a complete frame
  78179. + */
  78180. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  78181. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  78182. + j = 8;
  78183. + ret = -1;
  78184. + continue;
  78185. + }
  78186. + }
  78187. + if (xtime >= utime) {
  78188. + ret = i;
  78189. + j = 8; /* stop loop with a good value ret */
  78190. + continue;
  78191. + }
  78192. + /* add the frame time to x time */
  78193. + xtime += _hcd->frame_usecs[j];
  78194. + /* we must have a fully available next frame or break */
  78195. + if ((xtime < utime)
  78196. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  78197. + ret = -1;
  78198. + j = 8; /* stop loop with a bad value ret */
  78199. + continue;
  78200. + }
  78201. + }
  78202. + if (ret >= 0) {
  78203. + t_left = utime;
  78204. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  78205. + t_left -= _hcd->frame_usecs[j];
  78206. + if ( t_left <= 0 ) {
  78207. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  78208. + _hcd->frame_usecs[j]= -t_left;
  78209. + ret = i;
  78210. + done = 1;
  78211. + } else {
  78212. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  78213. + _hcd->frame_usecs[j] = 0;
  78214. + }
  78215. + }
  78216. + } else {
  78217. + i++;
  78218. + if (i == 8) {
  78219. + done = 1;
  78220. + ret = -1;
  78221. + }
  78222. + }
  78223. + }
  78224. + return ret;
  78225. +}
  78226. +
  78227. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  78228. +{
  78229. + int ret;
  78230. + ret = -1;
  78231. +
  78232. + if (_qh->speed == USB_SPEED_HIGH) {
  78233. + /* if this is a hs transaction we need a full frame */
  78234. + ret = find_single_uframe(_hcd, _qh);
  78235. + } else {
  78236. + /* if this is a fs transaction we may need a sequence of frames */
  78237. + ret = find_multi_uframe(_hcd, _qh);
  78238. + }
  78239. + return ret;
  78240. +}
  78241. +
  78242. +/**
  78243. + * Checks that the max transfer size allowed in a host channel is large enough
  78244. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  78245. + * transfer.
  78246. + *
  78247. + * @param hcd The HCD state structure for the DWC OTG controller.
  78248. + * @param qh QH for a periodic endpoint.
  78249. + *
  78250. + * @return 0 if successful, negative error code otherwise.
  78251. + */
  78252. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78253. +{
  78254. + int status;
  78255. + uint32_t max_xfer_size;
  78256. + uint32_t max_channel_xfer_size;
  78257. +
  78258. + status = 0;
  78259. +
  78260. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  78261. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  78262. +
  78263. + if (max_xfer_size > max_channel_xfer_size) {
  78264. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  78265. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  78266. + status = -DWC_E_NO_SPACE;
  78267. + }
  78268. +
  78269. + return status;
  78270. +}
  78271. +
  78272. +
  78273. +extern int g_next_sched_frame, g_np_count, g_np_sent;
  78274. +
  78275. +/**
  78276. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  78277. + *
  78278. + * @param hcd The HCD state structure for the DWC OTG controller.
  78279. + * @param qh QH for the periodic transfer. The QH should already contain the
  78280. + * scheduling information.
  78281. + *
  78282. + * @return 0 if successful, negative error code otherwise.
  78283. + */
  78284. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78285. +{
  78286. + int status = 0;
  78287. +
  78288. + if (microframe_schedule) {
  78289. + int frame;
  78290. + status = find_uframe(hcd, qh);
  78291. + frame = -1;
  78292. + if (status == 0) {
  78293. + frame = 7;
  78294. + } else {
  78295. + if (status > 0 )
  78296. + frame = status-1;
  78297. + }
  78298. +
  78299. + /* Set the new frame up */
  78300. + if (frame > -1) {
  78301. + qh->sched_frame &= ~0x7;
  78302. + qh->sched_frame |= (frame & 7);
  78303. + }
  78304. +
  78305. + if (status != -1)
  78306. + status = 0;
  78307. + } else {
  78308. + status = periodic_channel_available(hcd);
  78309. + if (status) {
  78310. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  78311. + return status;
  78312. + }
  78313. +
  78314. + status = check_periodic_bandwidth(hcd, qh);
  78315. + }
  78316. + if (status) {
  78317. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  78318. + "periodic transfer.\n", __func__);
  78319. + return status;
  78320. + }
  78321. + status = check_max_xfer_size(hcd, qh);
  78322. + if (status) {
  78323. + DWC_INFO("%s: Channel max transfer size too small "
  78324. + "for periodic transfer.\n", __func__);
  78325. + return status;
  78326. + }
  78327. +
  78328. + if (hcd->core_if->dma_desc_enable) {
  78329. + /* Don't rely on SOF and start in ready schedule */
  78330. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  78331. + }
  78332. + else {
  78333. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
  78334. + {
  78335. + g_next_sched_frame = qh->sched_frame;
  78336. +
  78337. + }
  78338. + /* Always start in the inactive schedule. */
  78339. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  78340. + }
  78341. +
  78342. + if (!microframe_schedule) {
  78343. + /* Reserve the periodic channel. */
  78344. + hcd->periodic_channels++;
  78345. + }
  78346. +
  78347. + /* Update claimed usecs per (micro)frame. */
  78348. + hcd->periodic_usecs += qh->usecs;
  78349. +
  78350. + return status;
  78351. +}
  78352. +
  78353. +
  78354. +/**
  78355. + * This function adds a QH to either the non periodic or periodic schedule if
  78356. + * it is not already in the schedule. If the QH is already in the schedule, no
  78357. + * action is taken.
  78358. + *
  78359. + * @return 0 if successful, negative error code otherwise.
  78360. + */
  78361. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78362. +{
  78363. + int status = 0;
  78364. + gintmsk_data_t intr_mask = {.d32 = 0 };
  78365. +
  78366. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  78367. + /* QH already in a schedule. */
  78368. + return status;
  78369. + }
  78370. +
  78371. + /* Add the new QH to the appropriate schedule */
  78372. + if (dwc_qh_is_non_per(qh)) {
  78373. + /* Always start in the inactive schedule. */
  78374. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  78375. + &qh->qh_list_entry);
  78376. + g_np_count++;
  78377. + } else {
  78378. + status = schedule_periodic(hcd, qh);
  78379. + if ( !hcd->periodic_qh_count ) {
  78380. + intr_mask.b.sofintr = 1;
  78381. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  78382. + intr_mask.d32, intr_mask.d32);
  78383. + }
  78384. + hcd->periodic_qh_count++;
  78385. + }
  78386. +
  78387. + return status;
  78388. +}
  78389. +
  78390. +/**
  78391. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  78392. + *
  78393. + * @param hcd The HCD state structure for the DWC OTG controller.
  78394. + * @param qh QH for the periodic transfer.
  78395. + */
  78396. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78397. +{
  78398. + int i;
  78399. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  78400. +
  78401. + /* Update claimed usecs per (micro)frame. */
  78402. + hcd->periodic_usecs -= qh->usecs;
  78403. +
  78404. + if (!microframe_schedule) {
  78405. + /* Release the periodic channel reservation. */
  78406. + hcd->periodic_channels--;
  78407. + } else {
  78408. + for (i = 0; i < 8; i++) {
  78409. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  78410. + qh->frame_usecs[i] = 0;
  78411. + }
  78412. + }
  78413. +}
  78414. +
  78415. +/**
  78416. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  78417. + * not freed.
  78418. + *
  78419. + * @param hcd The HCD state structure.
  78420. + * @param qh QH to remove from schedule. */
  78421. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  78422. +{
  78423. + gintmsk_data_t intr_mask = {.d32 = 0 };
  78424. +
  78425. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  78426. + /* QH is not in a schedule. */
  78427. + return;
  78428. + }
  78429. +
  78430. + if (dwc_qh_is_non_per(qh)) {
  78431. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  78432. + hcd->non_periodic_qh_ptr =
  78433. + hcd->non_periodic_qh_ptr->next;
  78434. + }
  78435. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  78436. +
  78437. + // If we've removed the last non-periodic entry then there are none left!
  78438. + g_np_count = g_np_sent;
  78439. + } else {
  78440. + deschedule_periodic(hcd, qh);
  78441. + hcd->periodic_qh_count--;
  78442. + if( !hcd->periodic_qh_count ) {
  78443. + intr_mask.b.sofintr = 1;
  78444. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  78445. + intr_mask.d32, 0);
  78446. + }
  78447. + }
  78448. +}
  78449. +
  78450. +/**
  78451. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  78452. + * non-periodic schedule. The QH is added to the inactive non-periodic
  78453. + * schedule if any QTDs are still attached to the QH.
  78454. + *
  78455. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  78456. + * there are any QTDs still attached to the QH, the QH is added to either the
  78457. + * periodic inactive schedule or the periodic ready schedule and its next
  78458. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  78459. + * the scheduled frame has been reached already. Otherwise it's placed in the
  78460. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  78461. + * completely removed from the periodic schedule.
  78462. + */
  78463. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  78464. + int sched_next_periodic_split)
  78465. +{
  78466. + if (dwc_qh_is_non_per(qh)) {
  78467. +
  78468. + dwc_otg_qh_t *qh_tmp;
  78469. + dwc_list_link_t *qh_list;
  78470. + DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
  78471. + {
  78472. + qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
  78473. + if(qh_tmp == qh)
  78474. + {
  78475. + /*
  78476. + * FIQ is being disabled because this one nevers gets a np_count increment
  78477. + * This is still not absolutely correct, but it should fix itself with
  78478. + * just an unnecessary extra interrupt
  78479. + */
  78480. + g_np_sent = g_np_count;
  78481. + }
  78482. + }
  78483. +
  78484. +
  78485. + dwc_otg_hcd_qh_remove(hcd, qh);
  78486. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  78487. + /* Add back to inactive non-periodic schedule. */
  78488. + dwc_otg_hcd_qh_add(hcd, qh);
  78489. + }
  78490. + } else {
  78491. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  78492. +
  78493. + if (qh->do_split) {
  78494. + /* Schedule the next continuing periodic split transfer */
  78495. + if (sched_next_periodic_split) {
  78496. +
  78497. + qh->sched_frame = frame_number;
  78498. +
  78499. + if (dwc_frame_num_le(frame_number,
  78500. + dwc_frame_num_inc
  78501. + (qh->start_split_frame,
  78502. + 1))) {
  78503. + /*
  78504. + * Allow one frame to elapse after start
  78505. + * split microframe before scheduling
  78506. + * complete split, but DONT if we are
  78507. + * doing the next start split in the
  78508. + * same frame for an ISOC out.
  78509. + */
  78510. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  78511. + (qh->ep_is_in != 0)) {
  78512. + qh->sched_frame =
  78513. + dwc_frame_num_inc(qh->sched_frame, 1);
  78514. + }
  78515. + }
  78516. + } else {
  78517. + qh->sched_frame =
  78518. + dwc_frame_num_inc(qh->start_split_frame,
  78519. + qh->interval);
  78520. + if (dwc_frame_num_le
  78521. + (qh->sched_frame, frame_number)) {
  78522. + qh->sched_frame = frame_number;
  78523. + }
  78524. + qh->sched_frame |= 0x7;
  78525. + qh->start_split_frame = qh->sched_frame;
  78526. + }
  78527. + } else {
  78528. + qh->sched_frame =
  78529. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  78530. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  78531. + qh->sched_frame = frame_number;
  78532. + }
  78533. + }
  78534. +
  78535. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  78536. + dwc_otg_hcd_qh_remove(hcd, qh);
  78537. + } else {
  78538. + /*
  78539. + * Remove from periodic_sched_queued and move to
  78540. + * appropriate queue.
  78541. + */
  78542. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  78543. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  78544. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  78545. + &qh->qh_list_entry);
  78546. + } else {
  78547. + if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
  78548. + {
  78549. + g_next_sched_frame = qh->sched_frame;
  78550. + }
  78551. +
  78552. + DWC_LIST_MOVE_HEAD
  78553. + (&hcd->periodic_sched_inactive,
  78554. + &qh->qh_list_entry);
  78555. + }
  78556. + }
  78557. + }
  78558. +}
  78559. +
  78560. +/**
  78561. + * This function allocates and initializes a QTD.
  78562. + *
  78563. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  78564. + * pointing to each other so each pair should have a unique correlation.
  78565. + * @param atomic_alloc Flag to do atomic alloc if needed
  78566. + *
  78567. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  78568. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  78569. +{
  78570. + dwc_otg_qtd_t *qtd;
  78571. +
  78572. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  78573. + if (qtd == NULL) {
  78574. + return NULL;
  78575. + }
  78576. +
  78577. + dwc_otg_hcd_qtd_init(qtd, urb);
  78578. + return qtd;
  78579. +}
  78580. +
  78581. +/**
  78582. + * Initializes a QTD structure.
  78583. + *
  78584. + * @param qtd The QTD to initialize.
  78585. + * @param urb The URB to use for initialization. */
  78586. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  78587. +{
  78588. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  78589. + qtd->urb = urb;
  78590. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  78591. + /*
  78592. + * The only time the QTD data toggle is used is on the data
  78593. + * phase of control transfers. This phase always starts with
  78594. + * DATA1.
  78595. + */
  78596. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  78597. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  78598. + }
  78599. +
  78600. + /* start split */
  78601. + qtd->complete_split = 0;
  78602. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  78603. + qtd->isoc_split_offset = 0;
  78604. + qtd->in_process = 0;
  78605. +
  78606. + /* Store the qtd ptr in the urb to reference what QTD. */
  78607. + urb->qtd = qtd;
  78608. + return;
  78609. +}
  78610. +
  78611. +/**
  78612. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  78613. + * QH to place the QTD into. If it does not find a QH, then it will create a
  78614. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  78615. + * is placed into the proper schedule based on its EP type.
  78616. + * HCD lock must be held and interrupts must be disabled on entry
  78617. + *
  78618. + * @param[in] qtd The QTD to add
  78619. + * @param[in] hcd The DWC HCD structure
  78620. + * @param[out] qh out parameter to return queue head
  78621. + * @param atomic_alloc Flag to do atomic alloc if needed
  78622. + *
  78623. + * @return 0 if successful, negative error code otherwise.
  78624. + */
  78625. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  78626. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  78627. +{
  78628. + int retval = 0;
  78629. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  78630. +
  78631. + /*
  78632. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  78633. + * doesn't exist.
  78634. + */
  78635. + if (*qh == NULL) {
  78636. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  78637. + if (*qh == NULL) {
  78638. + retval = -DWC_E_NO_MEMORY;
  78639. + goto done;
  78640. + }
  78641. + }
  78642. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  78643. + if (retval == 0) {
  78644. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  78645. + qtd_list_entry);
  78646. + qtd->qh = *qh;
  78647. + }
  78648. +done:
  78649. +
  78650. + return retval;
  78651. +}
  78652. +
  78653. +#endif /* DWC_DEVICE_ONLY */
  78654. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  78655. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 1970-01-01 01:00:00.000000000 +0100
  78656. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c 2014-02-07 19:57:30.000000000 +0100
  78657. @@ -0,0 +1,113 @@
  78658. +#include "dwc_otg_regs.h"
  78659. +#include "dwc_otg_dbg.h"
  78660. +
  78661. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
  78662. +{
  78663. + DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
  78664. + "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
  78665. + "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
  78666. + "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
  78667. + "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
  78668. + "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
  78669. + "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
  78670. + "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
  78671. + "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  78672. + function_name,
  78673. + gintsts.b.curmode,
  78674. + gintsts.b.modemismatch,
  78675. + gintsts.b.otgintr,
  78676. + gintsts.b.sofintr,
  78677. + gintsts.b.rxstsqlvl,
  78678. + gintsts.b.nptxfempty,
  78679. + gintsts.b.ginnakeff,
  78680. + gintsts.b.goutnakeff,
  78681. + gintsts.b.ulpickint,
  78682. + gintsts.b.i2cintr,
  78683. + gintsts.b.erlysuspend,
  78684. + gintsts.b.usbsuspend,
  78685. + gintsts.b.usbreset,
  78686. + gintsts.b.enumdone,
  78687. + gintsts.b.isooutdrop,
  78688. + gintsts.b.eopframe,
  78689. + gintsts.b.restoredone,
  78690. + gintsts.b.epmismatch,
  78691. + gintsts.b.inepint,
  78692. + gintsts.b.outepintr,
  78693. + gintsts.b.incomplisoin,
  78694. + gintsts.b.incomplisoout,
  78695. + gintsts.b.fetsusp,
  78696. + gintsts.b.resetdet,
  78697. + gintsts.b.portintr,
  78698. + gintsts.b.hcintr,
  78699. + gintsts.b.ptxfempty,
  78700. + gintsts.b.lpmtranrcvd,
  78701. + gintsts.b.conidstschng,
  78702. + gintsts.b.disconnect,
  78703. + gintsts.b.sessreqintr,
  78704. + gintsts.b.wkupintr);
  78705. + return;
  78706. +}
  78707. +
  78708. +void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
  78709. +{
  78710. + DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
  78711. + "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
  78712. + "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
  78713. + "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
  78714. + "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
  78715. + "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
  78716. + "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
  78717. + "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
  78718. + "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  78719. + function_name,
  78720. + gintmsk.b.modemismatch,
  78721. + gintmsk.b.otgintr,
  78722. + gintmsk.b.sofintr,
  78723. + gintmsk.b.rxstsqlvl,
  78724. + gintmsk.b.nptxfempty,
  78725. + gintmsk.b.ginnakeff,
  78726. + gintmsk.b.goutnakeff,
  78727. + gintmsk.b.ulpickint,
  78728. + gintmsk.b.i2cintr,
  78729. + gintmsk.b.erlysuspend,
  78730. + gintmsk.b.usbsuspend,
  78731. + gintmsk.b.usbreset,
  78732. + gintmsk.b.enumdone,
  78733. + gintmsk.b.isooutdrop,
  78734. + gintmsk.b.eopframe,
  78735. + gintmsk.b.restoredone,
  78736. + gintmsk.b.epmismatch,
  78737. + gintmsk.b.inepintr,
  78738. + gintmsk.b.outepintr,
  78739. + gintmsk.b.incomplisoin,
  78740. + gintmsk.b.incomplisoout,
  78741. + gintmsk.b.fetsusp,
  78742. + gintmsk.b.resetdet,
  78743. + gintmsk.b.portintr,
  78744. + gintmsk.b.hcintr,
  78745. + gintmsk.b.ptxfempty,
  78746. + gintmsk.b.lpmtranrcvd,
  78747. + gintmsk.b.conidstschng,
  78748. + gintmsk.b.disconnect,
  78749. + gintmsk.b.sessreqintr,
  78750. + gintmsk.b.wkupintr);
  78751. + return;
  78752. +}
  78753. +
  78754. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
  78755. +{
  78756. + DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
  78757. + "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
  78758. + "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
  78759. + "mvic: %1i\n",
  78760. + function_name,
  78761. + gotgint.b.sesenddet,
  78762. + gotgint.b.sesreqsucstschng,
  78763. + gotgint.b.hstnegsucstschng,
  78764. + gotgint.b.hstnegdet,
  78765. + gotgint.b.adevtoutchng,
  78766. + gotgint.b.debdone,
  78767. + gotgint.b.mvic);
  78768. +
  78769. + return;
  78770. +}
  78771. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  78772. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 1970-01-01 01:00:00.000000000 +0100
  78773. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h 2014-02-07 19:57:30.000000000 +0100
  78774. @@ -0,0 +1,48 @@
  78775. +#ifndef __DWC_OTG_MPHI_FIX_H__
  78776. +#define __DWC_OTG_MPHI_FIX_H__
  78777. +#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
  78778. +#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
  78779. +
  78780. +typedef struct {
  78781. + volatile void* base;
  78782. + volatile void* ctrl;
  78783. + volatile void* outdda;
  78784. + volatile void* outddb;
  78785. + volatile void* intstat;
  78786. +} mphi_regs_t;
  78787. +
  78788. +void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
  78789. +void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
  78790. +void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
  78791. +
  78792. +extern gintsts_data_t gintsts_saved;
  78793. +
  78794. +#ifdef DEBUG
  78795. +#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
  78796. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
  78797. +#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
  78798. +
  78799. +#else
  78800. +#define DWC_DBG_PRINT_CORE_INT(_arg_)
  78801. +#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
  78802. +#define DWC_DBG_PRINT_OTG_INT(_arg_)
  78803. +
  78804. +#endif
  78805. +
  78806. +typedef enum {
  78807. + FIQDBG_SCHED = (1 << 0),
  78808. + FIQDBG_INT = (1 << 1),
  78809. + FIQDBG_ERR = (1 << 2),
  78810. + FIQDBG_PORTHUB = (1 << 3),
  78811. +} FIQDBG_T;
  78812. +
  78813. +void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
  78814. +#ifdef FIQ_DEBUG
  78815. +#define fiq_print _fiq_print
  78816. +#else
  78817. +#define fiq_print(x, y, ...)
  78818. +#endif
  78819. +
  78820. +extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
  78821. +
  78822. +#endif
  78823. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  78824. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  78825. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-02-07 19:57:30.000000000 +0100
  78826. @@ -0,0 +1,188 @@
  78827. +#ifndef _DWC_OS_DEP_H_
  78828. +#define _DWC_OS_DEP_H_
  78829. +
  78830. +/**
  78831. + * @file
  78832. + *
  78833. + * This file contains OS dependent structures.
  78834. + *
  78835. + */
  78836. +
  78837. +#include <linux/kernel.h>
  78838. +#include <linux/module.h>
  78839. +#include <linux/moduleparam.h>
  78840. +#include <linux/init.h>
  78841. +#include <linux/device.h>
  78842. +#include <linux/errno.h>
  78843. +#include <linux/types.h>
  78844. +#include <linux/slab.h>
  78845. +#include <linux/list.h>
  78846. +#include <linux/interrupt.h>
  78847. +#include <linux/ctype.h>
  78848. +#include <linux/string.h>
  78849. +#include <linux/dma-mapping.h>
  78850. +#include <linux/jiffies.h>
  78851. +#include <linux/delay.h>
  78852. +#include <linux/timer.h>
  78853. +#include <linux/workqueue.h>
  78854. +#include <linux/stat.h>
  78855. +#include <linux/pci.h>
  78856. +
  78857. +#include <linux/version.h>
  78858. +
  78859. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  78860. +# include <linux/irq.h>
  78861. +#endif
  78862. +
  78863. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  78864. +# include <linux/usb/ch9.h>
  78865. +#else
  78866. +# include <linux/usb_ch9.h>
  78867. +#endif
  78868. +
  78869. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  78870. +# include <linux/usb/gadget.h>
  78871. +#else
  78872. +# include <linux/usb_gadget.h>
  78873. +#endif
  78874. +
  78875. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  78876. +# include <asm/irq.h>
  78877. +#endif
  78878. +
  78879. +#ifdef PCI_INTERFACE
  78880. +# include <asm/io.h>
  78881. +#endif
  78882. +
  78883. +#ifdef LM_INTERFACE
  78884. +# include <asm/unaligned.h>
  78885. +# include <asm/sizes.h>
  78886. +# include <asm/param.h>
  78887. +# include <asm/io.h>
  78888. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  78889. +# include <asm/arch/hardware.h>
  78890. +# include <asm/arch/lm.h>
  78891. +# include <asm/arch/irqs.h>
  78892. +# include <asm/arch/regs-irq.h>
  78893. +# else
  78894. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  78895. + here we assume that the machine architecture provides definitions
  78896. + in its own header
  78897. +*/
  78898. +# include <mach/lm.h>
  78899. +# include <mach/hardware.h>
  78900. +# endif
  78901. +#endif
  78902. +
  78903. +#ifdef PLATFORM_INTERFACE
  78904. +#include <linux/platform_device.h>
  78905. +#include <asm/mach/map.h>
  78906. +#endif
  78907. +
  78908. +/** The OS page size */
  78909. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  78910. +
  78911. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  78912. +typedef int gfp_t;
  78913. +#endif
  78914. +
  78915. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  78916. +# define IRQF_SHARED SA_SHIRQ
  78917. +#endif
  78918. +
  78919. +typedef struct os_dependent {
  78920. + /** Base address returned from ioremap() */
  78921. + void *base;
  78922. +
  78923. + /** Register offset for Diagnostic API */
  78924. + uint32_t reg_offset;
  78925. +
  78926. + /** Base address for MPHI peripheral */
  78927. + void *mphi_base;
  78928. +
  78929. +#ifdef LM_INTERFACE
  78930. + struct lm_device *lmdev;
  78931. +#elif defined(PCI_INTERFACE)
  78932. + struct pci_dev *pcidev;
  78933. +
  78934. + /** Start address of a PCI region */
  78935. + resource_size_t rsrc_start;
  78936. +
  78937. + /** Length address of a PCI region */
  78938. + resource_size_t rsrc_len;
  78939. +#elif defined(PLATFORM_INTERFACE)
  78940. + struct platform_device *platformdev;
  78941. +#endif
  78942. +
  78943. +} os_dependent_t;
  78944. +
  78945. +#ifdef __cplusplus
  78946. +}
  78947. +#endif
  78948. +
  78949. +
  78950. +
  78951. +/* Type for the our device on the chosen bus */
  78952. +#if defined(LM_INTERFACE)
  78953. +typedef struct lm_device dwc_bus_dev_t;
  78954. +#elif defined(PCI_INTERFACE)
  78955. +typedef struct pci_dev dwc_bus_dev_t;
  78956. +#elif defined(PLATFORM_INTERFACE)
  78957. +typedef struct platform_device dwc_bus_dev_t;
  78958. +#endif
  78959. +
  78960. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  78961. +#if defined(LM_INTERFACE)
  78962. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  78963. +#elif defined(PCI_INTERFACE)
  78964. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  78965. +#elif defined(PLATFORM_INTERFACE)
  78966. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  78967. +#endif
  78968. +
  78969. +/**
  78970. + * Helper macro returning the otg_device structure of a given struct device
  78971. + *
  78972. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  78973. + */
  78974. +#ifdef LM_INTERFACE
  78975. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78976. + struct lm_device *lm_dev = \
  78977. + container_of(_dev, struct lm_device, dev); \
  78978. + _var = lm_get_drvdata(lm_dev); \
  78979. + } while (0)
  78980. +
  78981. +#elif defined(PCI_INTERFACE)
  78982. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78983. + _var = dev_get_drvdata(_dev); \
  78984. + } while (0)
  78985. +
  78986. +#elif defined(PLATFORM_INTERFACE)
  78987. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  78988. + struct platform_device *platform_dev = \
  78989. + container_of(_dev, struct platform_device, dev); \
  78990. + _var = platform_get_drvdata(platform_dev); \
  78991. + } while (0)
  78992. +#endif
  78993. +
  78994. +
  78995. +/**
  78996. + * Helper macro returning the struct dev of the given struct os_dependent
  78997. + *
  78998. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  78999. + */
  79000. +#ifdef LM_INTERFACE
  79001. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79002. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  79003. +#elif defined(PCI_INTERFACE)
  79004. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79005. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  79006. +#elif defined(PLATFORM_INTERFACE)
  79007. +#define DWC_OTG_OS_GETDEV(_osdep) \
  79008. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  79009. +#endif
  79010. +
  79011. +
  79012. +
  79013. +
  79014. +#endif /* _DWC_OS_DEP_H_ */
  79015. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  79016. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  79017. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-02-07 19:57:30.000000000 +0100
  79018. @@ -0,0 +1,2708 @@
  79019. +/* ==========================================================================
  79020. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  79021. + * $Revision: #101 $
  79022. + * $Date: 2012/08/10 $
  79023. + * $Change: 2047372 $
  79024. + *
  79025. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79026. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79027. + * otherwise expressly agreed to in writing between Synopsys and you.
  79028. + *
  79029. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79030. + * any End User Software License Agreement or Agreement for Licensed Product
  79031. + * with Synopsys or any supplement thereto. You are permitted to use and
  79032. + * redistribute this Software in source and binary forms, with or without
  79033. + * modification, provided that redistributions of source code must retain this
  79034. + * notice. You may not view, use, disclose, copy or distribute this file or
  79035. + * any information contained herein except pursuant to this license grant from
  79036. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79037. + * below, then you are not authorized to use the Software.
  79038. + *
  79039. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79040. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79041. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79042. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79043. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79044. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79045. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79046. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79047. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79048. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79049. + * DAMAGE.
  79050. + * ========================================================================== */
  79051. +#ifndef DWC_HOST_ONLY
  79052. +
  79053. +/** @file
  79054. + * This file implements PCD Core. All code in this file is portable and doesn't
  79055. + * use any OS specific functions.
  79056. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  79057. + * header file, which can be used to implement OS specific PCD interface.
  79058. + *
  79059. + * An important function of the PCD is managing interrupts generated
  79060. + * by the DWC_otg controller. The implementation of the DWC_otg device
  79061. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  79062. + *
  79063. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  79064. + * @todo Does it work when the request size is greater than DEPTSIZ
  79065. + * transfer size
  79066. + *
  79067. + */
  79068. +
  79069. +#include "dwc_otg_pcd.h"
  79070. +
  79071. +#ifdef DWC_UTE_CFI
  79072. +#include "dwc_otg_cfi.h"
  79073. +
  79074. +extern int init_cfi(cfiobject_t * cfiobj);
  79075. +#endif
  79076. +
  79077. +/**
  79078. + * Choose endpoint from ep arrays using usb_ep structure.
  79079. + */
  79080. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  79081. +{
  79082. + int i;
  79083. + if (pcd->ep0.priv == handle) {
  79084. + return &pcd->ep0;
  79085. + }
  79086. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  79087. + if (pcd->in_ep[i].priv == handle)
  79088. + return &pcd->in_ep[i];
  79089. + if (pcd->out_ep[i].priv == handle)
  79090. + return &pcd->out_ep[i];
  79091. + }
  79092. +
  79093. + return NULL;
  79094. +}
  79095. +
  79096. +/**
  79097. + * This function completes a request. It call's the request call back.
  79098. + */
  79099. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  79100. + int32_t status)
  79101. +{
  79102. + unsigned stopped = ep->stopped;
  79103. +
  79104. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  79105. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  79106. +
  79107. + /* don't modify queue heads during completion callback */
  79108. + ep->stopped = 1;
  79109. + /* spin_unlock/spin_lock now done in fops->complete() */
  79110. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  79111. + req->actual);
  79112. +
  79113. + if (ep->pcd->request_pending > 0) {
  79114. + --ep->pcd->request_pending;
  79115. + }
  79116. +
  79117. + ep->stopped = stopped;
  79118. + DWC_FREE(req);
  79119. +}
  79120. +
  79121. +/**
  79122. + * This function terminates all the requsts in the EP request queue.
  79123. + */
  79124. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  79125. +{
  79126. + dwc_otg_pcd_request_t *req;
  79127. +
  79128. + ep->stopped = 1;
  79129. +
  79130. + /* called with irqs blocked?? */
  79131. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  79132. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  79133. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  79134. + }
  79135. +}
  79136. +
  79137. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  79138. + const struct dwc_otg_pcd_function_ops *fops)
  79139. +{
  79140. + pcd->fops = fops;
  79141. +}
  79142. +
  79143. +/**
  79144. + * PCD Callback function for initializing the PCD when switching to
  79145. + * device mode.
  79146. + *
  79147. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79148. + */
  79149. +static int32_t dwc_otg_pcd_start_cb(void *p)
  79150. +{
  79151. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79152. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  79153. +
  79154. + /*
  79155. + * Initialized the Core for Device mode.
  79156. + */
  79157. + if (dwc_otg_is_device_mode(core_if)) {
  79158. + dwc_otg_core_dev_init(core_if);
  79159. + /* Set core_if's lock pointer to the pcd->lock */
  79160. + core_if->lock = pcd->lock;
  79161. + }
  79162. + return 1;
  79163. +}
  79164. +
  79165. +/** CFI-specific buffer allocation function for EP */
  79166. +#ifdef DWC_UTE_CFI
  79167. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  79168. + size_t buflen, int flags)
  79169. +{
  79170. + dwc_otg_pcd_ep_t *ep;
  79171. + ep = get_ep_from_handle(pcd, pep);
  79172. + if (!ep) {
  79173. + DWC_WARN("bad ep\n");
  79174. + return -DWC_E_INVALID;
  79175. + }
  79176. +
  79177. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  79178. + flags);
  79179. +}
  79180. +#else
  79181. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  79182. + size_t buflen, int flags);
  79183. +#endif
  79184. +
  79185. +/**
  79186. + * PCD Callback function for notifying the PCD when resuming from
  79187. + * suspend.
  79188. + *
  79189. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79190. + */
  79191. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  79192. +{
  79193. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79194. +
  79195. + if (pcd->fops->resume) {
  79196. + pcd->fops->resume(pcd);
  79197. + }
  79198. +
  79199. + /* Stop the SRP timeout timer. */
  79200. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  79201. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  79202. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  79203. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  79204. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  79205. + }
  79206. + }
  79207. + return 1;
  79208. +}
  79209. +
  79210. +/**
  79211. + * PCD Callback function for notifying the PCD device is suspended.
  79212. + *
  79213. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79214. + */
  79215. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  79216. +{
  79217. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79218. +
  79219. + if (pcd->fops->suspend) {
  79220. + DWC_SPINUNLOCK(pcd->lock);
  79221. + pcd->fops->suspend(pcd);
  79222. + DWC_SPINLOCK(pcd->lock);
  79223. + }
  79224. +
  79225. + return 1;
  79226. +}
  79227. +
  79228. +/**
  79229. + * PCD Callback function for stopping the PCD when switching to Host
  79230. + * mode.
  79231. + *
  79232. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  79233. + */
  79234. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  79235. +{
  79236. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  79237. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  79238. +
  79239. + dwc_otg_pcd_stop(pcd);
  79240. + return 1;
  79241. +}
  79242. +
  79243. +/**
  79244. + * PCD Callback structure for handling mode switching.
  79245. + */
  79246. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  79247. + .start = dwc_otg_pcd_start_cb,
  79248. + .stop = dwc_otg_pcd_stop_cb,
  79249. + .suspend = dwc_otg_pcd_suspend_cb,
  79250. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  79251. + .p = 0, /* Set at registration */
  79252. +};
  79253. +
  79254. +/**
  79255. + * This function allocates a DMA Descriptor chain for the Endpoint
  79256. + * buffer to be used for a transfer to/from the specified endpoint.
  79257. + */
  79258. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  79259. + uint32_t count)
  79260. +{
  79261. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  79262. + dma_desc_addr);
  79263. +}
  79264. +
  79265. +/**
  79266. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  79267. + */
  79268. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  79269. + uint32_t dma_desc_addr, uint32_t count)
  79270. +{
  79271. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  79272. + dma_desc_addr);
  79273. +}
  79274. +
  79275. +#ifdef DWC_EN_ISOC
  79276. +
  79277. +/**
  79278. + * This function initializes a descriptor chain for Isochronous transfer
  79279. + *
  79280. + * @param core_if Programming view of DWC_otg controller.
  79281. + * @param dwc_ep The EP to start the transfer on.
  79282. + *
  79283. + */
  79284. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  79285. + dwc_ep_t * dwc_ep)
  79286. +{
  79287. +
  79288. + dsts_data_t dsts = {.d32 = 0 };
  79289. + depctl_data_t depctl = {.d32 = 0 };
  79290. + volatile uint32_t *addr;
  79291. + int i, j;
  79292. + uint32_t len;
  79293. +
  79294. + if (dwc_ep->is_in)
  79295. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  79296. + else
  79297. + dwc_ep->desc_cnt =
  79298. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79299. + dwc_ep->bInterval;
  79300. +
  79301. + /** Allocate descriptors for double buffering */
  79302. + dwc_ep->iso_desc_addr =
  79303. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  79304. + dwc_ep->desc_cnt * 2);
  79305. + if (dwc_ep->desc_addr) {
  79306. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  79307. + return;
  79308. + }
  79309. +
  79310. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79311. +
  79312. + /** ISO OUT EP */
  79313. + if (dwc_ep->is_in == 0) {
  79314. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  79315. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  79316. + dma_addr_t dma_ad;
  79317. + uint32_t data_per_desc;
  79318. + dwc_otg_dev_out_ep_regs_t *out_regs =
  79319. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  79320. + int offset;
  79321. +
  79322. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  79323. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  79324. +
  79325. + /** Buffer 0 descriptors setup */
  79326. + dma_ad = dwc_ep->dma_addr0;
  79327. +
  79328. + sts.b_iso_out.bs = BS_HOST_READY;
  79329. + sts.b_iso_out.rxsts = 0;
  79330. + sts.b_iso_out.l = 0;
  79331. + sts.b_iso_out.sp = 0;
  79332. + sts.b_iso_out.ioc = 0;
  79333. + sts.b_iso_out.pid = 0;
  79334. + sts.b_iso_out.framenum = 0;
  79335. +
  79336. + offset = 0;
  79337. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79338. + i += dwc_ep->pkt_per_frm) {
  79339. +
  79340. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  79341. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79342. + if (len > dwc_ep->data_per_frame)
  79343. + data_per_desc =
  79344. + dwc_ep->data_per_frame -
  79345. + j * dwc_ep->maxpacket;
  79346. + else
  79347. + data_per_desc = dwc_ep->maxpacket;
  79348. + len = data_per_desc % 4;
  79349. + if (len)
  79350. + data_per_desc += 4 - len;
  79351. +
  79352. + sts.b_iso_out.rxbytes = data_per_desc;
  79353. + dma_desc->buf = dma_ad;
  79354. + dma_desc->status.d32 = sts.d32;
  79355. +
  79356. + offset += data_per_desc;
  79357. + dma_desc++;
  79358. + dma_ad += data_per_desc;
  79359. + }
  79360. + }
  79361. +
  79362. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  79363. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79364. + if (len > dwc_ep->data_per_frame)
  79365. + data_per_desc =
  79366. + dwc_ep->data_per_frame -
  79367. + j * dwc_ep->maxpacket;
  79368. + else
  79369. + data_per_desc = dwc_ep->maxpacket;
  79370. + len = data_per_desc % 4;
  79371. + if (len)
  79372. + data_per_desc += 4 - len;
  79373. + sts.b_iso_out.rxbytes = data_per_desc;
  79374. + dma_desc->buf = dma_ad;
  79375. + dma_desc->status.d32 = sts.d32;
  79376. +
  79377. + offset += data_per_desc;
  79378. + dma_desc++;
  79379. + dma_ad += data_per_desc;
  79380. + }
  79381. +
  79382. + sts.b_iso_out.ioc = 1;
  79383. + len = (j + 1) * dwc_ep->maxpacket;
  79384. + if (len > dwc_ep->data_per_frame)
  79385. + data_per_desc =
  79386. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  79387. + else
  79388. + data_per_desc = dwc_ep->maxpacket;
  79389. + len = data_per_desc % 4;
  79390. + if (len)
  79391. + data_per_desc += 4 - len;
  79392. + sts.b_iso_out.rxbytes = data_per_desc;
  79393. +
  79394. + dma_desc->buf = dma_ad;
  79395. + dma_desc->status.d32 = sts.d32;
  79396. + dma_desc++;
  79397. +
  79398. + /** Buffer 1 descriptors setup */
  79399. + sts.b_iso_out.ioc = 0;
  79400. + dma_ad = dwc_ep->dma_addr1;
  79401. +
  79402. + offset = 0;
  79403. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79404. + i += dwc_ep->pkt_per_frm) {
  79405. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  79406. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  79407. + if (len > dwc_ep->data_per_frame)
  79408. + data_per_desc =
  79409. + dwc_ep->data_per_frame -
  79410. + j * dwc_ep->maxpacket;
  79411. + else
  79412. + data_per_desc = dwc_ep->maxpacket;
  79413. + len = data_per_desc % 4;
  79414. + if (len)
  79415. + data_per_desc += 4 - len;
  79416. +
  79417. + data_per_desc =
  79418. + sts.b_iso_out.rxbytes = data_per_desc;
  79419. + dma_desc->buf = dma_ad;
  79420. + dma_desc->status.d32 = sts.d32;
  79421. +
  79422. + offset += data_per_desc;
  79423. + dma_desc++;
  79424. + dma_ad += data_per_desc;
  79425. + }
  79426. + }
  79427. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  79428. + data_per_desc =
  79429. + ((j + 1) * dwc_ep->maxpacket >
  79430. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  79431. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  79432. + data_per_desc +=
  79433. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  79434. + sts.b_iso_out.rxbytes = data_per_desc;
  79435. + dma_desc->buf = dma_ad;
  79436. + dma_desc->status.d32 = sts.d32;
  79437. +
  79438. + offset += data_per_desc;
  79439. + dma_desc++;
  79440. + dma_ad += data_per_desc;
  79441. + }
  79442. +
  79443. + sts.b_iso_out.ioc = 1;
  79444. + sts.b_iso_out.l = 1;
  79445. + data_per_desc =
  79446. + ((j + 1) * dwc_ep->maxpacket >
  79447. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  79448. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  79449. + data_per_desc +=
  79450. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  79451. + sts.b_iso_out.rxbytes = data_per_desc;
  79452. +
  79453. + dma_desc->buf = dma_ad;
  79454. + dma_desc->status.d32 = sts.d32;
  79455. +
  79456. + dwc_ep->next_frame = 0;
  79457. +
  79458. + /** Write dma_ad into DOEPDMA register */
  79459. + DWC_WRITE_REG32(&(out_regs->doepdma),
  79460. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  79461. +
  79462. + }
  79463. + /** ISO IN EP */
  79464. + else {
  79465. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  79466. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  79467. + dma_addr_t dma_ad;
  79468. + dwc_otg_dev_in_ep_regs_t *in_regs =
  79469. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  79470. + unsigned int frmnumber;
  79471. + fifosize_data_t txfifosize, rxfifosize;
  79472. +
  79473. + txfifosize.d32 =
  79474. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  79475. + dtxfsts);
  79476. + rxfifosize.d32 =
  79477. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  79478. +
  79479. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  79480. +
  79481. + dma_ad = dwc_ep->dma_addr0;
  79482. +
  79483. + dsts.d32 =
  79484. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79485. +
  79486. + sts.b_iso_in.bs = BS_HOST_READY;
  79487. + sts.b_iso_in.txsts = 0;
  79488. + sts.b_iso_in.sp =
  79489. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  79490. + sts.b_iso_in.ioc = 0;
  79491. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  79492. +
  79493. + frmnumber = dwc_ep->next_frame;
  79494. +
  79495. + sts.b_iso_in.framenum = frmnumber;
  79496. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  79497. + sts.b_iso_in.l = 0;
  79498. +
  79499. + /** Buffer 0 descriptors setup */
  79500. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  79501. + dma_desc->buf = dma_ad;
  79502. + dma_desc->status.d32 = sts.d32;
  79503. + dma_desc++;
  79504. +
  79505. + dma_ad += dwc_ep->data_per_frame;
  79506. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  79507. + }
  79508. +
  79509. + sts.b_iso_in.ioc = 1;
  79510. + dma_desc->buf = dma_ad;
  79511. + dma_desc->status.d32 = sts.d32;
  79512. + ++dma_desc;
  79513. +
  79514. + /** Buffer 1 descriptors setup */
  79515. + sts.b_iso_in.ioc = 0;
  79516. + dma_ad = dwc_ep->dma_addr1;
  79517. +
  79518. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  79519. + i += dwc_ep->pkt_per_frm) {
  79520. + dma_desc->buf = dma_ad;
  79521. + dma_desc->status.d32 = sts.d32;
  79522. + dma_desc++;
  79523. +
  79524. + dma_ad += dwc_ep->data_per_frame;
  79525. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  79526. +
  79527. + sts.b_iso_in.ioc = 0;
  79528. + }
  79529. + sts.b_iso_in.ioc = 1;
  79530. + sts.b_iso_in.l = 1;
  79531. +
  79532. + dma_desc->buf = dma_ad;
  79533. + dma_desc->status.d32 = sts.d32;
  79534. +
  79535. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  79536. +
  79537. + /** Write dma_ad into diepdma register */
  79538. + DWC_WRITE_REG32(&(in_regs->diepdma),
  79539. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  79540. + }
  79541. + /** Enable endpoint, clear nak */
  79542. + depctl.d32 = 0;
  79543. + depctl.b.epena = 1;
  79544. + depctl.b.usbactep = 1;
  79545. + depctl.b.cnak = 1;
  79546. +
  79547. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  79548. + depctl.d32 = DWC_READ_REG32(addr);
  79549. +}
  79550. +
  79551. +/**
  79552. + * This function initializes a descriptor chain for Isochronous transfer
  79553. + *
  79554. + * @param core_if Programming view of DWC_otg controller.
  79555. + * @param ep The EP to start the transfer on.
  79556. + *
  79557. + */
  79558. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  79559. + dwc_ep_t * ep)
  79560. +{
  79561. + depctl_data_t depctl = {.d32 = 0 };
  79562. + volatile uint32_t *addr;
  79563. +
  79564. + if (ep->is_in) {
  79565. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  79566. + } else {
  79567. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  79568. + }
  79569. +
  79570. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  79571. + return;
  79572. + } else {
  79573. + deptsiz_data_t deptsiz = {.d32 = 0 };
  79574. +
  79575. + ep->xfer_len =
  79576. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  79577. + ep->pkt_cnt =
  79578. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  79579. + ep->xfer_count = 0;
  79580. + ep->xfer_buff =
  79581. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  79582. + ep->dma_addr =
  79583. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  79584. +
  79585. + if (ep->is_in) {
  79586. + /* Program the transfer size and packet count
  79587. + * as follows: xfersize = N * maxpacket +
  79588. + * short_packet pktcnt = N + (short_packet
  79589. + * exist ? 1 : 0)
  79590. + */
  79591. + deptsiz.b.mc = ep->pkt_per_frm;
  79592. + deptsiz.b.xfersize = ep->xfer_len;
  79593. + deptsiz.b.pktcnt =
  79594. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  79595. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  79596. + dieptsiz, deptsiz.d32);
  79597. +
  79598. + /* Write the DMA register */
  79599. + DWC_WRITE_REG32(&
  79600. + (core_if->dev_if->in_ep_regs[ep->num]->
  79601. + diepdma), (uint32_t) ep->dma_addr);
  79602. +
  79603. + } else {
  79604. + deptsiz.b.pktcnt =
  79605. + (ep->xfer_len + (ep->maxpacket - 1)) /
  79606. + ep->maxpacket;
  79607. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  79608. +
  79609. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  79610. + doeptsiz, deptsiz.d32);
  79611. +
  79612. + /* Write the DMA register */
  79613. + DWC_WRITE_REG32(&
  79614. + (core_if->dev_if->out_ep_regs[ep->num]->
  79615. + doepdma), (uint32_t) ep->dma_addr);
  79616. +
  79617. + }
  79618. + /** Enable endpoint, clear nak */
  79619. + depctl.d32 = 0;
  79620. + depctl.b.epena = 1;
  79621. + depctl.b.cnak = 1;
  79622. +
  79623. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  79624. + }
  79625. +}
  79626. +
  79627. +/**
  79628. + * This function does the setup for a data transfer for an EP and
  79629. + * starts the transfer. For an IN transfer, the packets will be
  79630. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  79631. + * the packets are unloaded from the Rx FIFO in the ISR.
  79632. + *
  79633. + * @param core_if Programming view of DWC_otg controller.
  79634. + * @param ep The EP to start the transfer on.
  79635. + */
  79636. +
  79637. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  79638. + dwc_ep_t * ep)
  79639. +{
  79640. + if (core_if->dma_enable) {
  79641. + if (core_if->dma_desc_enable) {
  79642. + if (ep->is_in) {
  79643. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  79644. + } else {
  79645. + ep->desc_cnt = ep->pkt_cnt;
  79646. + }
  79647. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  79648. + } else {
  79649. + if (core_if->pti_enh_enable) {
  79650. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  79651. + } else {
  79652. + ep->cur_pkt_addr =
  79653. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  79654. + xfer_buff0;
  79655. + ep->cur_pkt_dma_addr =
  79656. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  79657. + dma_addr0;
  79658. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  79659. + }
  79660. + }
  79661. + } else {
  79662. + ep->cur_pkt_addr =
  79663. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  79664. + ep->cur_pkt_dma_addr =
  79665. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  79666. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  79667. + }
  79668. +}
  79669. +
  79670. +/**
  79671. + * This function stops transfer for an EP and
  79672. + * resets the ep's variables.
  79673. + *
  79674. + * @param core_if Programming view of DWC_otg controller.
  79675. + * @param ep The EP to start the transfer on.
  79676. + */
  79677. +
  79678. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  79679. +{
  79680. + depctl_data_t depctl = {.d32 = 0 };
  79681. + volatile uint32_t *addr;
  79682. +
  79683. + if (ep->is_in == 1) {
  79684. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  79685. + } else {
  79686. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  79687. + }
  79688. +
  79689. + /* disable the ep */
  79690. + depctl.d32 = DWC_READ_REG32(addr);
  79691. +
  79692. + depctl.b.epdis = 1;
  79693. + depctl.b.snak = 1;
  79694. +
  79695. + DWC_WRITE_REG32(addr, depctl.d32);
  79696. +
  79697. + if (core_if->dma_desc_enable &&
  79698. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  79699. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  79700. + ep->iso_dma_desc_addr,
  79701. + ep->desc_cnt * 2);
  79702. + }
  79703. +
  79704. + /* reset varibales */
  79705. + ep->dma_addr0 = 0;
  79706. + ep->dma_addr1 = 0;
  79707. + ep->xfer_buff0 = 0;
  79708. + ep->xfer_buff1 = 0;
  79709. + ep->data_per_frame = 0;
  79710. + ep->data_pattern_frame = 0;
  79711. + ep->sync_frame = 0;
  79712. + ep->buf_proc_intrvl = 0;
  79713. + ep->bInterval = 0;
  79714. + ep->proc_buf_num = 0;
  79715. + ep->pkt_per_frm = 0;
  79716. + ep->pkt_per_frm = 0;
  79717. + ep->desc_cnt = 0;
  79718. + ep->iso_desc_addr = 0;
  79719. + ep->iso_dma_desc_addr = 0;
  79720. +}
  79721. +
  79722. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  79723. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  79724. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  79725. + int data_per_frame, int start_frame,
  79726. + int buf_proc_intrvl, void *req_handle,
  79727. + int atomic_alloc)
  79728. +{
  79729. + dwc_otg_pcd_ep_t *ep;
  79730. + dwc_irqflags_t flags = 0;
  79731. + dwc_ep_t *dwc_ep;
  79732. + int32_t frm_data;
  79733. + dsts_data_t dsts;
  79734. + dwc_otg_core_if_t *core_if;
  79735. +
  79736. + ep = get_ep_from_handle(pcd, ep_handle);
  79737. +
  79738. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  79739. + DWC_WARN("bad ep\n");
  79740. + return -DWC_E_INVALID;
  79741. + }
  79742. +
  79743. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79744. + core_if = GET_CORE_IF(pcd);
  79745. + dwc_ep = &ep->dwc_ep;
  79746. +
  79747. + if (ep->iso_req_handle) {
  79748. + DWC_WARN("ISO request in progress\n");
  79749. + }
  79750. +
  79751. + dwc_ep->dma_addr0 = dma0;
  79752. + dwc_ep->dma_addr1 = dma1;
  79753. +
  79754. + dwc_ep->xfer_buff0 = buf0;
  79755. + dwc_ep->xfer_buff1 = buf1;
  79756. +
  79757. + dwc_ep->data_per_frame = data_per_frame;
  79758. +
  79759. + /** @todo - pattern data support is to be implemented in the future */
  79760. + dwc_ep->data_pattern_frame = dp_frame;
  79761. + dwc_ep->sync_frame = sync_frame;
  79762. +
  79763. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  79764. +
  79765. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  79766. +
  79767. + dwc_ep->proc_buf_num = 0;
  79768. +
  79769. + dwc_ep->pkt_per_frm = 0;
  79770. + frm_data = ep->dwc_ep.data_per_frame;
  79771. + while (frm_data > 0) {
  79772. + dwc_ep->pkt_per_frm++;
  79773. + frm_data -= ep->dwc_ep.maxpacket;
  79774. + }
  79775. +
  79776. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  79777. +
  79778. + if (start_frame == -1) {
  79779. + dwc_ep->next_frame = dsts.b.soffn + 1;
  79780. + if (dwc_ep->bInterval != 1) {
  79781. + dwc_ep->next_frame =
  79782. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  79783. + dwc_ep->next_frame %
  79784. + dwc_ep->bInterval);
  79785. + }
  79786. + } else {
  79787. + dwc_ep->next_frame = start_frame;
  79788. + }
  79789. +
  79790. + if (!core_if->pti_enh_enable) {
  79791. + dwc_ep->pkt_cnt =
  79792. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79793. + dwc_ep->bInterval;
  79794. + } else {
  79795. + dwc_ep->pkt_cnt =
  79796. + (dwc_ep->data_per_frame *
  79797. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  79798. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  79799. + }
  79800. +
  79801. + if (core_if->dma_desc_enable) {
  79802. + dwc_ep->desc_cnt =
  79803. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  79804. + dwc_ep->bInterval;
  79805. + }
  79806. +
  79807. + if (atomic_alloc) {
  79808. + dwc_ep->pkt_info =
  79809. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79810. + } else {
  79811. + dwc_ep->pkt_info =
  79812. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79813. + }
  79814. + if (!dwc_ep->pkt_info) {
  79815. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79816. + return -DWC_E_NO_MEMORY;
  79817. + }
  79818. + if (core_if->pti_enh_enable) {
  79819. + dwc_memset(dwc_ep->pkt_info, 0,
  79820. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  79821. + }
  79822. +
  79823. + dwc_ep->cur_pkt = 0;
  79824. + ep->iso_req_handle = req_handle;
  79825. +
  79826. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79827. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  79828. + return 0;
  79829. +}
  79830. +
  79831. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  79832. + void *req_handle)
  79833. +{
  79834. + dwc_irqflags_t flags = 0;
  79835. + dwc_otg_pcd_ep_t *ep;
  79836. + dwc_ep_t *dwc_ep;
  79837. +
  79838. + ep = get_ep_from_handle(pcd, ep_handle);
  79839. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  79840. + DWC_WARN("bad ep\n");
  79841. + return -DWC_E_INVALID;
  79842. + }
  79843. + dwc_ep = &ep->dwc_ep;
  79844. +
  79845. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  79846. +
  79847. + DWC_FREE(dwc_ep->pkt_info);
  79848. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  79849. + if (ep->iso_req_handle != req_handle) {
  79850. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79851. + return -DWC_E_INVALID;
  79852. + }
  79853. +
  79854. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  79855. +
  79856. + ep->iso_req_handle = 0;
  79857. + return 0;
  79858. +}
  79859. +
  79860. +/**
  79861. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  79862. + * for Isochronous EPs
  79863. + *
  79864. + * - Every time a sync period completes this function is called to
  79865. + * perform data exchange between PCD and gadget
  79866. + */
  79867. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  79868. + void *req_handle)
  79869. +{
  79870. + int i;
  79871. + dwc_ep_t *dwc_ep;
  79872. +
  79873. + dwc_ep = &ep->dwc_ep;
  79874. +
  79875. + DWC_SPINUNLOCK(ep->pcd->lock);
  79876. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  79877. + dwc_ep->proc_buf_num ^ 0x1);
  79878. + DWC_SPINLOCK(ep->pcd->lock);
  79879. +
  79880. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  79881. + dwc_ep->pkt_info[i].status = 0;
  79882. + dwc_ep->pkt_info[i].offset = 0;
  79883. + dwc_ep->pkt_info[i].length = 0;
  79884. + }
  79885. +}
  79886. +
  79887. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  79888. + void *iso_req_handle)
  79889. +{
  79890. + dwc_otg_pcd_ep_t *ep;
  79891. + dwc_ep_t *dwc_ep;
  79892. +
  79893. + ep = get_ep_from_handle(pcd, ep_handle);
  79894. + if (!ep->desc || ep->dwc_ep.num == 0) {
  79895. + DWC_WARN("bad ep\n");
  79896. + return -DWC_E_INVALID;
  79897. + }
  79898. + dwc_ep = &ep->dwc_ep;
  79899. +
  79900. + return dwc_ep->pkt_cnt;
  79901. +}
  79902. +
  79903. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  79904. + void *iso_req_handle, int packet,
  79905. + int *status, int *actual, int *offset)
  79906. +{
  79907. + dwc_otg_pcd_ep_t *ep;
  79908. + dwc_ep_t *dwc_ep;
  79909. +
  79910. + ep = get_ep_from_handle(pcd, ep_handle);
  79911. + if (!ep)
  79912. + DWC_WARN("bad ep\n");
  79913. +
  79914. + dwc_ep = &ep->dwc_ep;
  79915. +
  79916. + *status = dwc_ep->pkt_info[packet].status;
  79917. + *actual = dwc_ep->pkt_info[packet].length;
  79918. + *offset = dwc_ep->pkt_info[packet].offset;
  79919. +}
  79920. +
  79921. +#endif /* DWC_EN_ISOC */
  79922. +
  79923. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  79924. + uint32_t is_in, uint32_t ep_num)
  79925. +{
  79926. + /* Init EP structure */
  79927. + pcd_ep->desc = 0;
  79928. + pcd_ep->pcd = pcd;
  79929. + pcd_ep->stopped = 1;
  79930. + pcd_ep->queue_sof = 0;
  79931. +
  79932. + /* Init DWC ep structure */
  79933. + pcd_ep->dwc_ep.is_in = is_in;
  79934. + pcd_ep->dwc_ep.num = ep_num;
  79935. + pcd_ep->dwc_ep.active = 0;
  79936. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  79937. + /* Control until ep is actvated */
  79938. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  79939. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  79940. + pcd_ep->dwc_ep.dma_addr = 0;
  79941. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  79942. + pcd_ep->dwc_ep.xfer_buff = 0;
  79943. + pcd_ep->dwc_ep.xfer_len = 0;
  79944. + pcd_ep->dwc_ep.xfer_count = 0;
  79945. + pcd_ep->dwc_ep.sent_zlp = 0;
  79946. + pcd_ep->dwc_ep.total_len = 0;
  79947. + pcd_ep->dwc_ep.desc_addr = 0;
  79948. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  79949. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  79950. +}
  79951. +
  79952. +/**
  79953. + * Initialize ep's
  79954. + */
  79955. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  79956. +{
  79957. + int i;
  79958. + uint32_t hwcfg1;
  79959. + dwc_otg_pcd_ep_t *ep;
  79960. + int in_ep_cntr, out_ep_cntr;
  79961. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  79962. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  79963. +
  79964. + /**
  79965. + * Initialize the EP0 structure.
  79966. + */
  79967. + ep = &pcd->ep0;
  79968. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  79969. +
  79970. + in_ep_cntr = 0;
  79971. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  79972. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  79973. + if ((hwcfg1 & 0x1) == 0) {
  79974. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  79975. + in_ep_cntr++;
  79976. + /**
  79977. + * @todo NGS: Add direction to EP, based on contents
  79978. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  79979. + * sprintf(";r
  79980. + */
  79981. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  79982. +
  79983. + DWC_CIRCLEQ_INIT(&ep->queue);
  79984. + }
  79985. + hwcfg1 >>= 2;
  79986. + }
  79987. +
  79988. + out_ep_cntr = 0;
  79989. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  79990. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  79991. + if ((hwcfg1 & 0x1) == 0) {
  79992. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  79993. + out_ep_cntr++;
  79994. + /**
  79995. + * @todo NGS: Add direction to EP, based on contents
  79996. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  79997. + * sprintf(";r
  79998. + */
  79999. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  80000. + DWC_CIRCLEQ_INIT(&ep->queue);
  80001. + }
  80002. + hwcfg1 >>= 2;
  80003. + }
  80004. +
  80005. + pcd->ep0state = EP0_DISCONNECT;
  80006. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  80007. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  80008. +}
  80009. +
  80010. +/**
  80011. + * This function is called when the SRP timer expires. The SRP should
  80012. + * complete within 6 seconds.
  80013. + */
  80014. +static void srp_timeout(void *ptr)
  80015. +{
  80016. + gotgctl_data_t gotgctl;
  80017. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  80018. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  80019. +
  80020. + gotgctl.d32 = DWC_READ_REG32(addr);
  80021. +
  80022. + core_if->srp_timer_started = 0;
  80023. +
  80024. + if (core_if->adp_enable) {
  80025. + if (gotgctl.b.bsesvld == 0) {
  80026. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  80027. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  80028. + /* Power off the core */
  80029. + if (core_if->power_down == 2) {
  80030. + gpwrdn.b.pwrdnswtch = 1;
  80031. + DWC_MODIFY_REG32(&core_if->
  80032. + core_global_regs->gpwrdn,
  80033. + gpwrdn.d32, 0);
  80034. + }
  80035. +
  80036. + gpwrdn.d32 = 0;
  80037. + gpwrdn.b.pmuintsel = 1;
  80038. + gpwrdn.b.pmuactv = 1;
  80039. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  80040. + gpwrdn.d32);
  80041. + dwc_otg_adp_probe_start(core_if);
  80042. + } else {
  80043. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  80044. + core_if->op_state = B_PERIPHERAL;
  80045. + dwc_otg_core_init(core_if);
  80046. + dwc_otg_enable_global_interrupts(core_if);
  80047. + cil_pcd_start(core_if);
  80048. + }
  80049. + }
  80050. +
  80051. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  80052. + (core_if->core_params->i2c_enable)) {
  80053. + DWC_PRINTF("SRP Timeout\n");
  80054. +
  80055. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  80056. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  80057. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  80058. + }
  80059. +
  80060. + /* Clear Session Request */
  80061. + gotgctl.d32 = 0;
  80062. + gotgctl.b.sesreq = 1;
  80063. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  80064. + gotgctl.d32, 0);
  80065. +
  80066. + core_if->srp_success = 0;
  80067. + } else {
  80068. + __DWC_ERROR("Device not connected/responding\n");
  80069. + gotgctl.b.sesreq = 0;
  80070. + DWC_WRITE_REG32(addr, gotgctl.d32);
  80071. + }
  80072. + } else if (gotgctl.b.sesreq) {
  80073. + DWC_PRINTF("SRP Timeout\n");
  80074. +
  80075. + __DWC_ERROR("Device not connected/responding\n");
  80076. + gotgctl.b.sesreq = 0;
  80077. + DWC_WRITE_REG32(addr, gotgctl.d32);
  80078. + } else {
  80079. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  80080. + }
  80081. +}
  80082. +
  80083. +/**
  80084. + * Tasklet
  80085. + *
  80086. + */
  80087. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  80088. +
  80089. +static void start_xfer_tasklet_func(void *data)
  80090. +{
  80091. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  80092. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80093. +
  80094. + int i;
  80095. + depctl_data_t diepctl;
  80096. +
  80097. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  80098. +
  80099. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  80100. +
  80101. + if (pcd->ep0.queue_sof) {
  80102. + pcd->ep0.queue_sof = 0;
  80103. + start_next_request(&pcd->ep0);
  80104. + // break;
  80105. + }
  80106. +
  80107. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  80108. + depctl_data_t diepctl;
  80109. + diepctl.d32 =
  80110. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  80111. +
  80112. + if (pcd->in_ep[i].queue_sof) {
  80113. + pcd->in_ep[i].queue_sof = 0;
  80114. + start_next_request(&pcd->in_ep[i]);
  80115. + // break;
  80116. + }
  80117. + }
  80118. +
  80119. + return;
  80120. +}
  80121. +
  80122. +/**
  80123. + * This function initialized the PCD portion of the driver.
  80124. + *
  80125. + */
  80126. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  80127. +{
  80128. + dwc_otg_pcd_t *pcd = NULL;
  80129. + dwc_otg_dev_if_t *dev_if;
  80130. + int i;
  80131. +
  80132. + /*
  80133. + * Allocate PCD structure
  80134. + */
  80135. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  80136. +
  80137. + if (pcd == NULL) {
  80138. + return NULL;
  80139. + }
  80140. +
  80141. + pcd->lock = DWC_SPINLOCK_ALLOC();
  80142. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  80143. + pcd, core_if);//GRAYG
  80144. + if (!pcd->lock) {
  80145. + DWC_ERROR("Could not allocate lock for pcd");
  80146. + DWC_FREE(pcd);
  80147. + return NULL;
  80148. + }
  80149. + /* Set core_if's lock pointer to hcd->lock */
  80150. + core_if->lock = pcd->lock;
  80151. + pcd->core_if = core_if;
  80152. +
  80153. + dev_if = core_if->dev_if;
  80154. + dev_if->isoc_ep = NULL;
  80155. +
  80156. + if (core_if->hwcfg4.b.ded_fifo_en) {
  80157. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  80158. + } else {
  80159. + DWC_PRINTF("Shared Tx FIFO mode\n");
  80160. + }
  80161. +
  80162. + /*
  80163. + * Initialized the Core for Device mode here if there is nod ADP support.
  80164. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  80165. + */
  80166. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  80167. + dwc_otg_core_dev_init(core_if);
  80168. + }
  80169. +
  80170. + /*
  80171. + * Register the PCD Callbacks.
  80172. + */
  80173. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  80174. +
  80175. + /*
  80176. + * Initialize the DMA buffer for SETUP packets
  80177. + */
  80178. + if (GET_CORE_IF(pcd)->dma_enable) {
  80179. + pcd->setup_pkt =
  80180. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  80181. + &pcd->setup_pkt_dma_handle);
  80182. + if (pcd->setup_pkt == NULL) {
  80183. + DWC_FREE(pcd);
  80184. + return NULL;
  80185. + }
  80186. +
  80187. + pcd->status_buf =
  80188. + DWC_DMA_ALLOC(sizeof(uint16_t),
  80189. + &pcd->status_buf_dma_handle);
  80190. + if (pcd->status_buf == NULL) {
  80191. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  80192. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  80193. + DWC_FREE(pcd);
  80194. + return NULL;
  80195. + }
  80196. +
  80197. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80198. + dev_if->setup_desc_addr[0] =
  80199. + dwc_otg_ep_alloc_desc_chain
  80200. + (&dev_if->dma_setup_desc_addr[0], 1);
  80201. + dev_if->setup_desc_addr[1] =
  80202. + dwc_otg_ep_alloc_desc_chain
  80203. + (&dev_if->dma_setup_desc_addr[1], 1);
  80204. + dev_if->in_desc_addr =
  80205. + dwc_otg_ep_alloc_desc_chain
  80206. + (&dev_if->dma_in_desc_addr, 1);
  80207. + dev_if->out_desc_addr =
  80208. + dwc_otg_ep_alloc_desc_chain
  80209. + (&dev_if->dma_out_desc_addr, 1);
  80210. + pcd->data_terminated = 0;
  80211. +
  80212. + if (dev_if->setup_desc_addr[0] == 0
  80213. + || dev_if->setup_desc_addr[1] == 0
  80214. + || dev_if->in_desc_addr == 0
  80215. + || dev_if->out_desc_addr == 0) {
  80216. +
  80217. + if (dev_if->out_desc_addr)
  80218. + dwc_otg_ep_free_desc_chain
  80219. + (dev_if->out_desc_addr,
  80220. + dev_if->dma_out_desc_addr, 1);
  80221. + if (dev_if->in_desc_addr)
  80222. + dwc_otg_ep_free_desc_chain
  80223. + (dev_if->in_desc_addr,
  80224. + dev_if->dma_in_desc_addr, 1);
  80225. + if (dev_if->setup_desc_addr[1])
  80226. + dwc_otg_ep_free_desc_chain
  80227. + (dev_if->setup_desc_addr[1],
  80228. + dev_if->dma_setup_desc_addr[1], 1);
  80229. + if (dev_if->setup_desc_addr[0])
  80230. + dwc_otg_ep_free_desc_chain
  80231. + (dev_if->setup_desc_addr[0],
  80232. + dev_if->dma_setup_desc_addr[0], 1);
  80233. +
  80234. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  80235. + pcd->setup_pkt,
  80236. + pcd->setup_pkt_dma_handle);
  80237. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  80238. + pcd->status_buf,
  80239. + pcd->status_buf_dma_handle);
  80240. +
  80241. + DWC_FREE(pcd);
  80242. +
  80243. + return NULL;
  80244. + }
  80245. + }
  80246. + } else {
  80247. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  80248. + if (pcd->setup_pkt == NULL) {
  80249. + DWC_FREE(pcd);
  80250. + return NULL;
  80251. + }
  80252. +
  80253. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  80254. + if (pcd->status_buf == NULL) {
  80255. + DWC_FREE(pcd->setup_pkt);
  80256. + DWC_FREE(pcd);
  80257. + return NULL;
  80258. + }
  80259. + }
  80260. +
  80261. + dwc_otg_pcd_reinit(pcd);
  80262. +
  80263. + /* Allocate the cfi object for the PCD */
  80264. +#ifdef DWC_UTE_CFI
  80265. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  80266. + if (NULL == pcd->cfi)
  80267. + goto fail;
  80268. + if (init_cfi(pcd->cfi)) {
  80269. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  80270. + goto fail;
  80271. + }
  80272. +#endif
  80273. +
  80274. + /* Initialize tasklets */
  80275. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  80276. + start_xfer_tasklet_func, pcd);
  80277. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  80278. + do_test_mode, pcd);
  80279. +
  80280. + /* Initialize SRP timer */
  80281. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  80282. +
  80283. + if (core_if->core_params->dev_out_nak) {
  80284. + /**
  80285. + * Initialize xfer timeout timer. Implemented for
  80286. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  80287. + */
  80288. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  80289. + pcd->core_if->ep_xfer_timer[i] =
  80290. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  80291. + &pcd->core_if->ep_xfer_info[i]);
  80292. + }
  80293. + }
  80294. +
  80295. + return pcd;
  80296. +#ifdef DWC_UTE_CFI
  80297. +fail:
  80298. +#endif
  80299. + if (pcd->setup_pkt)
  80300. + DWC_FREE(pcd->setup_pkt);
  80301. + if (pcd->status_buf)
  80302. + DWC_FREE(pcd->status_buf);
  80303. +#ifdef DWC_UTE_CFI
  80304. + if (pcd->cfi)
  80305. + DWC_FREE(pcd->cfi);
  80306. +#endif
  80307. + if (pcd)
  80308. + DWC_FREE(pcd);
  80309. + return NULL;
  80310. +
  80311. +}
  80312. +
  80313. +/**
  80314. + * Remove PCD specific data
  80315. + */
  80316. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  80317. +{
  80318. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  80319. + int i;
  80320. + if (pcd->core_if->core_params->dev_out_nak) {
  80321. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  80322. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  80323. + pcd->core_if->ep_xfer_info[i].state = 0;
  80324. + }
  80325. + }
  80326. +
  80327. + if (GET_CORE_IF(pcd)->dma_enable) {
  80328. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  80329. + pcd->setup_pkt_dma_handle);
  80330. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  80331. + pcd->status_buf_dma_handle);
  80332. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80333. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  80334. + dev_if->dma_setup_desc_addr
  80335. + [0], 1);
  80336. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  80337. + dev_if->dma_setup_desc_addr
  80338. + [1], 1);
  80339. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  80340. + dev_if->dma_in_desc_addr, 1);
  80341. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  80342. + dev_if->dma_out_desc_addr,
  80343. + 1);
  80344. + }
  80345. + } else {
  80346. + DWC_FREE(pcd->setup_pkt);
  80347. + DWC_FREE(pcd->status_buf);
  80348. + }
  80349. + DWC_SPINLOCK_FREE(pcd->lock);
  80350. + /* Set core_if's lock pointer to NULL */
  80351. + pcd->core_if->lock = NULL;
  80352. +
  80353. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  80354. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  80355. + if (pcd->core_if->core_params->dev_out_nak) {
  80356. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  80357. + if (pcd->core_if->ep_xfer_timer[i]) {
  80358. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  80359. + }
  80360. + }
  80361. + }
  80362. +
  80363. +/* Release the CFI object's dynamic memory */
  80364. +#ifdef DWC_UTE_CFI
  80365. + if (pcd->cfi->ops.release) {
  80366. + pcd->cfi->ops.release(pcd->cfi);
  80367. + }
  80368. +#endif
  80369. +
  80370. + DWC_FREE(pcd);
  80371. +}
  80372. +
  80373. +/**
  80374. + * Returns whether registered pcd is dual speed or not
  80375. + */
  80376. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  80377. +{
  80378. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80379. +
  80380. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  80381. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  80382. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  80383. + (core_if->core_params->ulpi_fs_ls))) {
  80384. + return 0;
  80385. + }
  80386. +
  80387. + return 1;
  80388. +}
  80389. +
  80390. +/**
  80391. + * Returns whether registered pcd is OTG capable or not
  80392. + */
  80393. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  80394. +{
  80395. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  80396. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  80397. +
  80398. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  80399. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  80400. + return 0;
  80401. + }
  80402. +
  80403. + return 1;
  80404. +}
  80405. +
  80406. +/**
  80407. + * This function assigns periodic Tx FIFO to an periodic EP
  80408. + * in shared Tx FIFO mode
  80409. + */
  80410. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  80411. +{
  80412. + uint32_t TxMsk = 1;
  80413. + int i;
  80414. +
  80415. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  80416. + if ((TxMsk & core_if->tx_msk) == 0) {
  80417. + core_if->tx_msk |= TxMsk;
  80418. + return i + 1;
  80419. + }
  80420. + TxMsk <<= 1;
  80421. + }
  80422. + return 0;
  80423. +}
  80424. +
  80425. +/**
  80426. + * This function assigns periodic Tx FIFO to an periodic EP
  80427. + * in shared Tx FIFO mode
  80428. + */
  80429. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  80430. +{
  80431. + uint32_t PerTxMsk = 1;
  80432. + int i;
  80433. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  80434. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  80435. + core_if->p_tx_msk |= PerTxMsk;
  80436. + return i + 1;
  80437. + }
  80438. + PerTxMsk <<= 1;
  80439. + }
  80440. + return 0;
  80441. +}
  80442. +
  80443. +/**
  80444. + * This function releases periodic Tx FIFO
  80445. + * in shared Tx FIFO mode
  80446. + */
  80447. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  80448. + uint32_t fifo_num)
  80449. +{
  80450. + core_if->p_tx_msk =
  80451. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  80452. +}
  80453. +
  80454. +/**
  80455. + * This function releases periodic Tx FIFO
  80456. + * in shared Tx FIFO mode
  80457. + */
  80458. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  80459. +{
  80460. + core_if->tx_msk =
  80461. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  80462. +}
  80463. +
  80464. +/**
  80465. + * This function is being called from gadget
  80466. + * to enable PCD endpoint.
  80467. + */
  80468. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  80469. + const uint8_t * ep_desc, void *usb_ep)
  80470. +{
  80471. + int num, dir;
  80472. + dwc_otg_pcd_ep_t *ep = NULL;
  80473. + const usb_endpoint_descriptor_t *desc;
  80474. + dwc_irqflags_t flags;
  80475. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  80476. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  80477. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  80478. + int retval = 0;
  80479. + int i, epcount;
  80480. +
  80481. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  80482. +
  80483. + if (!desc) {
  80484. + pcd->ep0.priv = usb_ep;
  80485. + ep = &pcd->ep0;
  80486. + retval = -DWC_E_INVALID;
  80487. + goto out;
  80488. + }
  80489. +
  80490. + num = UE_GET_ADDR(desc->bEndpointAddress);
  80491. + dir = UE_GET_DIR(desc->bEndpointAddress);
  80492. +
  80493. + if (!desc->wMaxPacketSize) {
  80494. + DWC_WARN("bad maxpacketsize\n");
  80495. + retval = -DWC_E_INVALID;
  80496. + goto out;
  80497. + }
  80498. +
  80499. + if (dir == UE_DIR_IN) {
  80500. + epcount = pcd->core_if->dev_if->num_in_eps;
  80501. + for (i = 0; i < epcount; i++) {
  80502. + if (num == pcd->in_ep[i].dwc_ep.num) {
  80503. + ep = &pcd->in_ep[i];
  80504. + break;
  80505. + }
  80506. + }
  80507. + } else {
  80508. + epcount = pcd->core_if->dev_if->num_out_eps;
  80509. + for (i = 0; i < epcount; i++) {
  80510. + if (num == pcd->out_ep[i].dwc_ep.num) {
  80511. + ep = &pcd->out_ep[i];
  80512. + break;
  80513. + }
  80514. + }
  80515. + }
  80516. +
  80517. + if (!ep) {
  80518. + DWC_WARN("bad address\n");
  80519. + retval = -DWC_E_INVALID;
  80520. + goto out;
  80521. + }
  80522. +
  80523. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80524. +
  80525. + ep->desc = desc;
  80526. + ep->priv = usb_ep;
  80527. +
  80528. + /*
  80529. + * Activate the EP
  80530. + */
  80531. + ep->stopped = 0;
  80532. +
  80533. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  80534. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  80535. +
  80536. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  80537. +
  80538. + if (ep->dwc_ep.is_in) {
  80539. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80540. + ep->dwc_ep.tx_fifo_num = 0;
  80541. +
  80542. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  80543. + /*
  80544. + * if ISOC EP then assign a Periodic Tx FIFO.
  80545. + */
  80546. + ep->dwc_ep.tx_fifo_num =
  80547. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  80548. + }
  80549. + } else {
  80550. + /*
  80551. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  80552. + */
  80553. + ep->dwc_ep.tx_fifo_num =
  80554. + assign_tx_fifo(GET_CORE_IF(pcd));
  80555. + }
  80556. +
  80557. + /* Calculating EP info controller base address */
  80558. + if (ep->dwc_ep.tx_fifo_num
  80559. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80560. + gdfifocfg.d32 =
  80561. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  80562. + core_global_regs->gdfifocfg);
  80563. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  80564. + dptxfsiz.d32 =
  80565. + (DWC_READ_REG32
  80566. + (&GET_CORE_IF(pcd)->core_global_regs->
  80567. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  80568. + gdfifocfg.b.epinfobase =
  80569. + gdfifocfgbase.d32 + dptxfsiz.d32;
  80570. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  80571. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  80572. + core_global_regs->gdfifocfg,
  80573. + gdfifocfg.d32);
  80574. + }
  80575. + }
  80576. + }
  80577. + /* Set initial data PID. */
  80578. + if (ep->dwc_ep.type == UE_BULK) {
  80579. + ep->dwc_ep.data_pid_start = 0;
  80580. + }
  80581. +
  80582. + /* Alloc DMA Descriptors */
  80583. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80584. +#ifndef DWC_UTE_PER_IO
  80585. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  80586. +#endif
  80587. + ep->dwc_ep.desc_addr =
  80588. + dwc_otg_ep_alloc_desc_chain(&ep->
  80589. + dwc_ep.dma_desc_addr,
  80590. + MAX_DMA_DESC_CNT);
  80591. + if (!ep->dwc_ep.desc_addr) {
  80592. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  80593. + __func__);
  80594. + retval = -DWC_E_SHUTDOWN;
  80595. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80596. + goto out;
  80597. + }
  80598. +#ifndef DWC_UTE_PER_IO
  80599. + }
  80600. +#endif
  80601. + }
  80602. +
  80603. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  80604. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  80605. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  80606. +#ifdef DWC_UTE_PER_IO
  80607. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  80608. +#endif
  80609. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  80610. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  80611. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  80612. + }
  80613. +
  80614. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  80615. +
  80616. +#ifdef DWC_UTE_CFI
  80617. + if (pcd->cfi->ops.ep_enable) {
  80618. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  80619. + }
  80620. +#endif
  80621. +
  80622. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80623. +
  80624. +out:
  80625. + return retval;
  80626. +}
  80627. +
  80628. +/**
  80629. + * This function is being called from gadget
  80630. + * to disable PCD endpoint.
  80631. + */
  80632. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  80633. +{
  80634. + dwc_otg_pcd_ep_t *ep;
  80635. + dwc_irqflags_t flags;
  80636. + dwc_otg_dev_dma_desc_t *desc_addr;
  80637. + dwc_dma_t dma_desc_addr;
  80638. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  80639. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  80640. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  80641. +
  80642. + ep = get_ep_from_handle(pcd, ep_handle);
  80643. +
  80644. + if (!ep || !ep->desc) {
  80645. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  80646. + return -DWC_E_INVALID;
  80647. + }
  80648. +
  80649. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  80650. +
  80651. + dwc_otg_request_nuke(ep);
  80652. +
  80653. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  80654. + if (pcd->core_if->core_params->dev_out_nak) {
  80655. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  80656. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  80657. + }
  80658. + ep->desc = NULL;
  80659. + ep->stopped = 1;
  80660. +
  80661. + gdfifocfg.d32 =
  80662. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  80663. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  80664. +
  80665. + if (ep->dwc_ep.is_in) {
  80666. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80667. + /* Flush the Tx FIFO */
  80668. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  80669. + ep->dwc_ep.tx_fifo_num);
  80670. + }
  80671. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  80672. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  80673. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  80674. + /* Decreasing EPinfo Base Addr */
  80675. + dptxfsiz.d32 =
  80676. + (DWC_READ_REG32
  80677. + (&GET_CORE_IF(pcd)->
  80678. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  80679. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  80680. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  80681. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  80682. + gdfifocfg.d32);
  80683. + }
  80684. + }
  80685. + }
  80686. +
  80687. + /* Free DMA Descriptors */
  80688. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  80689. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  80690. + desc_addr = ep->dwc_ep.desc_addr;
  80691. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  80692. +
  80693. + /* Cannot call dma_free_coherent() with IRQs disabled */
  80694. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80695. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  80696. + MAX_DMA_DESC_CNT);
  80697. +
  80698. + goto out_unlocked;
  80699. + }
  80700. + }
  80701. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  80702. +
  80703. +out_unlocked:
  80704. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  80705. + ep->dwc_ep.is_in ? "IN" : "OUT");
  80706. + return 0;
  80707. +
  80708. +}
  80709. +
  80710. +/******************************************************************************/
  80711. +#ifdef DWC_UTE_PER_IO
  80712. +
  80713. +/**
  80714. + * Free the request and its extended parts
  80715. + *
  80716. + */
  80717. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  80718. +{
  80719. + DWC_FREE(req->ext_req.per_io_frame_descs);
  80720. + DWC_FREE(req);
  80721. +}
  80722. +
  80723. +/**
  80724. + * Start the next request in the endpoint's queue.
  80725. + *
  80726. + */
  80727. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  80728. + dwc_otg_pcd_ep_t * ep)
  80729. +{
  80730. + int i;
  80731. + dwc_otg_pcd_request_t *req = NULL;
  80732. + dwc_ep_t *dwcep = NULL;
  80733. + struct dwc_iso_xreq_port *ereq = NULL;
  80734. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  80735. + uint16_t nat;
  80736. + depctl_data_t diepctl;
  80737. +
  80738. + dwcep = &ep->dwc_ep;
  80739. +
  80740. + if (dwcep->xiso_active_xfers > 0) {
  80741. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  80742. + DWC_WARN("There are currently active transfers for EP%d \
  80743. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  80744. + dwcep->xiso_queued_xfers);
  80745. +#endif
  80746. + return 0;
  80747. + }
  80748. +
  80749. + nat = UGETW(ep->desc->wMaxPacketSize);
  80750. + nat = (nat >> 11) & 0x03;
  80751. +
  80752. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80753. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  80754. + ereq = &req->ext_req;
  80755. + ep->stopped = 0;
  80756. +
  80757. + /* Get the frame number */
  80758. + dwcep->xiso_frame_num =
  80759. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  80760. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  80761. +
  80762. + ddesc_iso = ereq->per_io_frame_descs;
  80763. +
  80764. + if (dwcep->is_in) {
  80765. + /* Setup DMA Descriptor chain for IN Isoc request */
  80766. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80767. + //if ((i % (nat + 1)) == 0)
  80768. + if ( i > 0 )
  80769. + dwcep->xiso_frame_num =
  80770. + (dwcep->xiso_bInterval +
  80771. + dwcep->xiso_frame_num) & 0x3FFF;
  80772. + dwcep->desc_addr[i].buf =
  80773. + req->dma + ddesc_iso[i].offset;
  80774. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  80775. + ddesc_iso[i].length;
  80776. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  80777. + dwcep->xiso_frame_num;
  80778. + dwcep->desc_addr[i].status.b_iso_in.bs =
  80779. + BS_HOST_READY;
  80780. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  80781. + dwcep->desc_addr[i].status.b_iso_in.sp =
  80782. + (ddesc_iso[i].length %
  80783. + dwcep->maxpacket) ? 1 : 0;
  80784. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  80785. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  80786. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  80787. +
  80788. + /* Process the last descriptor */
  80789. + if (i == ereq->pio_pkt_count - 1) {
  80790. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  80791. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  80792. + }
  80793. + }
  80794. +
  80795. + /* Setup and start the transfer for this endpoint */
  80796. + dwcep->xiso_active_xfers++;
  80797. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  80798. + in_ep_regs[dwcep->num]->diepdma,
  80799. + dwcep->dma_desc_addr);
  80800. + diepctl.d32 = 0;
  80801. + diepctl.b.epena = 1;
  80802. + diepctl.b.cnak = 1;
  80803. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  80804. + in_ep_regs[dwcep->num]->diepctl, 0,
  80805. + diepctl.d32);
  80806. + } else {
  80807. + /* Setup DMA Descriptor chain for OUT Isoc request */
  80808. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80809. + //if ((i % (nat + 1)) == 0)
  80810. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  80811. + dwcep->xiso_frame_num) & 0x3FFF;
  80812. + dwcep->desc_addr[i].buf =
  80813. + req->dma + ddesc_iso[i].offset;
  80814. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  80815. + ddesc_iso[i].length;
  80816. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  80817. + dwcep->xiso_frame_num;
  80818. + dwcep->desc_addr[i].status.b_iso_out.bs =
  80819. + BS_HOST_READY;
  80820. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  80821. + dwcep->desc_addr[i].status.b_iso_out.sp =
  80822. + (ddesc_iso[i].length %
  80823. + dwcep->maxpacket) ? 1 : 0;
  80824. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  80825. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  80826. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  80827. +
  80828. + /* Process the last descriptor */
  80829. + if (i == ereq->pio_pkt_count - 1) {
  80830. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  80831. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  80832. + }
  80833. + }
  80834. +
  80835. + /* Setup and start the transfer for this endpoint */
  80836. + dwcep->xiso_active_xfers++;
  80837. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  80838. + dev_if->out_ep_regs[dwcep->num]->
  80839. + doepdma, dwcep->dma_desc_addr);
  80840. + diepctl.d32 = 0;
  80841. + diepctl.b.epena = 1;
  80842. + diepctl.b.cnak = 1;
  80843. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  80844. + dev_if->out_ep_regs[dwcep->num]->
  80845. + doepctl, 0, diepctl.d32);
  80846. + }
  80847. +
  80848. + } else {
  80849. + ep->stopped = 1;
  80850. + }
  80851. +
  80852. + return 0;
  80853. +}
  80854. +
  80855. +/**
  80856. + * - Remove the request from the queue
  80857. + */
  80858. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  80859. +{
  80860. + dwc_otg_pcd_request_t *req = NULL;
  80861. + struct dwc_iso_xreq_port *ereq = NULL;
  80862. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  80863. + dwc_ep_t *dwcep = NULL;
  80864. + int i;
  80865. +
  80866. + //DWC_DEBUG();
  80867. + dwcep = &ep->dwc_ep;
  80868. +
  80869. + /* Get the first pending request from the queue */
  80870. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  80871. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  80872. + if (!req) {
  80873. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  80874. + return;
  80875. + }
  80876. + dwcep->xiso_active_xfers--;
  80877. + dwcep->xiso_queued_xfers--;
  80878. + /* Remove this request from the queue */
  80879. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  80880. + } else {
  80881. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  80882. + return;
  80883. + }
  80884. +
  80885. + ep->stopped = 1;
  80886. + ereq = &req->ext_req;
  80887. + ddesc_iso = ereq->per_io_frame_descs;
  80888. +
  80889. + if (dwcep->xiso_active_xfers < 0) {
  80890. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  80891. + dwcep->xiso_active_xfers);
  80892. + }
  80893. +
  80894. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  80895. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80896. + if (dwcep->is_in) { /* IN endpoints */
  80897. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  80898. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  80899. + ddesc_iso[i].status =
  80900. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  80901. + } else { /* OUT endpoints */
  80902. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  80903. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  80904. + ddesc_iso[i].status =
  80905. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  80906. + }
  80907. + }
  80908. +
  80909. + DWC_SPINUNLOCK(ep->pcd->lock);
  80910. +
  80911. + /* Call the completion function in the non-portable logic */
  80912. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  80913. + &req->ext_req);
  80914. +
  80915. + DWC_SPINLOCK(ep->pcd->lock);
  80916. +
  80917. + /* Free the request - specific freeing needed for extended request object */
  80918. + dwc_pcd_xiso_ereq_free(ep, req);
  80919. +
  80920. + /* Start the next request */
  80921. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  80922. +
  80923. + return;
  80924. +}
  80925. +
  80926. +/**
  80927. + * Create and initialize the Isoc pkt descriptors of the extended request.
  80928. + *
  80929. + */
  80930. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  80931. + void *ereq_nonport,
  80932. + int atomic_alloc)
  80933. +{
  80934. + struct dwc_iso_xreq_port *ereq = NULL;
  80935. + struct dwc_iso_xreq_port *req_mapped = NULL;
  80936. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  80937. + uint32_t pkt_count;
  80938. + int i;
  80939. +
  80940. + ereq = &req->ext_req;
  80941. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  80942. + pkt_count = req_mapped->pio_pkt_count;
  80943. +
  80944. + /* Create the isoc descs */
  80945. + if (atomic_alloc) {
  80946. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  80947. + } else {
  80948. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  80949. + }
  80950. +
  80951. + if (!ipds) {
  80952. + DWC_ERROR("Failed to allocate isoc descriptors");
  80953. + return -DWC_E_NO_MEMORY;
  80954. + }
  80955. +
  80956. + /* Initialize the extended request fields */
  80957. + ereq->per_io_frame_descs = ipds;
  80958. + ereq->error_count = 0;
  80959. + ereq->pio_alloc_pkt_count = pkt_count;
  80960. + ereq->pio_pkt_count = pkt_count;
  80961. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  80962. +
  80963. + /* Init the Isoc descriptors */
  80964. + for (i = 0; i < pkt_count; i++) {
  80965. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  80966. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  80967. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  80968. + ipds[i].actual_length =
  80969. + req_mapped->per_io_frame_descs[i].actual_length;
  80970. + }
  80971. +
  80972. + return 0;
  80973. +}
  80974. +
  80975. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  80976. +{
  80977. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  80978. + int i;
  80979. +
  80980. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  80981. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  80982. + DWC_DEBUG("error_count=%d", ereq->error_count);
  80983. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  80984. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  80985. + DWC_DEBUG("res=%d", ereq->res);
  80986. +
  80987. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  80988. + xfd = &ereq->per_io_frame_descs[0];
  80989. + DWC_DEBUG("FD #%d", i);
  80990. +
  80991. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  80992. + DWC_DEBUG("xfd->length=%d", xfd->length);
  80993. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  80994. + DWC_DEBUG("xfd->status=%d", xfd->status);
  80995. + }
  80996. +}
  80997. +
  80998. +/**
  80999. + *
  81000. + */
  81001. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81002. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  81003. + int zero, void *req_handle, int atomic_alloc,
  81004. + void *ereq_nonport)
  81005. +{
  81006. + dwc_otg_pcd_request_t *req = NULL;
  81007. + dwc_otg_pcd_ep_t *ep;
  81008. + dwc_irqflags_t flags;
  81009. + int res;
  81010. +
  81011. + ep = get_ep_from_handle(pcd, ep_handle);
  81012. + if (!ep) {
  81013. + DWC_WARN("bad ep\n");
  81014. + return -DWC_E_INVALID;
  81015. + }
  81016. +
  81017. + /* We support this extension only for DDMA mode */
  81018. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  81019. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  81020. + return -DWC_E_INVALID;
  81021. +
  81022. + /* Create a dwc_otg_pcd_request_t object */
  81023. + if (atomic_alloc) {
  81024. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  81025. + } else {
  81026. + req = DWC_ALLOC(sizeof(*req));
  81027. + }
  81028. +
  81029. + if (!req) {
  81030. + return -DWC_E_NO_MEMORY;
  81031. + }
  81032. +
  81033. + /* Create the Isoc descs for this request which shall be the exact match
  81034. + * of the structure sent to us from the non-portable logic */
  81035. + res =
  81036. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  81037. + if (res) {
  81038. + DWC_WARN("Failed to init the Isoc descriptors");
  81039. + DWC_FREE(req);
  81040. + return res;
  81041. + }
  81042. +
  81043. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81044. +
  81045. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  81046. + req->buf = buf;
  81047. + req->dma = dma_buf;
  81048. + req->length = buflen;
  81049. + req->sent_zlp = zero;
  81050. + req->priv = req_handle;
  81051. +
  81052. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81053. + ep->dwc_ep.dma_addr = dma_buf;
  81054. + ep->dwc_ep.start_xfer_buff = buf;
  81055. + ep->dwc_ep.xfer_buff = buf;
  81056. + ep->dwc_ep.xfer_len = 0;
  81057. + ep->dwc_ep.xfer_count = 0;
  81058. + ep->dwc_ep.sent_zlp = 0;
  81059. + ep->dwc_ep.total_len = buflen;
  81060. +
  81061. + /* Add this request to the tail */
  81062. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81063. + ep->dwc_ep.xiso_queued_xfers++;
  81064. +
  81065. +//DWC_DEBUG("CP_0");
  81066. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  81067. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  81068. +//prn_ext_request(&req->ext_req);
  81069. +
  81070. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81071. +
  81072. + /* If the req->status == ASAP then check if there is any active transfer
  81073. + * for this endpoint. If no active transfers, then get the first entry
  81074. + * from the queue and start that transfer
  81075. + */
  81076. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  81077. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  81078. + if (res) {
  81079. + DWC_WARN("Failed to start the next Isoc transfer");
  81080. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81081. + DWC_FREE(req);
  81082. + return res;
  81083. + }
  81084. + }
  81085. +
  81086. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81087. + return 0;
  81088. +}
  81089. +
  81090. +#endif
  81091. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  81092. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81093. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  81094. + int zero, void *req_handle, int atomic_alloc)
  81095. +{
  81096. + dwc_irqflags_t flags;
  81097. + dwc_otg_pcd_request_t *req;
  81098. + dwc_otg_pcd_ep_t *ep;
  81099. + uint32_t max_transfer;
  81100. +
  81101. + ep = get_ep_from_handle(pcd, ep_handle);
  81102. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  81103. + DWC_WARN("bad ep\n");
  81104. + return -DWC_E_INVALID;
  81105. + }
  81106. +
  81107. + if (atomic_alloc) {
  81108. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  81109. + } else {
  81110. + req = DWC_ALLOC(sizeof(*req));
  81111. + }
  81112. +
  81113. + if (!req) {
  81114. + return -DWC_E_NO_MEMORY;
  81115. + }
  81116. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  81117. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  81118. + if (ep->dwc_ep.num != 0) {
  81119. + DWC_ERROR("queue req %p, len %d buf %p\n",
  81120. + req_handle, buflen, buf);
  81121. + }
  81122. + }
  81123. +
  81124. + req->buf = buf;
  81125. + req->dma = dma_buf;
  81126. + req->length = buflen;
  81127. + req->sent_zlp = zero;
  81128. + req->priv = req_handle;
  81129. + req->dw_align_buf = NULL;
  81130. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  81131. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  81132. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  81133. + &req->dw_align_buf_dma);
  81134. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81135. +
  81136. + /*
  81137. + * After adding request to the queue for IN ISOC wait for In Token Received
  81138. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  81139. + * Received when EP is disabled interrupt to obtain starting microframe
  81140. + * (odd/even) start transfer
  81141. + */
  81142. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  81143. + if (req != 0) {
  81144. + depctl_data_t depctl = {.d32 =
  81145. + DWC_READ_REG32(&pcd->core_if->dev_if->
  81146. + in_ep_regs[ep->dwc_ep.num]->
  81147. + diepctl) };
  81148. + ++pcd->request_pending;
  81149. +
  81150. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81151. + if (ep->dwc_ep.is_in) {
  81152. + depctl.b.cnak = 1;
  81153. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  81154. + in_ep_regs[ep->dwc_ep.num]->
  81155. + diepctl, depctl.d32);
  81156. + }
  81157. +
  81158. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81159. + }
  81160. + return 0;
  81161. + }
  81162. +
  81163. + /*
  81164. + * For EP0 IN without premature status, zlp is required?
  81165. + */
  81166. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  81167. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  81168. + //_req->zero = 1;
  81169. + }
  81170. +
  81171. + /* Start the transfer */
  81172. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  81173. + /* EP0 Transfer? */
  81174. + if (ep->dwc_ep.num == 0) {
  81175. + switch (pcd->ep0state) {
  81176. + case EP0_IN_DATA_PHASE:
  81177. + DWC_DEBUGPL(DBG_PCD,
  81178. + "%s ep0: EP0_IN_DATA_PHASE\n",
  81179. + __func__);
  81180. + break;
  81181. +
  81182. + case EP0_OUT_DATA_PHASE:
  81183. + DWC_DEBUGPL(DBG_PCD,
  81184. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  81185. + __func__);
  81186. + if (pcd->request_config) {
  81187. + /* Complete STATUS PHASE */
  81188. + ep->dwc_ep.is_in = 1;
  81189. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  81190. + }
  81191. + break;
  81192. +
  81193. + case EP0_IN_STATUS_PHASE:
  81194. + DWC_DEBUGPL(DBG_PCD,
  81195. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  81196. + __func__);
  81197. + break;
  81198. +
  81199. + default:
  81200. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  81201. + pcd->ep0state);
  81202. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81203. + return -DWC_E_SHUTDOWN;
  81204. + }
  81205. +
  81206. + ep->dwc_ep.dma_addr = dma_buf;
  81207. + ep->dwc_ep.start_xfer_buff = buf;
  81208. + ep->dwc_ep.xfer_buff = buf;
  81209. + ep->dwc_ep.xfer_len = buflen;
  81210. + ep->dwc_ep.xfer_count = 0;
  81211. + ep->dwc_ep.sent_zlp = 0;
  81212. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  81213. +
  81214. + if (zero) {
  81215. + if ((ep->dwc_ep.xfer_len %
  81216. + ep->dwc_ep.maxpacket == 0)
  81217. + && (ep->dwc_ep.xfer_len != 0)) {
  81218. + ep->dwc_ep.sent_zlp = 1;
  81219. + }
  81220. +
  81221. + }
  81222. +
  81223. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  81224. + &ep->dwc_ep);
  81225. + } // non-ep0 endpoints
  81226. + else {
  81227. +#ifdef DWC_UTE_CFI
  81228. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  81229. + /* store the request length */
  81230. + ep->dwc_ep.cfi_req_len = buflen;
  81231. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  81232. + ep, req);
  81233. + } else {
  81234. +#endif
  81235. + max_transfer =
  81236. + GET_CORE_IF(ep->pcd)->core_params->
  81237. + max_transfer_size;
  81238. +
  81239. + /* Setup and start the Transfer */
  81240. + if (req->dw_align_buf){
  81241. + if (ep->dwc_ep.is_in)
  81242. + dwc_memcpy(req->dw_align_buf,
  81243. + buf, buflen);
  81244. + ep->dwc_ep.dma_addr =
  81245. + req->dw_align_buf_dma;
  81246. + ep->dwc_ep.start_xfer_buff =
  81247. + req->dw_align_buf;
  81248. + ep->dwc_ep.xfer_buff =
  81249. + req->dw_align_buf;
  81250. + } else {
  81251. + ep->dwc_ep.dma_addr = dma_buf;
  81252. + ep->dwc_ep.start_xfer_buff = buf;
  81253. + ep->dwc_ep.xfer_buff = buf;
  81254. + }
  81255. + ep->dwc_ep.xfer_len = 0;
  81256. + ep->dwc_ep.xfer_count = 0;
  81257. + ep->dwc_ep.sent_zlp = 0;
  81258. + ep->dwc_ep.total_len = buflen;
  81259. +
  81260. + ep->dwc_ep.maxxfer = max_transfer;
  81261. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  81262. + uint32_t out_max_xfer =
  81263. + DDMA_MAX_TRANSFER_SIZE -
  81264. + (DDMA_MAX_TRANSFER_SIZE % 4);
  81265. + if (ep->dwc_ep.is_in) {
  81266. + if (ep->dwc_ep.maxxfer >
  81267. + DDMA_MAX_TRANSFER_SIZE) {
  81268. + ep->dwc_ep.maxxfer =
  81269. + DDMA_MAX_TRANSFER_SIZE;
  81270. + }
  81271. + } else {
  81272. + if (ep->dwc_ep.maxxfer >
  81273. + out_max_xfer) {
  81274. + ep->dwc_ep.maxxfer =
  81275. + out_max_xfer;
  81276. + }
  81277. + }
  81278. + }
  81279. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  81280. + ep->dwc_ep.maxxfer -=
  81281. + (ep->dwc_ep.maxxfer %
  81282. + ep->dwc_ep.maxpacket);
  81283. + }
  81284. +
  81285. + if (zero) {
  81286. + if ((ep->dwc_ep.total_len %
  81287. + ep->dwc_ep.maxpacket == 0)
  81288. + && (ep->dwc_ep.total_len != 0)) {
  81289. + ep->dwc_ep.sent_zlp = 1;
  81290. + }
  81291. + }
  81292. +#ifdef DWC_UTE_CFI
  81293. + }
  81294. +#endif
  81295. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  81296. + &ep->dwc_ep);
  81297. + }
  81298. + }
  81299. +
  81300. + if (req != 0) {
  81301. + ++pcd->request_pending;
  81302. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  81303. + if (ep->dwc_ep.is_in && ep->stopped
  81304. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  81305. + /** @todo NGS Create a function for this. */
  81306. + diepmsk_data_t diepmsk = {.d32 = 0 };
  81307. + diepmsk.b.intktxfemp = 1;
  81308. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  81309. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81310. + dev_if->dev_global_regs->diepeachintmsk
  81311. + [ep->dwc_ep.num], 0,
  81312. + diepmsk.d32);
  81313. + } else {
  81314. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  81315. + dev_if->dev_global_regs->
  81316. + diepmsk, 0, diepmsk.d32);
  81317. + }
  81318. +
  81319. + }
  81320. + }
  81321. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81322. +
  81323. + return 0;
  81324. +}
  81325. +
  81326. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  81327. + void *req_handle)
  81328. +{
  81329. + dwc_irqflags_t flags;
  81330. + dwc_otg_pcd_request_t *req;
  81331. + dwc_otg_pcd_ep_t *ep;
  81332. +
  81333. + ep = get_ep_from_handle(pcd, ep_handle);
  81334. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  81335. + DWC_WARN("bad argument\n");
  81336. + return -DWC_E_INVALID;
  81337. + }
  81338. +
  81339. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81340. +
  81341. + /* make sure it's actually queued on this endpoint */
  81342. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  81343. + if (req->priv == (void *)req_handle) {
  81344. + break;
  81345. + }
  81346. + }
  81347. +
  81348. + if (req->priv != (void *)req_handle) {
  81349. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81350. + return -DWC_E_INVALID;
  81351. + }
  81352. +
  81353. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  81354. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  81355. + } else {
  81356. + req = NULL;
  81357. + }
  81358. +
  81359. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81360. +
  81361. + return req ? 0 : -DWC_E_SHUTDOWN;
  81362. +
  81363. +}
  81364. +
  81365. +/**
  81366. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  81367. + *
  81368. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  81369. + * requests. If the gadget driver clears the halt status, it will
  81370. + * automatically unwedge the endpoint.
  81371. + *
  81372. + * Returns zero on success, else negative DWC error code.
  81373. + */
  81374. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  81375. +{
  81376. + dwc_otg_pcd_ep_t *ep;
  81377. + dwc_irqflags_t flags;
  81378. + int retval = 0;
  81379. +
  81380. + ep = get_ep_from_handle(pcd, ep_handle);
  81381. +
  81382. + if ((!ep->desc && ep != &pcd->ep0) ||
  81383. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  81384. + DWC_WARN("%s, bad ep\n", __func__);
  81385. + return -DWC_E_INVALID;
  81386. + }
  81387. +
  81388. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81389. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81390. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  81391. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81392. + retval = -DWC_E_AGAIN;
  81393. + } else {
  81394. + /* This code needs to be reviewed */
  81395. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  81396. + dtxfsts_data_t txstatus;
  81397. + fifosize_data_t txfifosize;
  81398. +
  81399. + txfifosize.d32 =
  81400. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81401. + core_global_regs->dtxfsiz[ep->dwc_ep.
  81402. + tx_fifo_num]);
  81403. + txstatus.d32 =
  81404. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  81405. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  81406. + dtxfsts);
  81407. +
  81408. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  81409. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  81410. + retval = -DWC_E_AGAIN;
  81411. + } else {
  81412. + if (ep->dwc_ep.num == 0) {
  81413. + pcd->ep0state = EP0_STALL;
  81414. + }
  81415. +
  81416. + ep->stopped = 1;
  81417. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  81418. + &ep->dwc_ep);
  81419. + }
  81420. + } else {
  81421. + if (ep->dwc_ep.num == 0) {
  81422. + pcd->ep0state = EP0_STALL;
  81423. + }
  81424. +
  81425. + ep->stopped = 1;
  81426. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81427. + }
  81428. + }
  81429. +
  81430. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81431. +
  81432. + return retval;
  81433. +}
  81434. +
  81435. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  81436. +{
  81437. + dwc_otg_pcd_ep_t *ep;
  81438. + dwc_irqflags_t flags;
  81439. + int retval = 0;
  81440. +
  81441. + ep = get_ep_from_handle(pcd, ep_handle);
  81442. +
  81443. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  81444. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  81445. + DWC_WARN("%s, bad ep\n", __func__);
  81446. + return -DWC_E_INVALID;
  81447. + }
  81448. +
  81449. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81450. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81451. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  81452. + ep->dwc_ep.is_in ? "IN" : "OUT");
  81453. + retval = -DWC_E_AGAIN;
  81454. + } else if (value == 0) {
  81455. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81456. + } else if (value == 1) {
  81457. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  81458. + dtxfsts_data_t txstatus;
  81459. + fifosize_data_t txfifosize;
  81460. +
  81461. + txfifosize.d32 =
  81462. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  81463. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  81464. + txstatus.d32 =
  81465. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  81466. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  81467. +
  81468. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  81469. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  81470. + retval = -DWC_E_AGAIN;
  81471. + } else {
  81472. + if (ep->dwc_ep.num == 0) {
  81473. + pcd->ep0state = EP0_STALL;
  81474. + }
  81475. +
  81476. + ep->stopped = 1;
  81477. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  81478. + &ep->dwc_ep);
  81479. + }
  81480. + } else {
  81481. + if (ep->dwc_ep.num == 0) {
  81482. + pcd->ep0state = EP0_STALL;
  81483. + }
  81484. +
  81485. + ep->stopped = 1;
  81486. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  81487. + }
  81488. + } else if (value == 2) {
  81489. + ep->dwc_ep.stall_clear_flag = 0;
  81490. + } else if (value == 3) {
  81491. + ep->dwc_ep.stall_clear_flag = 1;
  81492. + }
  81493. +
  81494. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81495. +
  81496. + return retval;
  81497. +}
  81498. +
  81499. +/**
  81500. + * This function initiates remote wakeup of the host from suspend state.
  81501. + */
  81502. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  81503. +{
  81504. + dctl_data_t dctl = { 0 };
  81505. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81506. + dsts_data_t dsts;
  81507. +
  81508. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81509. + if (!dsts.b.suspsts) {
  81510. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  81511. + }
  81512. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  81513. + if (pcd->remote_wakeup_enable) {
  81514. + if (set) {
  81515. +
  81516. + if (core_if->adp_enable) {
  81517. + gpwrdn_data_t gpwrdn;
  81518. +
  81519. + dwc_otg_adp_probe_stop(core_if);
  81520. +
  81521. + /* Mask SRP detected interrupt from Power Down Logic */
  81522. + gpwrdn.d32 = 0;
  81523. + gpwrdn.b.srp_det_msk = 1;
  81524. + DWC_MODIFY_REG32(&core_if->
  81525. + core_global_regs->gpwrdn,
  81526. + gpwrdn.d32, 0);
  81527. +
  81528. + /* Disable Power Down Logic */
  81529. + gpwrdn.d32 = 0;
  81530. + gpwrdn.b.pmuactv = 1;
  81531. + DWC_MODIFY_REG32(&core_if->
  81532. + core_global_regs->gpwrdn,
  81533. + gpwrdn.d32, 0);
  81534. +
  81535. + /*
  81536. + * Initialize the Core for Device mode.
  81537. + */
  81538. + core_if->op_state = B_PERIPHERAL;
  81539. + dwc_otg_core_init(core_if);
  81540. + dwc_otg_enable_global_interrupts(core_if);
  81541. + cil_pcd_start(core_if);
  81542. +
  81543. + dwc_otg_initiate_srp(core_if);
  81544. + }
  81545. +
  81546. + dctl.b.rmtwkupsig = 1;
  81547. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  81548. + dctl, 0, dctl.d32);
  81549. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  81550. +
  81551. + dwc_mdelay(2);
  81552. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  81553. + dctl, dctl.d32, 0);
  81554. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  81555. + }
  81556. + } else {
  81557. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  81558. + }
  81559. +}
  81560. +
  81561. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81562. +/**
  81563. + * This function initiates remote wakeup of the host from L1 sleep state.
  81564. + */
  81565. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  81566. +{
  81567. + glpmcfg_data_t lpmcfg;
  81568. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81569. +
  81570. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  81571. +
  81572. + /* Check if we are in L1 state */
  81573. + if (!lpmcfg.b.prt_sleep_sts) {
  81574. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  81575. + return;
  81576. + }
  81577. +
  81578. + /* Check if host allows remote wakeup */
  81579. + if (!lpmcfg.b.rem_wkup_en) {
  81580. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  81581. + return;
  81582. + }
  81583. +
  81584. + /* Check if Resume OK */
  81585. + if (!lpmcfg.b.sleep_state_resumeok) {
  81586. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  81587. + return;
  81588. + }
  81589. +
  81590. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  81591. + lpmcfg.b.en_utmi_sleep = 0;
  81592. + lpmcfg.b.hird_thres &= (~(1 << 4));
  81593. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  81594. +
  81595. + if (set) {
  81596. + dctl_data_t dctl = {.d32 = 0 };
  81597. + dctl.b.rmtwkupsig = 1;
  81598. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  81599. + * Hardware will automatically clear this bit.
  81600. + */
  81601. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  81602. + 0, dctl.d32);
  81603. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  81604. + }
  81605. +
  81606. +}
  81607. +#endif
  81608. +
  81609. +/**
  81610. + * Performs remote wakeup.
  81611. + */
  81612. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  81613. +{
  81614. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81615. + dwc_irqflags_t flags;
  81616. + if (dwc_otg_is_device_mode(core_if)) {
  81617. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81618. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81619. + if (core_if->lx_state == DWC_OTG_L1) {
  81620. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  81621. + } else {
  81622. +#endif
  81623. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  81624. +#ifdef CONFIG_USB_DWC_OTG_LPM
  81625. + }
  81626. +#endif
  81627. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81628. + }
  81629. + return;
  81630. +}
  81631. +
  81632. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  81633. +{
  81634. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81635. + dctl_data_t dctl = { 0 };
  81636. +
  81637. + if (dwc_otg_is_device_mode(core_if)) {
  81638. + dctl.b.sftdiscon = 1;
  81639. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  81640. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  81641. + dwc_udelay(no_of_usecs);
  81642. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  81643. +
  81644. + } else{
  81645. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  81646. + }
  81647. + return;
  81648. +
  81649. +}
  81650. +
  81651. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  81652. +{
  81653. + dsts_data_t dsts;
  81654. + gotgctl_data_t gotgctl;
  81655. +
  81656. + /*
  81657. + * This function starts the Protocol if no session is in progress. If
  81658. + * a session is already in progress, but the device is suspended,
  81659. + * remote wakeup signaling is started.
  81660. + */
  81661. +
  81662. + /* Check if valid session */
  81663. + gotgctl.d32 =
  81664. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  81665. + if (gotgctl.b.bsesvld) {
  81666. + /* Check if suspend state */
  81667. + dsts.d32 =
  81668. + DWC_READ_REG32(&
  81669. + (GET_CORE_IF(pcd)->dev_if->
  81670. + dev_global_regs->dsts));
  81671. + if (dsts.b.suspsts) {
  81672. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  81673. + }
  81674. + } else {
  81675. + dwc_otg_pcd_initiate_srp(pcd);
  81676. + }
  81677. +
  81678. + return 0;
  81679. +
  81680. +}
  81681. +
  81682. +/**
  81683. + * Start the SRP timer to detect when the SRP does not complete within
  81684. + * 6 seconds.
  81685. + *
  81686. + * @param pcd the pcd structure.
  81687. + */
  81688. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  81689. +{
  81690. + dwc_irqflags_t flags;
  81691. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81692. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  81693. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81694. +}
  81695. +
  81696. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  81697. +{
  81698. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  81699. +}
  81700. +
  81701. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  81702. +{
  81703. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  81704. +}
  81705. +
  81706. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  81707. +{
  81708. + return pcd->b_hnp_enable;
  81709. +}
  81710. +
  81711. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  81712. +{
  81713. + return pcd->a_hnp_support;
  81714. +}
  81715. +
  81716. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  81717. +{
  81718. + return pcd->a_alt_hnp_support;
  81719. +}
  81720. +
  81721. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  81722. +{
  81723. + return pcd->remote_wakeup_enable;
  81724. +}
  81725. +
  81726. +#endif /* DWC_HOST_ONLY */
  81727. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  81728. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  81729. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-02-07 19:57:30.000000000 +0100
  81730. @@ -0,0 +1,266 @@
  81731. +/* ==========================================================================
  81732. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  81733. + * $Revision: #48 $
  81734. + * $Date: 2012/08/10 $
  81735. + * $Change: 2047372 $
  81736. + *
  81737. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81738. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81739. + * otherwise expressly agreed to in writing between Synopsys and you.
  81740. + *
  81741. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81742. + * any End User Software License Agreement or Agreement for Licensed Product
  81743. + * with Synopsys or any supplement thereto. You are permitted to use and
  81744. + * redistribute this Software in source and binary forms, with or without
  81745. + * modification, provided that redistributions of source code must retain this
  81746. + * notice. You may not view, use, disclose, copy or distribute this file or
  81747. + * any information contained herein except pursuant to this license grant from
  81748. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81749. + * below, then you are not authorized to use the Software.
  81750. + *
  81751. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81752. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81753. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81754. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81755. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81756. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81757. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81758. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81759. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81760. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81761. + * DAMAGE.
  81762. + * ========================================================================== */
  81763. +#ifndef DWC_HOST_ONLY
  81764. +#if !defined(__DWC_PCD_H__)
  81765. +#define __DWC_PCD_H__
  81766. +
  81767. +#include "dwc_otg_os_dep.h"
  81768. +#include "usb.h"
  81769. +#include "dwc_otg_cil.h"
  81770. +#include "dwc_otg_pcd_if.h"
  81771. +struct cfiobject;
  81772. +
  81773. +/**
  81774. + * @file
  81775. + *
  81776. + * This file contains the structures, constants, and interfaces for
  81777. + * the Perpherial Contoller Driver (PCD).
  81778. + *
  81779. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  81780. + * Gadget API, so that the existing Gadget drivers can be used. For
  81781. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  81782. + * (FBS) driver will be used. The FBS driver supports the
  81783. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  81784. + * transports.
  81785. + *
  81786. + */
  81787. +
  81788. +/** Invalid DMA Address */
  81789. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  81790. +
  81791. +/** Max Transfer size for any EP */
  81792. +#define DDMA_MAX_TRANSFER_SIZE 65535
  81793. +
  81794. +/**
  81795. + * Get the pointer to the core_if from the pcd pointer.
  81796. + */
  81797. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  81798. +
  81799. +/**
  81800. + * States of EP0.
  81801. + */
  81802. +typedef enum ep0_state {
  81803. + EP0_DISCONNECT, /* no host */
  81804. + EP0_IDLE,
  81805. + EP0_IN_DATA_PHASE,
  81806. + EP0_OUT_DATA_PHASE,
  81807. + EP0_IN_STATUS_PHASE,
  81808. + EP0_OUT_STATUS_PHASE,
  81809. + EP0_STALL,
  81810. +} ep0state_e;
  81811. +
  81812. +/** Fordward declaration.*/
  81813. +struct dwc_otg_pcd;
  81814. +
  81815. +/** DWC_otg iso request structure.
  81816. + *
  81817. + */
  81818. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  81819. +
  81820. +#ifdef DWC_UTE_PER_IO
  81821. +
  81822. +/**
  81823. + * This shall be the exact analogy of the same type structure defined in the
  81824. + * usb_gadget.h. Each descriptor contains
  81825. + */
  81826. +struct dwc_iso_pkt_desc_port {
  81827. + uint32_t offset;
  81828. + uint32_t length; /* expected length */
  81829. + uint32_t actual_length;
  81830. + uint32_t status;
  81831. +};
  81832. +
  81833. +struct dwc_iso_xreq_port {
  81834. + /** transfer/submission flag */
  81835. + uint32_t tr_sub_flags;
  81836. + /** Start the request ASAP */
  81837. +#define DWC_EREQ_TF_ASAP 0x00000002
  81838. + /** Just enqueue the request w/o initiating a transfer */
  81839. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  81840. +
  81841. + /**
  81842. + * count of ISO packets attached to this request - shall
  81843. + * not exceed the pio_alloc_pkt_count
  81844. + */
  81845. + uint32_t pio_pkt_count;
  81846. + /** count of ISO packets allocated for this request */
  81847. + uint32_t pio_alloc_pkt_count;
  81848. + /** number of ISO packet errors */
  81849. + uint32_t error_count;
  81850. + /** reserved for future extension */
  81851. + uint32_t res;
  81852. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  81853. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  81854. +};
  81855. +#endif
  81856. +/** DWC_otg request structure.
  81857. + * This structure is a list of requests.
  81858. + */
  81859. +typedef struct dwc_otg_pcd_request {
  81860. + void *priv;
  81861. + void *buf;
  81862. + dwc_dma_t dma;
  81863. + uint32_t length;
  81864. + uint32_t actual;
  81865. + unsigned sent_zlp:1;
  81866. + /**
  81867. + * Used instead of original buffer if
  81868. + * it(physical address) is not dword-aligned.
  81869. + **/
  81870. + uint8_t *dw_align_buf;
  81871. + dwc_dma_t dw_align_buf_dma;
  81872. +
  81873. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  81874. +#ifdef DWC_UTE_PER_IO
  81875. + struct dwc_iso_xreq_port ext_req;
  81876. + //void *priv_ereq_nport; /* */
  81877. +#endif
  81878. +} dwc_otg_pcd_request_t;
  81879. +
  81880. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  81881. +
  81882. +/** PCD EP structure.
  81883. + * This structure describes an EP, there is an array of EPs in the PCD
  81884. + * structure.
  81885. + */
  81886. +typedef struct dwc_otg_pcd_ep {
  81887. + /** USB EP Descriptor */
  81888. + const usb_endpoint_descriptor_t *desc;
  81889. +
  81890. + /** queue of dwc_otg_pcd_requests. */
  81891. + struct req_list queue;
  81892. + unsigned stopped:1;
  81893. + unsigned disabling:1;
  81894. + unsigned dma:1;
  81895. + unsigned queue_sof:1;
  81896. +
  81897. +#ifdef DWC_EN_ISOC
  81898. + /** ISOC req handle passed */
  81899. + void *iso_req_handle;
  81900. +#endif //_EN_ISOC_
  81901. +
  81902. + /** DWC_otg ep data. */
  81903. + dwc_ep_t dwc_ep;
  81904. +
  81905. + /** Pointer to PCD */
  81906. + struct dwc_otg_pcd *pcd;
  81907. +
  81908. + void *priv;
  81909. +} dwc_otg_pcd_ep_t;
  81910. +
  81911. +/** DWC_otg PCD Structure.
  81912. + * This structure encapsulates the data for the dwc_otg PCD.
  81913. + */
  81914. +struct dwc_otg_pcd {
  81915. + const struct dwc_otg_pcd_function_ops *fops;
  81916. + /** The DWC otg device pointer */
  81917. + struct dwc_otg_device *otg_dev;
  81918. + /** Core Interface */
  81919. + dwc_otg_core_if_t *core_if;
  81920. + /** State of EP0 */
  81921. + ep0state_e ep0state;
  81922. + /** EP0 Request is pending */
  81923. + unsigned ep0_pending:1;
  81924. + /** Indicates when SET CONFIGURATION Request is in process */
  81925. + unsigned request_config:1;
  81926. + /** The state of the Remote Wakeup Enable. */
  81927. + unsigned remote_wakeup_enable:1;
  81928. + /** The state of the B-Device HNP Enable. */
  81929. + unsigned b_hnp_enable:1;
  81930. + /** The state of A-Device HNP Support. */
  81931. + unsigned a_hnp_support:1;
  81932. + /** The state of the A-Device Alt HNP support. */
  81933. + unsigned a_alt_hnp_support:1;
  81934. + /** Count of pending Requests */
  81935. + unsigned request_pending;
  81936. +
  81937. + /** SETUP packet for EP0
  81938. + * This structure is allocated as a DMA buffer on PCD initialization
  81939. + * with enough space for up to 3 setup packets.
  81940. + */
  81941. + union {
  81942. + usb_device_request_t req;
  81943. + uint32_t d32[2];
  81944. + } *setup_pkt;
  81945. +
  81946. + dwc_dma_t setup_pkt_dma_handle;
  81947. +
  81948. + /* Additional buffer and flag for CTRL_WR premature case */
  81949. + uint8_t *backup_buf;
  81950. + unsigned data_terminated;
  81951. +
  81952. + /** 2-byte dma buffer used to return status from GET_STATUS */
  81953. + uint16_t *status_buf;
  81954. + dwc_dma_t status_buf_dma_handle;
  81955. +
  81956. + /** EP0 */
  81957. + dwc_otg_pcd_ep_t ep0;
  81958. +
  81959. + /** Array of IN EPs. */
  81960. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  81961. + /** Array of OUT EPs. */
  81962. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  81963. + /** number of valid EPs in the above array. */
  81964. +// unsigned num_eps : 4;
  81965. + dwc_spinlock_t *lock;
  81966. +
  81967. + /** Tasklet to defer starting of TEST mode transmissions until
  81968. + * Status Phase has been completed.
  81969. + */
  81970. + dwc_tasklet_t *test_mode_tasklet;
  81971. +
  81972. + /** Tasklet to delay starting of xfer in DMA mode */
  81973. + dwc_tasklet_t *start_xfer_tasklet;
  81974. +
  81975. + /** The test mode to enter when the tasklet is executed. */
  81976. + unsigned test_mode;
  81977. + /** The cfi_api structure that implements most of the CFI API
  81978. + * and OTG specific core configuration functionality
  81979. + */
  81980. +#ifdef DWC_UTE_CFI
  81981. + struct cfiobject *cfi;
  81982. +#endif
  81983. +
  81984. +};
  81985. +
  81986. +//FIXME this functions should be static, and this prototypes should be removed
  81987. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  81988. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  81989. + dwc_otg_pcd_request_t * req, int32_t status);
  81990. +
  81991. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  81992. + void *req_handle);
  81993. +
  81994. +extern void do_test_mode(void *data);
  81995. +#endif
  81996. +#endif /* DWC_HOST_ONLY */
  81997. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  81998. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  81999. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-02-07 19:57:30.000000000 +0100
  82000. @@ -0,0 +1,360 @@
  82001. +/* ==========================================================================
  82002. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  82003. + * $Revision: #11 $
  82004. + * $Date: 2011/10/26 $
  82005. + * $Change: 1873028 $
  82006. + *
  82007. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82008. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82009. + * otherwise expressly agreed to in writing between Synopsys and you.
  82010. + *
  82011. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82012. + * any End User Software License Agreement or Agreement for Licensed Product
  82013. + * with Synopsys or any supplement thereto. You are permitted to use and
  82014. + * redistribute this Software in source and binary forms, with or without
  82015. + * modification, provided that redistributions of source code must retain this
  82016. + * notice. You may not view, use, disclose, copy or distribute this file or
  82017. + * any information contained herein except pursuant to this license grant from
  82018. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82019. + * below, then you are not authorized to use the Software.
  82020. + *
  82021. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82022. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82023. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82024. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82025. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82026. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82027. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82028. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82029. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82030. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82031. + * DAMAGE.
  82032. + * ========================================================================== */
  82033. +#ifndef DWC_HOST_ONLY
  82034. +
  82035. +#if !defined(__DWC_PCD_IF_H__)
  82036. +#define __DWC_PCD_IF_H__
  82037. +
  82038. +//#include "dwc_os.h"
  82039. +#include "dwc_otg_core_if.h"
  82040. +
  82041. +/** @file
  82042. + * This file defines DWC_OTG PCD Core API.
  82043. + */
  82044. +
  82045. +struct dwc_otg_pcd;
  82046. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  82047. +
  82048. +/** Maxpacket size for EP0 */
  82049. +#define MAX_EP0_SIZE 64
  82050. +/** Maxpacket size for any EP */
  82051. +#define MAX_PACKET_SIZE 1024
  82052. +
  82053. +/** @name Function Driver Callbacks */
  82054. +/** @{ */
  82055. +
  82056. +/** This function will be called whenever a previously queued request has
  82057. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  82058. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  82059. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  82060. + * parameters. */
  82061. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82062. + void *req_handle, int32_t status,
  82063. + uint32_t actual);
  82064. +/**
  82065. + * This function will be called whenever a previousle queued ISOC request has
  82066. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  82067. + * function.
  82068. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  82069. + * functions.
  82070. + */
  82071. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82072. + void *req_handle, int proc_buf_num);
  82073. +/** This function should handle any SETUP request that cannot be handled by the
  82074. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  82075. + * class-specific requests, etc. The function must non-blocking.
  82076. + *
  82077. + * Returns 0 on success.
  82078. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  82079. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  82080. + * Returns -DWC_E_SHUTDOWN on any other error. */
  82081. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  82082. +/** This is called whenever the device has been disconnected. The function
  82083. + * driver should take appropriate action to clean up all pending requests in the
  82084. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  82085. + * state. */
  82086. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  82087. +/** This function is called when device has been connected. */
  82088. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  82089. +/** This function is called when device has been suspended */
  82090. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  82091. +/** This function is called when device has received LPM tokens, i.e.
  82092. + * device has been sent to sleep state. */
  82093. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  82094. +/** This function is called when device has been resumed
  82095. + * from suspend(L2) or L1 sleep state. */
  82096. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  82097. +/** This function is called whenever hnp params has been changed.
  82098. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  82099. + * to get hnp parameters. */
  82100. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  82101. +/** This function is called whenever USB RESET is detected. */
  82102. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  82103. +
  82104. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  82105. +
  82106. +/**
  82107. + *
  82108. + * @param ep_handle Void pointer to the usb_ep structure
  82109. + * @param ereq_port Pointer to the extended request structure created in the
  82110. + * portable part.
  82111. + */
  82112. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  82113. + void *req_handle, int32_t status,
  82114. + void *ereq_port);
  82115. +/** Function Driver Ops Data Structure */
  82116. +struct dwc_otg_pcd_function_ops {
  82117. + dwc_connect_cb_t connect;
  82118. + dwc_disconnect_cb_t disconnect;
  82119. + dwc_setup_cb_t setup;
  82120. + dwc_completion_cb_t complete;
  82121. + dwc_isoc_completion_cb_t isoc_complete;
  82122. + dwc_suspend_cb_t suspend;
  82123. + dwc_sleep_cb_t sleep;
  82124. + dwc_resume_cb_t resume;
  82125. + dwc_reset_cb_t reset;
  82126. + dwc_hnp_params_changed_cb_t hnp_changed;
  82127. + cfi_setup_cb_t cfi_setup;
  82128. +#ifdef DWC_UTE_PER_IO
  82129. + xiso_completion_cb_t xisoc_complete;
  82130. +#endif
  82131. +};
  82132. +/** @} */
  82133. +
  82134. +/** @name Function Driver Functions */
  82135. +/** @{ */
  82136. +
  82137. +/** Call this function to get pointer on dwc_otg_pcd_t,
  82138. + * this pointer will be used for all PCD API functions.
  82139. + *
  82140. + * @param core_if The DWC_OTG Core
  82141. + */
  82142. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  82143. +
  82144. +/** Frees PCD allocated by dwc_otg_pcd_init
  82145. + *
  82146. + * @param pcd The PCD
  82147. + */
  82148. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  82149. +
  82150. +/** Call this to bind the function driver to the PCD Core.
  82151. + *
  82152. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  82153. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  82154. + */
  82155. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  82156. + const struct dwc_otg_pcd_function_ops *fops);
  82157. +
  82158. +/** Enables an endpoint for use. This function enables an endpoint in
  82159. + * the PCD. The endpoint is described by the ep_desc which has the
  82160. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  82161. + * to the endpoint from other API functions and in callbacks. Normally this
  82162. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  82163. + * core for that interface.
  82164. + *
  82165. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82166. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82167. + * Returns 0 on success.
  82168. + *
  82169. + * @param pcd The PCD
  82170. + * @param ep_desc Endpoint descriptor
  82171. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  82172. + */
  82173. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  82174. + const uint8_t * ep_desc, void *usb_ep);
  82175. +
  82176. +/** Disable the endpoint referenced by ep_handle.
  82177. + *
  82178. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82179. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  82180. + * Returns 0 on success. */
  82181. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  82182. +
  82183. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  82184. + * After the transfer is completes, the complete callback will be called with
  82185. + * the request status.
  82186. + *
  82187. + * @param pcd The PCD
  82188. + * @param ep_handle The handle of the endpoint
  82189. + * @param buf The buffer for the data
  82190. + * @param dma_buf The DMA buffer for the data
  82191. + * @param buflen The length of the data transfer
  82192. + * @param zero Specifies whether to send zero length last packet.
  82193. + * @param req_handle Set this handle to any value to use to reference this
  82194. + * request in the ep_dequeue function or from the complete callback
  82195. + * @param atomic_alloc If driver need to perform atomic allocations
  82196. + * for internal data structures.
  82197. + *
  82198. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82199. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82200. + * Returns 0 on success. */
  82201. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82202. + uint8_t * buf, dwc_dma_t dma_buf,
  82203. + uint32_t buflen, int zero, void *req_handle,
  82204. + int atomic_alloc);
  82205. +#ifdef DWC_UTE_PER_IO
  82206. +/**
  82207. + *
  82208. + * @param ereq_nonport Pointer to the extended request part of the
  82209. + * usb_request structure defined in usb_gadget.h file.
  82210. + */
  82211. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82212. + uint8_t * buf, dwc_dma_t dma_buf,
  82213. + uint32_t buflen, int zero,
  82214. + void *req_handle, int atomic_alloc,
  82215. + void *ereq_nonport);
  82216. +
  82217. +#endif
  82218. +
  82219. +/** De-queue the specified data transfer that has not yet completed.
  82220. + *
  82221. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82222. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82223. + * Returns 0 on success. */
  82224. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  82225. + void *req_handle);
  82226. +
  82227. +/** Halt (STALL) an endpoint or clear it.
  82228. + *
  82229. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  82230. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  82231. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  82232. + * Returns 0 on success. */
  82233. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  82234. +
  82235. +/** This function */
  82236. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  82237. +
  82238. +/** This function should be called on every hardware interrupt */
  82239. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  82240. +
  82241. +/** This function returns current frame number */
  82242. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  82243. +
  82244. +/**
  82245. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  82246. + * For isochronous transfers duble buffering is used.
  82247. + * After processing each of buffers comlete callback will be called with
  82248. + * status for each transaction.
  82249. + *
  82250. + * @param pcd The PCD
  82251. + * @param ep_handle The handle of the endpoint
  82252. + * @param buf0 The virtual address of first data buffer
  82253. + * @param buf1 The virtual address of second data buffer
  82254. + * @param dma0 The DMA address of first data buffer
  82255. + * @param dma1 The DMA address of second data buffer
  82256. + * @param sync_frame Data pattern frame number
  82257. + * @param dp_frame Data size for pattern frame
  82258. + * @param data_per_frame Data size for regular frame
  82259. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  82260. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  82261. + * @param req_handle Handle of ISOC request
  82262. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  82263. + * internal data structures.
  82264. + *
  82265. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  82266. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  82267. + * Returns -DW_E_SHUTDOWN for any other error.
  82268. + * Returns 0 on success
  82269. + */
  82270. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  82271. + uint8_t * buf0, uint8_t * buf1,
  82272. + dwc_dma_t dma0, dwc_dma_t dma1,
  82273. + int sync_frame, int dp_frame,
  82274. + int data_per_frame, int start_frame,
  82275. + int buf_proc_intrvl, void *req_handle,
  82276. + int atomic_alloc);
  82277. +
  82278. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  82279. + *
  82280. + * @param pcd The PCD
  82281. + * @param ep_handle The handle of the endpoint
  82282. + * @param req_handle Handle of ISOC request
  82283. + *
  82284. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  82285. + * Returns 0 on success
  82286. + */
  82287. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  82288. + void *req_handle);
  82289. +
  82290. +/** Get ISOC packet status.
  82291. + *
  82292. + * @param pcd The PCD
  82293. + * @param ep_handle The handle of the endpoint
  82294. + * @param iso_req_handle Isochronoush request handle
  82295. + * @param packet Number of packet
  82296. + * @param status Out parameter for returning status
  82297. + * @param actual Out parameter for returning actual length
  82298. + * @param offset Out parameter for returning offset
  82299. + *
  82300. + */
  82301. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  82302. + void *ep_handle,
  82303. + void *iso_req_handle, int packet,
  82304. + int *status, int *actual,
  82305. + int *offset);
  82306. +
  82307. +/** Get ISOC packet count.
  82308. + *
  82309. + * @param pcd The PCD
  82310. + * @param ep_handle The handle of the endpoint
  82311. + * @param iso_req_handle
  82312. + */
  82313. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  82314. + void *ep_handle,
  82315. + void *iso_req_handle);
  82316. +
  82317. +/** This function starts the SRP Protocol if no session is in progress. If
  82318. + * a session is already in progress, but the device is suspended,
  82319. + * remote wakeup signaling is started.
  82320. + */
  82321. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  82322. +
  82323. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  82324. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  82325. +
  82326. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  82327. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  82328. +
  82329. +/** Initiate SRP */
  82330. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  82331. +
  82332. +/** Starts remote wakeup signaling. */
  82333. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  82334. +
  82335. +/** Starts micorsecond soft disconnect. */
  82336. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  82337. +/** This function returns whether device is dualspeed.*/
  82338. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  82339. +
  82340. +/** This function returns whether device is otg. */
  82341. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  82342. +
  82343. +/** These functions allow to get hnp parameters */
  82344. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  82345. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  82346. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  82347. +
  82348. +/** CFI specific Interface functions */
  82349. +/** Allocate a cfi buffer */
  82350. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  82351. + dwc_dma_t * addr, size_t buflen,
  82352. + int flags);
  82353. +
  82354. +/******************************************************************************/
  82355. +
  82356. +/** @} */
  82357. +
  82358. +#endif /* __DWC_PCD_IF_H__ */
  82359. +
  82360. +#endif /* DWC_HOST_ONLY */
  82361. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  82362. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  82363. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-02-07 19:57:30.000000000 +0100
  82364. @@ -0,0 +1,5147 @@
  82365. +/* ==========================================================================
  82366. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  82367. + * $Revision: #116 $
  82368. + * $Date: 2012/08/10 $
  82369. + * $Change: 2047372 $
  82370. + *
  82371. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  82372. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  82373. + * otherwise expressly agreed to in writing between Synopsys and you.
  82374. + *
  82375. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  82376. + * any End User Software License Agreement or Agreement for Licensed Product
  82377. + * with Synopsys or any supplement thereto. You are permitted to use and
  82378. + * redistribute this Software in source and binary forms, with or without
  82379. + * modification, provided that redistributions of source code must retain this
  82380. + * notice. You may not view, use, disclose, copy or distribute this file or
  82381. + * any information contained herein except pursuant to this license grant from
  82382. + * Synopsys. If you do not agree with this notice, including the disclaimer
  82383. + * below, then you are not authorized to use the Software.
  82384. + *
  82385. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  82386. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  82387. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  82388. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  82389. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  82390. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  82391. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  82392. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82393. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  82394. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  82395. + * DAMAGE.
  82396. + * ========================================================================== */
  82397. +#ifndef DWC_HOST_ONLY
  82398. +
  82399. +#include "dwc_otg_pcd.h"
  82400. +
  82401. +#ifdef DWC_UTE_CFI
  82402. +#include "dwc_otg_cfi.h"
  82403. +#endif
  82404. +
  82405. +#ifdef DWC_UTE_PER_IO
  82406. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  82407. +#endif
  82408. +//#define PRINT_CFI_DMA_DESCS
  82409. +
  82410. +#define DEBUG_EP0
  82411. +
  82412. +/**
  82413. + * This function updates OTG.
  82414. + */
  82415. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  82416. +{
  82417. +
  82418. + if (reset) {
  82419. + pcd->b_hnp_enable = 0;
  82420. + pcd->a_hnp_support = 0;
  82421. + pcd->a_alt_hnp_support = 0;
  82422. + }
  82423. +
  82424. + if (pcd->fops->hnp_changed) {
  82425. + pcd->fops->hnp_changed(pcd);
  82426. + }
  82427. +}
  82428. +
  82429. +/** @file
  82430. + * This file contains the implementation of the PCD Interrupt handlers.
  82431. + *
  82432. + * The PCD handles the device interrupts. Many conditions can cause a
  82433. + * device interrupt. When an interrupt occurs, the device interrupt
  82434. + * service routine determines the cause of the interrupt and
  82435. + * dispatches handling to the appropriate function. These interrupt
  82436. + * handling functions are described below.
  82437. + * All interrupt registers are processed from LSB to MSB.
  82438. + */
  82439. +
  82440. +/**
  82441. + * This function prints the ep0 state for debug purposes.
  82442. + */
  82443. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  82444. +{
  82445. +#ifdef DEBUG
  82446. + char str[40];
  82447. +
  82448. + switch (pcd->ep0state) {
  82449. + case EP0_DISCONNECT:
  82450. + dwc_strcpy(str, "EP0_DISCONNECT");
  82451. + break;
  82452. + case EP0_IDLE:
  82453. + dwc_strcpy(str, "EP0_IDLE");
  82454. + break;
  82455. + case EP0_IN_DATA_PHASE:
  82456. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  82457. + break;
  82458. + case EP0_OUT_DATA_PHASE:
  82459. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  82460. + break;
  82461. + case EP0_IN_STATUS_PHASE:
  82462. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  82463. + break;
  82464. + case EP0_OUT_STATUS_PHASE:
  82465. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  82466. + break;
  82467. + case EP0_STALL:
  82468. + dwc_strcpy(str, "EP0_STALL");
  82469. + break;
  82470. + default:
  82471. + dwc_strcpy(str, "EP0_INVALID");
  82472. + }
  82473. +
  82474. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  82475. +#endif
  82476. +}
  82477. +
  82478. +/**
  82479. + * This function calculate the size of the payload in the memory
  82480. + * for out endpoints and prints size for debug purposes(used in
  82481. + * 2.93a DevOutNak feature).
  82482. + */
  82483. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  82484. +{
  82485. +#ifdef DEBUG
  82486. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  82487. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  82488. + int pack_num;
  82489. + unsigned payload;
  82490. +
  82491. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  82492. + deptsiz_updt.d32 =
  82493. + DWC_READ_REG32(&pcd->core_if->dev_if->
  82494. + out_ep_regs[ep->num]->doeptsiz);
  82495. + /* Payload will be */
  82496. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  82497. + /* Packet count is decremented every time a packet
  82498. + * is written to the RxFIFO not in to the external memory
  82499. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  82500. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  82501. + DWC_DEBUGPL(DBG_PCDV,
  82502. + "Payload for EP%d-%s\n",
  82503. + ep->num, (ep->is_in ? "IN" : "OUT"));
  82504. + DWC_DEBUGPL(DBG_PCDV,
  82505. + "Number of transfered bytes = 0x%08x\n", payload);
  82506. + DWC_DEBUGPL(DBG_PCDV,
  82507. + "Number of transfered packets = %d\n", pack_num);
  82508. +#endif
  82509. +}
  82510. +
  82511. +
  82512. +#ifdef DWC_UTE_CFI
  82513. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  82514. + const uint8_t * epname, int descnum)
  82515. +{
  82516. + CFI_INFO
  82517. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  82518. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  82519. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  82520. + ddesc->status.b.bs);
  82521. +}
  82522. +#endif
  82523. +
  82524. +/**
  82525. + * This function returns pointer to in ep struct with number ep_num
  82526. + */
  82527. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  82528. +{
  82529. + int i;
  82530. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  82531. + if (ep_num == 0) {
  82532. + return &pcd->ep0;
  82533. + } else {
  82534. + for (i = 0; i < num_in_eps; ++i) {
  82535. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  82536. + return &pcd->in_ep[i];
  82537. + }
  82538. + return 0;
  82539. + }
  82540. +}
  82541. +
  82542. +/**
  82543. + * This function returns pointer to out ep struct with number ep_num
  82544. + */
  82545. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  82546. +{
  82547. + int i;
  82548. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  82549. + if (ep_num == 0) {
  82550. + return &pcd->ep0;
  82551. + } else {
  82552. + for (i = 0; i < num_out_eps; ++i) {
  82553. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  82554. + return &pcd->out_ep[i];
  82555. + }
  82556. + return 0;
  82557. + }
  82558. +}
  82559. +
  82560. +/**
  82561. + * This functions gets a pointer to an EP from the wIndex address
  82562. + * value of the control request.
  82563. + */
  82564. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  82565. +{
  82566. + dwc_otg_pcd_ep_t *ep;
  82567. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  82568. +
  82569. + if (ep_num == 0) {
  82570. + ep = &pcd->ep0;
  82571. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  82572. + ep = &pcd->in_ep[ep_num - 1];
  82573. + } else {
  82574. + ep = &pcd->out_ep[ep_num - 1];
  82575. + }
  82576. +
  82577. + return ep;
  82578. +}
  82579. +
  82580. +/**
  82581. + * This function checks the EP request queue, if the queue is not
  82582. + * empty the next request is started.
  82583. + */
  82584. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  82585. +{
  82586. + dwc_otg_pcd_request_t *req = 0;
  82587. + uint32_t max_transfer =
  82588. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  82589. +
  82590. +#ifdef DWC_UTE_CFI
  82591. + struct dwc_otg_pcd *pcd;
  82592. + pcd = ep->pcd;
  82593. +#endif
  82594. +
  82595. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82596. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82597. +
  82598. +#ifdef DWC_UTE_CFI
  82599. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  82600. + ep->dwc_ep.cfi_req_len = req->length;
  82601. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  82602. + } else {
  82603. +#endif
  82604. + /* Setup and start the Transfer */
  82605. + if (req->dw_align_buf) {
  82606. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  82607. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  82608. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  82609. + } else {
  82610. + ep->dwc_ep.dma_addr = req->dma;
  82611. + ep->dwc_ep.start_xfer_buff = req->buf;
  82612. + ep->dwc_ep.xfer_buff = req->buf;
  82613. + }
  82614. + ep->dwc_ep.sent_zlp = 0;
  82615. + ep->dwc_ep.total_len = req->length;
  82616. + ep->dwc_ep.xfer_len = 0;
  82617. + ep->dwc_ep.xfer_count = 0;
  82618. +
  82619. + ep->dwc_ep.maxxfer = max_transfer;
  82620. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  82621. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  82622. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  82623. + if (ep->dwc_ep.is_in) {
  82624. + if (ep->dwc_ep.maxxfer >
  82625. + DDMA_MAX_TRANSFER_SIZE) {
  82626. + ep->dwc_ep.maxxfer =
  82627. + DDMA_MAX_TRANSFER_SIZE;
  82628. + }
  82629. + } else {
  82630. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  82631. + ep->dwc_ep.maxxfer =
  82632. + out_max_xfer;
  82633. + }
  82634. + }
  82635. + }
  82636. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  82637. + ep->dwc_ep.maxxfer -=
  82638. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  82639. + }
  82640. + if (req->sent_zlp) {
  82641. + if ((ep->dwc_ep.total_len %
  82642. + ep->dwc_ep.maxpacket == 0)
  82643. + && (ep->dwc_ep.total_len != 0)) {
  82644. + ep->dwc_ep.sent_zlp = 1;
  82645. + }
  82646. +
  82647. + }
  82648. +#ifdef DWC_UTE_CFI
  82649. + }
  82650. +#endif
  82651. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  82652. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  82653. + DWC_PRINTF("There are no more ISOC requests \n");
  82654. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  82655. + }
  82656. +}
  82657. +
  82658. +/**
  82659. + * This function handles the SOF Interrupts. At this time the SOF
  82660. + * Interrupt is disabled.
  82661. + */
  82662. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  82663. +{
  82664. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82665. +
  82666. + gintsts_data_t gintsts;
  82667. +
  82668. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  82669. +
  82670. + /* Clear interrupt */
  82671. + gintsts.d32 = 0;
  82672. + gintsts.b.sofintr = 1;
  82673. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  82674. +
  82675. + return 1;
  82676. +}
  82677. +
  82678. +/**
  82679. + * This function handles the Rx Status Queue Level Interrupt, which
  82680. + * indicates that there is a least one packet in the Rx FIFO. The
  82681. + * packets are moved from the FIFO to memory, where they will be
  82682. + * processed when the Endpoint Interrupt Register indicates Transfer
  82683. + * Complete or SETUP Phase Done.
  82684. + *
  82685. + * Repeat the following until the Rx Status Queue is empty:
  82686. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  82687. + * info
  82688. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  82689. + * and exit
  82690. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  82691. + * SETUP data to the buffer
  82692. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  82693. + * to the destination buffer
  82694. + */
  82695. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  82696. +{
  82697. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82698. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  82699. + gintmsk_data_t gintmask = {.d32 = 0 };
  82700. + device_grxsts_data_t status;
  82701. + dwc_otg_pcd_ep_t *ep;
  82702. + gintsts_data_t gintsts;
  82703. +#ifdef DEBUG
  82704. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  82705. +#endif
  82706. +
  82707. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  82708. + /* Disable the Rx Status Queue Level interrupt */
  82709. + gintmask.b.rxstsqlvl = 1;
  82710. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  82711. +
  82712. + /* Get the Status from the top of the FIFO */
  82713. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  82714. +
  82715. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  82716. + "pktsts:%x Frame:%d(0x%0x)\n",
  82717. + status.b.epnum, status.b.bcnt,
  82718. + dpid_str[status.b.dpid],
  82719. + status.b.pktsts, status.b.fn, status.b.fn);
  82720. + /* Get pointer to EP structure */
  82721. + ep = get_out_ep(pcd, status.b.epnum);
  82722. +
  82723. + switch (status.b.pktsts) {
  82724. + case DWC_DSTS_GOUT_NAK:
  82725. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  82726. + break;
  82727. + case DWC_STS_DATA_UPDT:
  82728. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  82729. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  82730. + /** @todo NGS Check for buffer overflow? */
  82731. + dwc_otg_read_packet(core_if,
  82732. + ep->dwc_ep.xfer_buff,
  82733. + status.b.bcnt);
  82734. + ep->dwc_ep.xfer_count += status.b.bcnt;
  82735. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  82736. + }
  82737. + break;
  82738. + case DWC_STS_XFER_COMP:
  82739. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  82740. + break;
  82741. + case DWC_DSTS_SETUP_COMP:
  82742. +#ifdef DEBUG_EP0
  82743. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  82744. +#endif
  82745. + break;
  82746. + case DWC_DSTS_SETUP_UPDT:
  82747. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  82748. +#ifdef DEBUG_EP0
  82749. + DWC_DEBUGPL(DBG_PCD,
  82750. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  82751. + pcd->setup_pkt->req.bmRequestType,
  82752. + pcd->setup_pkt->req.bRequest,
  82753. + UGETW(pcd->setup_pkt->req.wValue),
  82754. + UGETW(pcd->setup_pkt->req.wIndex),
  82755. + UGETW(pcd->setup_pkt->req.wLength));
  82756. +#endif
  82757. + ep->dwc_ep.xfer_count += status.b.bcnt;
  82758. + break;
  82759. + default:
  82760. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  82761. + status.b.pktsts);
  82762. + break;
  82763. + }
  82764. +
  82765. + /* Enable the Rx Status Queue Level interrupt */
  82766. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  82767. + /* Clear interrupt */
  82768. + gintsts.d32 = 0;
  82769. + gintsts.b.rxstsqlvl = 1;
  82770. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  82771. +
  82772. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  82773. + return 1;
  82774. +}
  82775. +
  82776. +/**
  82777. + * This function examines the Device IN Token Learning Queue to
  82778. + * determine the EP number of the last IN token received. This
  82779. + * implementation is for the Mass Storage device where there are only
  82780. + * 2 IN EPs (Control-IN and BULK-IN).
  82781. + *
  82782. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  82783. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  82784. + *
  82785. + * @param core_if Programming view of DWC_otg controller.
  82786. + *
  82787. + */
  82788. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  82789. +{
  82790. + dwc_otg_device_global_regs_t *dev_global_regs =
  82791. + core_if->dev_if->dev_global_regs;
  82792. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  82793. + /* Number of Token Queue Registers */
  82794. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  82795. + dtknq1_data_t dtknqr1;
  82796. + uint32_t in_tkn_epnums[4];
  82797. + int ndx = 0;
  82798. + int i = 0;
  82799. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  82800. + int epnum = 0;
  82801. +
  82802. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  82803. +
  82804. + /* Read the DTKNQ Registers */
  82805. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  82806. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  82807. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  82808. + in_tkn_epnums[i]);
  82809. + if (addr == &dev_global_regs->dvbusdis) {
  82810. + addr = &dev_global_regs->dtknqr3_dthrctl;
  82811. + } else {
  82812. + ++addr;
  82813. + }
  82814. +
  82815. + }
  82816. +
  82817. + /* Copy the DTKNQR1 data to the bit field. */
  82818. + dtknqr1.d32 = in_tkn_epnums[0];
  82819. + /* Get the EP numbers */
  82820. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  82821. + ndx = dtknqr1.b.intknwptr - 1;
  82822. +
  82823. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  82824. + if (ndx == -1) {
  82825. + /** @todo Find a simpler way to calculate the max
  82826. + * queue position.*/
  82827. + int cnt = TOKEN_Q_DEPTH;
  82828. + if (TOKEN_Q_DEPTH <= 6) {
  82829. + cnt = TOKEN_Q_DEPTH - 1;
  82830. + } else if (TOKEN_Q_DEPTH <= 14) {
  82831. + cnt = TOKEN_Q_DEPTH - 7;
  82832. + } else if (TOKEN_Q_DEPTH <= 22) {
  82833. + cnt = TOKEN_Q_DEPTH - 15;
  82834. + } else {
  82835. + cnt = TOKEN_Q_DEPTH - 23;
  82836. + }
  82837. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  82838. + } else {
  82839. + if (ndx <= 5) {
  82840. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  82841. + } else if (ndx <= 13) {
  82842. + ndx -= 6;
  82843. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  82844. + } else if (ndx <= 21) {
  82845. + ndx -= 14;
  82846. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  82847. + } else if (ndx <= 29) {
  82848. + ndx -= 22;
  82849. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  82850. + }
  82851. + }
  82852. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  82853. + return epnum;
  82854. +}
  82855. +
  82856. +/**
  82857. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  82858. + * The active request is checked for the next packet to be loaded into
  82859. + * the non-periodic Tx FIFO.
  82860. + */
  82861. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  82862. +{
  82863. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82864. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  82865. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  82866. + gnptxsts_data_t txstatus = {.d32 = 0 };
  82867. + gintsts_data_t gintsts;
  82868. +
  82869. + int epnum = 0;
  82870. + dwc_otg_pcd_ep_t *ep = 0;
  82871. + uint32_t len = 0;
  82872. + int dwords;
  82873. +
  82874. + /* Get the epnum from the IN Token Learning Queue. */
  82875. + epnum = get_ep_of_last_in_token(core_if);
  82876. + ep = get_in_ep(pcd, epnum);
  82877. +
  82878. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  82879. +
  82880. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  82881. +
  82882. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82883. + if (len > ep->dwc_ep.maxpacket) {
  82884. + len = ep->dwc_ep.maxpacket;
  82885. + }
  82886. + dwords = (len + 3) / 4;
  82887. +
  82888. + /* While there is space in the queue and space in the FIFO and
  82889. + * More data to tranfer, Write packets to the Tx FIFO */
  82890. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  82891. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  82892. +
  82893. + while (txstatus.b.nptxqspcavail > 0 &&
  82894. + txstatus.b.nptxfspcavail > dwords &&
  82895. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  82896. + /* Write the FIFO */
  82897. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  82898. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82899. +
  82900. + if (len > ep->dwc_ep.maxpacket) {
  82901. + len = ep->dwc_ep.maxpacket;
  82902. + }
  82903. +
  82904. + dwords = (len + 3) / 4;
  82905. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  82906. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  82907. + }
  82908. +
  82909. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  82910. + DWC_READ_REG32(&global_regs->gnptxsts));
  82911. +
  82912. + /* Clear interrupt */
  82913. + gintsts.d32 = 0;
  82914. + gintsts.b.nptxfempty = 1;
  82915. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  82916. +
  82917. + return 1;
  82918. +}
  82919. +
  82920. +/**
  82921. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  82922. + * The active request is checked for the next packet to be loaded into
  82923. + * apropriate Tx FIFO.
  82924. + */
  82925. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  82926. +{
  82927. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82928. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  82929. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  82930. + dtxfsts_data_t txstatus = {.d32 = 0 };
  82931. + dwc_otg_pcd_ep_t *ep = 0;
  82932. + uint32_t len = 0;
  82933. + int dwords;
  82934. +
  82935. + ep = get_in_ep(pcd, epnum);
  82936. +
  82937. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  82938. +
  82939. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  82940. +
  82941. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82942. +
  82943. + if (len > ep->dwc_ep.maxpacket) {
  82944. + len = ep->dwc_ep.maxpacket;
  82945. + }
  82946. +
  82947. + dwords = (len + 3) / 4;
  82948. +
  82949. + /* While there is space in the queue and space in the FIFO and
  82950. + * More data to tranfer, Write packets to the Tx FIFO */
  82951. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  82952. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  82953. +
  82954. + while (txstatus.b.txfspcavail > dwords &&
  82955. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  82956. + ep->dwc_ep.xfer_len != 0) {
  82957. + /* Write the FIFO */
  82958. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  82959. +
  82960. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  82961. + if (len > ep->dwc_ep.maxpacket) {
  82962. + len = ep->dwc_ep.maxpacket;
  82963. + }
  82964. +
  82965. + dwords = (len + 3) / 4;
  82966. + txstatus.d32 =
  82967. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  82968. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  82969. + txstatus.d32);
  82970. + }
  82971. +
  82972. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  82973. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  82974. +
  82975. + return 1;
  82976. +}
  82977. +
  82978. +/**
  82979. + * This function is called when the Device is disconnected. It stops
  82980. + * any active requests and informs the Gadget driver of the
  82981. + * disconnect.
  82982. + */
  82983. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  82984. +{
  82985. + int i, num_in_eps, num_out_eps;
  82986. + dwc_otg_pcd_ep_t *ep;
  82987. +
  82988. + gintmsk_data_t intr_mask = {.d32 = 0 };
  82989. +
  82990. + DWC_SPINLOCK(pcd->lock);
  82991. +
  82992. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  82993. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  82994. +
  82995. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  82996. + /* don't disconnect drivers more than once */
  82997. + if (pcd->ep0state == EP0_DISCONNECT) {
  82998. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  82999. + DWC_SPINUNLOCK(pcd->lock);
  83000. + return;
  83001. + }
  83002. + pcd->ep0state = EP0_DISCONNECT;
  83003. +
  83004. + /* Reset the OTG state. */
  83005. + dwc_otg_pcd_update_otg(pcd, 1);
  83006. +
  83007. + /* Disable the NP Tx Fifo Empty Interrupt. */
  83008. + intr_mask.b.nptxfempty = 1;
  83009. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83010. + intr_mask.d32, 0);
  83011. +
  83012. + /* Flush the FIFOs */
  83013. + /**@todo NGS Flush Periodic FIFOs */
  83014. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  83015. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  83016. +
  83017. + /* prevent new request submissions, kill any outstanding requests */
  83018. + ep = &pcd->ep0;
  83019. + dwc_otg_request_nuke(ep);
  83020. + /* prevent new request submissions, kill any outstanding requests */
  83021. + for (i = 0; i < num_in_eps; i++) {
  83022. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  83023. + dwc_otg_request_nuke(ep);
  83024. + }
  83025. + /* prevent new request submissions, kill any outstanding requests */
  83026. + for (i = 0; i < num_out_eps; i++) {
  83027. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  83028. + dwc_otg_request_nuke(ep);
  83029. + }
  83030. +
  83031. + /* report disconnect; the driver is already quiesced */
  83032. + if (pcd->fops->disconnect) {
  83033. + DWC_SPINUNLOCK(pcd->lock);
  83034. + pcd->fops->disconnect(pcd);
  83035. + DWC_SPINLOCK(pcd->lock);
  83036. + }
  83037. + DWC_SPINUNLOCK(pcd->lock);
  83038. +}
  83039. +
  83040. +/**
  83041. + * This interrupt indicates that ...
  83042. + */
  83043. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  83044. +{
  83045. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83046. + gintsts_data_t gintsts;
  83047. +
  83048. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  83049. + intr_mask.b.i2cintr = 1;
  83050. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83051. + intr_mask.d32, 0);
  83052. +
  83053. + /* Clear interrupt */
  83054. + gintsts.d32 = 0;
  83055. + gintsts.b.i2cintr = 1;
  83056. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83057. + gintsts.d32);
  83058. + return 1;
  83059. +}
  83060. +
  83061. +/**
  83062. + * This interrupt indicates that ...
  83063. + */
  83064. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  83065. +{
  83066. + gintsts_data_t gintsts;
  83067. +#if defined(VERBOSE)
  83068. + DWC_PRINTF("Early Suspend Detected\n");
  83069. +#endif
  83070. +
  83071. + /* Clear interrupt */
  83072. + gintsts.d32 = 0;
  83073. + gintsts.b.erlysuspend = 1;
  83074. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83075. + gintsts.d32);
  83076. + return 1;
  83077. +}
  83078. +
  83079. +/**
  83080. + * This function configures EPO to receive SETUP packets.
  83081. + *
  83082. + * @todo NGS: Update the comments from the HW FS.
  83083. + *
  83084. + * -# Program the following fields in the endpoint specific registers
  83085. + * for Control OUT EP 0, in order to receive a setup packet
  83086. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  83087. + * setup packets)
  83088. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  83089. + * to back setup packets)
  83090. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  83091. + * store any setup packets received
  83092. + *
  83093. + * @param core_if Programming view of DWC_otg controller.
  83094. + * @param pcd Programming view of the PCD.
  83095. + */
  83096. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  83097. + dwc_otg_pcd_t * pcd)
  83098. +{
  83099. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83100. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  83101. + dwc_otg_dev_dma_desc_t *dma_desc;
  83102. + depctl_data_t doepctl = {.d32 = 0 };
  83103. +
  83104. +#ifdef VERBOSE
  83105. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  83106. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  83107. +#endif
  83108. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  83109. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  83110. + if (doepctl.b.epena) {
  83111. + return;
  83112. + }
  83113. + }
  83114. +
  83115. + doeptsize0.b.supcnt = 3;
  83116. + doeptsize0.b.pktcnt = 1;
  83117. + doeptsize0.b.xfersize = 8 * 3;
  83118. +
  83119. + if (core_if->dma_enable) {
  83120. + if (!core_if->dma_desc_enable) {
  83121. + /** put here as for Hermes mode deptisz register should not be written */
  83122. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  83123. + doeptsize0.d32);
  83124. +
  83125. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  83126. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  83127. + pcd->setup_pkt_dma_handle);
  83128. + } else {
  83129. + dev_if->setup_desc_index =
  83130. + (dev_if->setup_desc_index + 1) & 1;
  83131. + dma_desc =
  83132. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  83133. +
  83134. + /** DMA Descriptor Setup */
  83135. + dma_desc->status.b.bs = BS_HOST_BUSY;
  83136. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  83137. + dma_desc->status.b.sr = 0;
  83138. + dma_desc->status.b.mtrf = 0;
  83139. + }
  83140. + dma_desc->status.b.l = 1;
  83141. + dma_desc->status.b.ioc = 1;
  83142. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  83143. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  83144. + dma_desc->status.b.sts = 0;
  83145. + dma_desc->status.b.bs = BS_HOST_READY;
  83146. +
  83147. + /** DOEPDMA0 Register write */
  83148. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  83149. + dev_if->dma_setup_desc_addr
  83150. + [dev_if->setup_desc_index]);
  83151. + }
  83152. +
  83153. + } else {
  83154. + /** put here as for Hermes mode deptisz register should not be written */
  83155. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  83156. + doeptsize0.d32);
  83157. + }
  83158. +
  83159. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  83160. + doepctl.d32 = 0;
  83161. + doepctl.b.epena = 1;
  83162. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  83163. + doepctl.b.cnak = 1;
  83164. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  83165. + } else {
  83166. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  83167. + }
  83168. +
  83169. +#ifdef VERBOSE
  83170. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  83171. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  83172. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  83173. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  83174. +#endif
  83175. +}
  83176. +
  83177. +/**
  83178. + * This interrupt occurs when a USB Reset is detected. When the USB
  83179. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  83180. + * EP0 state is set to IDLE.
  83181. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  83182. + * -# Unmask the following interrupt bits
  83183. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  83184. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  83185. + * - DOEPMSK.SETUP = 1
  83186. + * - DOEPMSK.XferCompl = 1
  83187. + * - DIEPMSK.XferCompl = 1
  83188. + * - DIEPMSK.TimeOut = 1
  83189. + * -# Program the following fields in the endpoint specific registers
  83190. + * for Control OUT EP 0, in order to receive a setup packet
  83191. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  83192. + * setup packets)
  83193. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  83194. + * to back setup packets)
  83195. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  83196. + * store any setup packets received
  83197. + * At this point, all the required initialization, except for enabling
  83198. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  83199. + */
  83200. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  83201. +{
  83202. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83203. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  83204. + depctl_data_t doepctl = {.d32 = 0 };
  83205. + depctl_data_t diepctl = {.d32 = 0 };
  83206. + daint_data_t daintmsk = {.d32 = 0 };
  83207. + doepmsk_data_t doepmsk = {.d32 = 0 };
  83208. + diepmsk_data_t diepmsk = {.d32 = 0 };
  83209. + dcfg_data_t dcfg = {.d32 = 0 };
  83210. + grstctl_t resetctl = {.d32 = 0 };
  83211. + dctl_data_t dctl = {.d32 = 0 };
  83212. + int i = 0;
  83213. + gintsts_data_t gintsts;
  83214. + pcgcctl_data_t power = {.d32 = 0 };
  83215. +
  83216. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  83217. + if (power.b.stoppclk) {
  83218. + power.d32 = 0;
  83219. + power.b.stoppclk = 1;
  83220. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83221. +
  83222. + power.b.pwrclmp = 1;
  83223. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83224. +
  83225. + power.b.rstpdwnmodule = 1;
  83226. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  83227. + }
  83228. +
  83229. + core_if->lx_state = DWC_OTG_L0;
  83230. +
  83231. + DWC_PRINTF("USB RESET\n");
  83232. +#ifdef DWC_EN_ISOC
  83233. + for (i = 1; i < 16; ++i) {
  83234. + dwc_otg_pcd_ep_t *ep;
  83235. + dwc_ep_t *dwc_ep;
  83236. + ep = get_in_ep(pcd, i);
  83237. + if (ep != 0) {
  83238. + dwc_ep = &ep->dwc_ep;
  83239. + dwc_ep->next_frame = 0xffffffff;
  83240. + }
  83241. + }
  83242. +#endif /* DWC_EN_ISOC */
  83243. +
  83244. + /* reset the HNP settings */
  83245. + dwc_otg_pcd_update_otg(pcd, 1);
  83246. +
  83247. + /* Clear the Remote Wakeup Signalling */
  83248. + dctl.b.rmtwkupsig = 1;
  83249. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  83250. +
  83251. + /* Set NAK for all OUT EPs */
  83252. + doepctl.b.snak = 1;
  83253. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  83254. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  83255. + }
  83256. +
  83257. + /* Flush the NP Tx FIFO */
  83258. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  83259. + /* Flush the Learning Queue */
  83260. + resetctl.b.intknqflsh = 1;
  83261. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  83262. +
  83263. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  83264. + core_if->start_predict = 0;
  83265. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  83266. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  83267. + }
  83268. + core_if->nextep_seq[0] = 0;
  83269. + core_if->first_in_nextep_seq = 0;
  83270. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  83271. + diepctl.b.nextep = 0;
  83272. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  83273. +
  83274. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  83275. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83276. + dcfg.b.epmscnt = 2;
  83277. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83278. +
  83279. + DWC_DEBUGPL(DBG_PCDV,
  83280. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  83281. + __func__, core_if->first_in_nextep_seq);
  83282. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  83283. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  83284. + }
  83285. + }
  83286. +
  83287. + if (core_if->multiproc_int_enable) {
  83288. + daintmsk.b.inep0 = 1;
  83289. + daintmsk.b.outep0 = 1;
  83290. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  83291. + daintmsk.d32);
  83292. +
  83293. + doepmsk.b.setup = 1;
  83294. + doepmsk.b.xfercompl = 1;
  83295. + doepmsk.b.ahberr = 1;
  83296. + doepmsk.b.epdisabled = 1;
  83297. +
  83298. + if ((core_if->dma_desc_enable) ||
  83299. + (core_if->dma_enable
  83300. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  83301. + doepmsk.b.stsphsercvd = 1;
  83302. + }
  83303. + if (core_if->dma_desc_enable)
  83304. + doepmsk.b.bna = 1;
  83305. +/*
  83306. + doepmsk.b.babble = 1;
  83307. + doepmsk.b.nyet = 1;
  83308. +
  83309. + if (core_if->dma_enable) {
  83310. + doepmsk.b.nak = 1;
  83311. + }
  83312. +*/
  83313. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  83314. + doepmsk.d32);
  83315. +
  83316. + diepmsk.b.xfercompl = 1;
  83317. + diepmsk.b.timeout = 1;
  83318. + diepmsk.b.epdisabled = 1;
  83319. + diepmsk.b.ahberr = 1;
  83320. + diepmsk.b.intknepmis = 1;
  83321. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  83322. + diepmsk.b.intknepmis = 0;
  83323. +
  83324. +/* if (core_if->dma_desc_enable) {
  83325. + diepmsk.b.bna = 1;
  83326. + }
  83327. +*/
  83328. +/*
  83329. + if (core_if->dma_enable) {
  83330. + diepmsk.b.nak = 1;
  83331. + }
  83332. +*/
  83333. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  83334. + diepmsk.d32);
  83335. + } else {
  83336. + daintmsk.b.inep0 = 1;
  83337. + daintmsk.b.outep0 = 1;
  83338. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  83339. + daintmsk.d32);
  83340. +
  83341. + doepmsk.b.setup = 1;
  83342. + doepmsk.b.xfercompl = 1;
  83343. + doepmsk.b.ahberr = 1;
  83344. + doepmsk.b.epdisabled = 1;
  83345. +
  83346. + if ((core_if->dma_desc_enable) ||
  83347. + (core_if->dma_enable
  83348. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  83349. + doepmsk.b.stsphsercvd = 1;
  83350. + }
  83351. + if (core_if->dma_desc_enable)
  83352. + doepmsk.b.bna = 1;
  83353. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  83354. +
  83355. + diepmsk.b.xfercompl = 1;
  83356. + diepmsk.b.timeout = 1;
  83357. + diepmsk.b.epdisabled = 1;
  83358. + diepmsk.b.ahberr = 1;
  83359. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  83360. + diepmsk.b.intknepmis = 0;
  83361. +/*
  83362. + if (core_if->dma_desc_enable) {
  83363. + diepmsk.b.bna = 1;
  83364. + }
  83365. +*/
  83366. +
  83367. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  83368. + }
  83369. +
  83370. + /* Reset Device Address */
  83371. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  83372. + dcfg.b.devaddr = 0;
  83373. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  83374. +
  83375. + /* setup EP0 to receive SETUP packets */
  83376. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  83377. + ep0_out_start(core_if, pcd);
  83378. +
  83379. + /* Clear interrupt */
  83380. + gintsts.d32 = 0;
  83381. + gintsts.b.usbreset = 1;
  83382. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83383. +
  83384. + return 1;
  83385. +}
  83386. +
  83387. +/**
  83388. + * Get the device speed from the device status register and convert it
  83389. + * to USB speed constant.
  83390. + *
  83391. + * @param core_if Programming view of DWC_otg controller.
  83392. + */
  83393. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  83394. +{
  83395. + dsts_data_t dsts;
  83396. + int speed = 0;
  83397. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83398. +
  83399. + switch (dsts.b.enumspd) {
  83400. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  83401. + speed = USB_SPEED_HIGH;
  83402. + break;
  83403. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  83404. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  83405. + speed = USB_SPEED_FULL;
  83406. + break;
  83407. +
  83408. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  83409. + speed = USB_SPEED_LOW;
  83410. + break;
  83411. + }
  83412. +
  83413. + return speed;
  83414. +}
  83415. +
  83416. +/**
  83417. + * Read the device status register and set the device speed in the
  83418. + * data structure.
  83419. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  83420. + */
  83421. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  83422. +{
  83423. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83424. + gintsts_data_t gintsts;
  83425. + gusbcfg_data_t gusbcfg;
  83426. + dwc_otg_core_global_regs_t *global_regs =
  83427. + GET_CORE_IF(pcd)->core_global_regs;
  83428. + uint8_t utmi16b, utmi8b;
  83429. + int speed;
  83430. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  83431. +
  83432. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  83433. + utmi16b = 6; //vahrama old value was 6;
  83434. + utmi8b = 9;
  83435. + } else {
  83436. + utmi16b = 4;
  83437. + utmi8b = 8;
  83438. + }
  83439. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83440. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  83441. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  83442. + }
  83443. +
  83444. +#ifdef DEBUG_EP0
  83445. + print_ep0_state(pcd);
  83446. +#endif
  83447. +
  83448. + if (pcd->ep0state == EP0_DISCONNECT) {
  83449. + pcd->ep0state = EP0_IDLE;
  83450. + } else if (pcd->ep0state == EP0_STALL) {
  83451. + pcd->ep0state = EP0_IDLE;
  83452. + }
  83453. +
  83454. + pcd->ep0state = EP0_IDLE;
  83455. +
  83456. + ep0->stopped = 0;
  83457. +
  83458. + speed = get_device_speed(GET_CORE_IF(pcd));
  83459. + pcd->fops->connect(pcd, speed);
  83460. +
  83461. + /* Set USB turnaround time based on device speed and PHY interface. */
  83462. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  83463. + if (speed == USB_SPEED_HIGH) {
  83464. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83465. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  83466. + /* ULPI interface */
  83467. + gusbcfg.b.usbtrdtim = 9;
  83468. + }
  83469. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83470. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  83471. + /* UTMI+ interface */
  83472. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  83473. + gusbcfg.b.usbtrdtim = utmi8b;
  83474. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  83475. + b.utmi_phy_data_width == 1) {
  83476. + gusbcfg.b.usbtrdtim = utmi16b;
  83477. + } else if (GET_CORE_IF(pcd)->
  83478. + core_params->phy_utmi_width == 8) {
  83479. + gusbcfg.b.usbtrdtim = utmi8b;
  83480. + } else {
  83481. + gusbcfg.b.usbtrdtim = utmi16b;
  83482. + }
  83483. + }
  83484. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  83485. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  83486. + /* UTMI+ OR ULPI interface */
  83487. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  83488. + /* ULPI interface */
  83489. + gusbcfg.b.usbtrdtim = 9;
  83490. + } else {
  83491. + /* UTMI+ interface */
  83492. + if (GET_CORE_IF(pcd)->
  83493. + core_params->phy_utmi_width == 16) {
  83494. + gusbcfg.b.usbtrdtim = utmi16b;
  83495. + } else {
  83496. + gusbcfg.b.usbtrdtim = utmi8b;
  83497. + }
  83498. + }
  83499. + }
  83500. + } else {
  83501. + /* Full or low speed */
  83502. + gusbcfg.b.usbtrdtim = 9;
  83503. + }
  83504. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  83505. +
  83506. + /* Clear interrupt */
  83507. + gintsts.d32 = 0;
  83508. + gintsts.b.enumdone = 1;
  83509. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83510. + gintsts.d32);
  83511. + return 1;
  83512. +}
  83513. +
  83514. +/**
  83515. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  83516. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  83517. + * read all the data from the Rx FIFO.
  83518. + */
  83519. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  83520. +{
  83521. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83522. + gintsts_data_t gintsts;
  83523. +
  83524. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  83525. + "ISOC Out Dropped");
  83526. +
  83527. + intr_mask.b.isooutdrop = 1;
  83528. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83529. + intr_mask.d32, 0);
  83530. +
  83531. + /* Clear interrupt */
  83532. + gintsts.d32 = 0;
  83533. + gintsts.b.isooutdrop = 1;
  83534. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83535. + gintsts.d32);
  83536. +
  83537. + return 1;
  83538. +}
  83539. +
  83540. +/**
  83541. + * This interrupt indicates the end of the portion of the micro-frame
  83542. + * for periodic transactions. If there is a periodic transaction for
  83543. + * the next frame, load the packets into the EP periodic Tx FIFO.
  83544. + */
  83545. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  83546. +{
  83547. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83548. + gintsts_data_t gintsts;
  83549. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  83550. +
  83551. + intr_mask.b.eopframe = 1;
  83552. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  83553. + intr_mask.d32, 0);
  83554. +
  83555. + /* Clear interrupt */
  83556. + gintsts.d32 = 0;
  83557. + gintsts.b.eopframe = 1;
  83558. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  83559. + gintsts.d32);
  83560. +
  83561. + return 1;
  83562. +}
  83563. +
  83564. +/**
  83565. + * This interrupt indicates that EP of the packet on the top of the
  83566. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  83567. + *
  83568. + * The "Device IN Token Queue" Registers are read to determine the
  83569. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  83570. + * is flushed, so it can be reloaded in the order seen in the IN Token
  83571. + * Queue.
  83572. + */
  83573. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  83574. +{
  83575. + gintsts_data_t gintsts;
  83576. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83577. + dctl_data_t dctl;
  83578. + gintmsk_data_t intr_mask = {.d32 = 0 };
  83579. +
  83580. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  83581. + core_if->start_predict = 1;
  83582. +
  83583. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  83584. +
  83585. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  83586. + if (!gintsts.b.ginnakeff) {
  83587. + /* Disable EP Mismatch interrupt */
  83588. + intr_mask.d32 = 0;
  83589. + intr_mask.b.epmismatch = 1;
  83590. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  83591. + /* Enable the Global IN NAK Effective Interrupt */
  83592. + intr_mask.d32 = 0;
  83593. + intr_mask.b.ginnakeff = 1;
  83594. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  83595. + /* Set the global non-periodic IN NAK handshake */
  83596. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  83597. + dctl.b.sgnpinnak = 1;
  83598. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  83599. + } else {
  83600. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  83601. + }
  83602. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  83603. + * handler after Global IN NAK Effective interrupt will be asserted */
  83604. + }
  83605. + /* Clear interrupt */
  83606. + gintsts.d32 = 0;
  83607. + gintsts.b.epmismatch = 1;
  83608. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83609. +
  83610. + return 1;
  83611. +}
  83612. +
  83613. +/**
  83614. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  83615. + * core has stopped fetching data for IN endpoints due to the unavailability of
  83616. + * TxFIFO space or Request Queue space. This interrupt is used by the
  83617. + * application for an endpoint mismatch algorithm.
  83618. + *
  83619. + * @param pcd The PCD
  83620. + */
  83621. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  83622. +{
  83623. + gintsts_data_t gintsts;
  83624. + gintmsk_data_t gintmsk_data;
  83625. + dctl_data_t dctl;
  83626. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83627. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  83628. +
  83629. + /* Clear the global non-periodic IN NAK handshake */
  83630. + dctl.d32 = 0;
  83631. + dctl.b.cgnpinnak = 1;
  83632. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  83633. +
  83634. + /* Mask GINTSTS.FETSUSP interrupt */
  83635. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  83636. + gintmsk_data.b.fetsusp = 0;
  83637. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  83638. +
  83639. + /* Clear interrupt */
  83640. + gintsts.d32 = 0;
  83641. + gintsts.b.fetsusp = 1;
  83642. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  83643. +
  83644. + return 1;
  83645. +}
  83646. +/**
  83647. + * This funcion stalls EP0.
  83648. + */
  83649. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  83650. +{
  83651. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83652. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  83653. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  83654. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  83655. +
  83656. + ep0->dwc_ep.is_in = 1;
  83657. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83658. + pcd->ep0.stopped = 1;
  83659. + pcd->ep0state = EP0_IDLE;
  83660. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  83661. +}
  83662. +
  83663. +/**
  83664. + * This functions delegates the setup command to the gadget driver.
  83665. + */
  83666. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  83667. + usb_device_request_t * ctrl)
  83668. +{
  83669. + int ret = 0;
  83670. + DWC_SPINUNLOCK(pcd->lock);
  83671. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  83672. + DWC_SPINLOCK(pcd->lock);
  83673. + if (ret < 0) {
  83674. + ep0_do_stall(pcd, ret);
  83675. + }
  83676. +
  83677. + /** @todo This is a g_file_storage gadget driver specific
  83678. + * workaround: a DELAYED_STATUS result from the fsg_setup
  83679. + * routine will result in the gadget queueing a EP0 IN status
  83680. + * phase for a two-stage control transfer. Exactly the same as
  83681. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  83682. + * specific request. Need a generic way to know when the gadget
  83683. + * driver will queue the status phase. Can we assume when we
  83684. + * call the gadget driver setup() function that it will always
  83685. + * queue and require the following flag? Need to look into
  83686. + * this.
  83687. + */
  83688. +
  83689. + if (ret == 256 + 999) {
  83690. + pcd->request_config = 1;
  83691. + }
  83692. +}
  83693. +
  83694. +#ifdef DWC_UTE_CFI
  83695. +/**
  83696. + * This functions delegates the CFI setup commands to the gadget driver.
  83697. + * This function will return a negative value to indicate a failure.
  83698. + */
  83699. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  83700. + struct cfi_usb_ctrlrequest *ctrl_req)
  83701. +{
  83702. + int ret = 0;
  83703. +
  83704. + if (pcd->fops && pcd->fops->cfi_setup) {
  83705. + DWC_SPINUNLOCK(pcd->lock);
  83706. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  83707. + DWC_SPINLOCK(pcd->lock);
  83708. + if (ret < 0) {
  83709. + ep0_do_stall(pcd, ret);
  83710. + return ret;
  83711. + }
  83712. + }
  83713. +
  83714. + return ret;
  83715. +}
  83716. +#endif
  83717. +
  83718. +/**
  83719. + * This function starts the Zero-Length Packet for the IN status phase
  83720. + * of a 2 stage control transfer.
  83721. + */
  83722. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  83723. +{
  83724. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83725. + if (pcd->ep0state == EP0_STALL) {
  83726. + return;
  83727. + }
  83728. +
  83729. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  83730. +
  83731. + /* Prepare for more SETUP Packets */
  83732. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  83733. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  83734. + && (pcd->core_if->dma_desc_enable)
  83735. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  83736. + DWC_DEBUGPL(DBG_PCDV,
  83737. + "Data terminated wait next packet in out_desc_addr\n");
  83738. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  83739. + pcd->data_terminated = 1;
  83740. + }
  83741. + ep0->dwc_ep.xfer_len = 0;
  83742. + ep0->dwc_ep.xfer_count = 0;
  83743. + ep0->dwc_ep.is_in = 1;
  83744. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  83745. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83746. +
  83747. + /* Prepare for more SETUP Packets */
  83748. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  83749. +}
  83750. +
  83751. +/**
  83752. + * This function starts the Zero-Length Packet for the OUT status phase
  83753. + * of a 2 stage control transfer.
  83754. + */
  83755. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  83756. +{
  83757. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83758. + if (pcd->ep0state == EP0_STALL) {
  83759. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  83760. + return;
  83761. + }
  83762. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  83763. +
  83764. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  83765. + ep0->dwc_ep.xfer_len = 0;
  83766. + ep0->dwc_ep.xfer_count = 0;
  83767. + ep0->dwc_ep.is_in = 0;
  83768. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  83769. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83770. +
  83771. + /* Prepare for more SETUP Packets */
  83772. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  83773. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  83774. + }
  83775. +}
  83776. +
  83777. +/**
  83778. + * Clear the EP halt (STALL) and if pending requests start the
  83779. + * transfer.
  83780. + */
  83781. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  83782. +{
  83783. + if (ep->dwc_ep.stall_clear_flag == 0)
  83784. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83785. +
  83786. + /* Reactive the EP */
  83787. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  83788. + if (ep->stopped) {
  83789. + ep->stopped = 0;
  83790. + /* If there is a request in the EP queue start it */
  83791. +
  83792. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  83793. + * epmismatch not yet implemented. */
  83794. +
  83795. + /*
  83796. + * Above fixme is solved by implmenting a tasklet to call the
  83797. + * start_next_request(), outside of interrupt context at some
  83798. + * time after the current time, after a clear-halt setup packet.
  83799. + * Still need to implement ep mismatch in the future if a gadget
  83800. + * ever uses more than one endpoint at once
  83801. + */
  83802. + ep->queue_sof = 1;
  83803. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  83804. + }
  83805. + /* Start Control Status Phase */
  83806. + do_setup_in_status_phase(pcd);
  83807. +}
  83808. +
  83809. +/**
  83810. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  83811. + * is sent from the host. The Device Control register is written with
  83812. + * the Test Mode bits set to the specified Test Mode. This is done as
  83813. + * a tasklet so that the "Status" phase of the control transfer
  83814. + * completes before transmitting the TEST packets.
  83815. + *
  83816. + * @todo This has not been tested since the tasklet struct was put
  83817. + * into the PCD struct!
  83818. + *
  83819. + */
  83820. +void do_test_mode(void *data)
  83821. +{
  83822. + dctl_data_t dctl;
  83823. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  83824. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83825. + int test_mode = pcd->test_mode;
  83826. +
  83827. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  83828. +
  83829. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  83830. + switch (test_mode) {
  83831. + case 1: // TEST_J
  83832. + dctl.b.tstctl = 1;
  83833. + break;
  83834. +
  83835. + case 2: // TEST_K
  83836. + dctl.b.tstctl = 2;
  83837. + break;
  83838. +
  83839. + case 3: // TEST_SE0_NAK
  83840. + dctl.b.tstctl = 3;
  83841. + break;
  83842. +
  83843. + case 4: // TEST_PACKET
  83844. + dctl.b.tstctl = 4;
  83845. + break;
  83846. +
  83847. + case 5: // TEST_FORCE_ENABLE
  83848. + dctl.b.tstctl = 5;
  83849. + break;
  83850. + }
  83851. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  83852. +}
  83853. +
  83854. +/**
  83855. + * This function process the GET_STATUS Setup Commands.
  83856. + */
  83857. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  83858. +{
  83859. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83860. + dwc_otg_pcd_ep_t *ep;
  83861. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  83862. + uint16_t *status = pcd->status_buf;
  83863. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83864. +
  83865. +#ifdef DEBUG_EP0
  83866. + DWC_DEBUGPL(DBG_PCD,
  83867. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  83868. + ctrl.bmRequestType, ctrl.bRequest,
  83869. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83870. + UGETW(ctrl.wLength));
  83871. +#endif
  83872. +
  83873. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  83874. + case UT_DEVICE:
  83875. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  83876. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  83877. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  83878. + DWC_PRINTF("OTG CAP - %d, %d\n",
  83879. + core_if->core_params->otg_cap,
  83880. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  83881. + if (core_if->otg_ver == 1
  83882. + && core_if->core_params->otg_cap ==
  83883. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83884. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  83885. + *otgsts = (core_if->otg_sts & 0x1);
  83886. + pcd->ep0_pending = 1;
  83887. + ep0->dwc_ep.start_xfer_buff =
  83888. + (uint8_t *) otgsts;
  83889. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  83890. + ep0->dwc_ep.dma_addr =
  83891. + pcd->status_buf_dma_handle;
  83892. + ep0->dwc_ep.xfer_len = 1;
  83893. + ep0->dwc_ep.xfer_count = 0;
  83894. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  83895. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  83896. + &ep0->dwc_ep);
  83897. + return;
  83898. + } else {
  83899. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83900. + return;
  83901. + }
  83902. + break;
  83903. + } else {
  83904. + *status = 0x1; /* Self powered */
  83905. + *status |= pcd->remote_wakeup_enable << 1;
  83906. + break;
  83907. + }
  83908. + case UT_INTERFACE:
  83909. + *status = 0;
  83910. + break;
  83911. +
  83912. + case UT_ENDPOINT:
  83913. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  83914. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  83915. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83916. + return;
  83917. + }
  83918. + /** @todo check for EP stall */
  83919. + *status = ep->stopped;
  83920. + break;
  83921. + }
  83922. + pcd->ep0_pending = 1;
  83923. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  83924. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  83925. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  83926. + ep0->dwc_ep.xfer_len = 2;
  83927. + ep0->dwc_ep.xfer_count = 0;
  83928. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  83929. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  83930. +}
  83931. +
  83932. +/**
  83933. + * This function process the SET_FEATURE Setup Commands.
  83934. + */
  83935. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  83936. +{
  83937. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83938. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  83939. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  83940. + dwc_otg_pcd_ep_t *ep = 0;
  83941. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  83942. + gotgctl_data_t gotgctl = {.d32 = 0 };
  83943. +
  83944. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  83945. + ctrl.bmRequestType, ctrl.bRequest,
  83946. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  83947. + UGETW(ctrl.wLength));
  83948. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  83949. +
  83950. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  83951. + case UT_DEVICE:
  83952. + switch (UGETW(ctrl.wValue)) {
  83953. + case UF_DEVICE_REMOTE_WAKEUP:
  83954. + pcd->remote_wakeup_enable = 1;
  83955. + break;
  83956. +
  83957. + case UF_TEST_MODE:
  83958. + /* Setup the Test Mode tasklet to do the Test
  83959. + * Packet generation after the SETUP Status
  83960. + * phase has completed. */
  83961. +
  83962. + /** @todo This has not been tested since the
  83963. + * tasklet struct was put into the PCD
  83964. + * struct! */
  83965. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  83966. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  83967. + break;
  83968. +
  83969. + case UF_DEVICE_B_HNP_ENABLE:
  83970. + DWC_DEBUGPL(DBG_PCDV,
  83971. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  83972. +
  83973. + /* dev may initiate HNP */
  83974. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83975. + pcd->b_hnp_enable = 1;
  83976. + dwc_otg_pcd_update_otg(pcd, 0);
  83977. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  83978. + /**@todo Is the gotgctl.devhnpen cleared
  83979. + * by a USB Reset? */
  83980. + gotgctl.b.devhnpen = 1;
  83981. + gotgctl.b.hnpreq = 1;
  83982. + DWC_WRITE_REG32(&global_regs->gotgctl,
  83983. + gotgctl.d32);
  83984. + } else {
  83985. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83986. + return;
  83987. + }
  83988. + break;
  83989. +
  83990. + case UF_DEVICE_A_HNP_SUPPORT:
  83991. + /* RH port supports HNP */
  83992. + DWC_DEBUGPL(DBG_PCDV,
  83993. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  83994. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  83995. + pcd->a_hnp_support = 1;
  83996. + dwc_otg_pcd_update_otg(pcd, 0);
  83997. + } else {
  83998. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  83999. + return;
  84000. + }
  84001. + break;
  84002. +
  84003. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  84004. + /* other RH port does */
  84005. + DWC_DEBUGPL(DBG_PCDV,
  84006. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  84007. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  84008. + pcd->a_alt_hnp_support = 1;
  84009. + dwc_otg_pcd_update_otg(pcd, 0);
  84010. + } else {
  84011. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84012. + return;
  84013. + }
  84014. + break;
  84015. +
  84016. + default:
  84017. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84018. + return;
  84019. +
  84020. + }
  84021. + do_setup_in_status_phase(pcd);
  84022. + break;
  84023. +
  84024. + case UT_INTERFACE:
  84025. + do_gadget_setup(pcd, &ctrl);
  84026. + break;
  84027. +
  84028. + case UT_ENDPOINT:
  84029. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  84030. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84031. + if (ep == 0) {
  84032. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84033. + return;
  84034. + }
  84035. + ep->stopped = 1;
  84036. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  84037. + }
  84038. + do_setup_in_status_phase(pcd);
  84039. + break;
  84040. + }
  84041. +}
  84042. +
  84043. +/**
  84044. + * This function process the CLEAR_FEATURE Setup Commands.
  84045. + */
  84046. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  84047. +{
  84048. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84049. + dwc_otg_pcd_ep_t *ep = 0;
  84050. +
  84051. + DWC_DEBUGPL(DBG_PCD,
  84052. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  84053. + ctrl.bmRequestType, ctrl.bRequest,
  84054. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84055. + UGETW(ctrl.wLength));
  84056. +
  84057. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  84058. + case UT_DEVICE:
  84059. + switch (UGETW(ctrl.wValue)) {
  84060. + case UF_DEVICE_REMOTE_WAKEUP:
  84061. + pcd->remote_wakeup_enable = 0;
  84062. + break;
  84063. +
  84064. + case UF_TEST_MODE:
  84065. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  84066. + break;
  84067. +
  84068. + default:
  84069. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84070. + return;
  84071. + }
  84072. + do_setup_in_status_phase(pcd);
  84073. + break;
  84074. +
  84075. + case UT_ENDPOINT:
  84076. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  84077. + if (ep == 0) {
  84078. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  84079. + return;
  84080. + }
  84081. +
  84082. + pcd_clear_halt(pcd, ep);
  84083. +
  84084. + break;
  84085. + }
  84086. +}
  84087. +
  84088. +/**
  84089. + * This function process the SET_ADDRESS Setup Commands.
  84090. + */
  84091. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  84092. +{
  84093. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  84094. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84095. +
  84096. + if (ctrl.bmRequestType == UT_DEVICE) {
  84097. + dcfg_data_t dcfg = {.d32 = 0 };
  84098. +
  84099. +#ifdef DEBUG_EP0
  84100. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  84101. +#endif
  84102. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  84103. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  84104. + do_setup_in_status_phase(pcd);
  84105. + }
  84106. +}
  84107. +
  84108. +/**
  84109. + * This function processes SETUP commands. In Linux, the USB Command
  84110. + * processing is done in two places - the first being the PCD and the
  84111. + * second in the Gadget Driver (for example, the File-Backed Storage
  84112. + * Gadget Driver).
  84113. + *
  84114. + * <table>
  84115. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  84116. + *
  84117. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  84118. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  84119. + * </td></tr>
  84120. + *
  84121. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  84122. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  84123. + * interface requests are ignored.</td></tr>
  84124. + *
  84125. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  84126. + * requests are processed by the PCD. Interface requests are passed
  84127. + * to the Gadget Driver.</td></tr>
  84128. + *
  84129. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  84130. + * with device address received </td></tr>
  84131. + *
  84132. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  84133. + * requested descriptor</td></tr>
  84134. + *
  84135. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  84136. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  84137. + *
  84138. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  84139. + * all EPs and enable EPs for new configuration.</td></tr>
  84140. + *
  84141. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  84142. + * the current configuration</td></tr>
  84143. + *
  84144. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  84145. + * EPs and enable EPs for new configuration.</td></tr>
  84146. + *
  84147. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  84148. + * current interface.</td></tr>
  84149. + *
  84150. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  84151. + * message.</td></tr>
  84152. + * </table>
  84153. + *
  84154. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  84155. + * processed by pcd_setup. Calling the Function Driver's setup function from
  84156. + * pcd_setup processes the gadget SETUP commands.
  84157. + */
  84158. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  84159. +{
  84160. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84161. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84162. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  84163. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  84164. +
  84165. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  84166. +
  84167. +#ifdef DWC_UTE_CFI
  84168. + int retval = 0;
  84169. + struct cfi_usb_ctrlrequest cfi_req;
  84170. +#endif
  84171. +
  84172. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  84173. +
  84174. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  84175. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  84176. + && (doeptsize0.b.supcnt < 2)
  84177. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  84178. + DWC_ERROR
  84179. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  84180. + }
  84181. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  84182. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  84183. + ctrl =
  84184. + (pcd->setup_pkt +
  84185. + (3 - doeptsize0.b.supcnt - 1 +
  84186. + ep0->dwc_ep.stp_rollover))->req;
  84187. + }
  84188. +#ifdef DEBUG_EP0
  84189. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  84190. + ctrl.bmRequestType, ctrl.bRequest,
  84191. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  84192. + UGETW(ctrl.wLength));
  84193. +#endif
  84194. +
  84195. + /* Clean up the request queue */
  84196. + dwc_otg_request_nuke(ep0);
  84197. + ep0->stopped = 0;
  84198. +
  84199. + if (ctrl.bmRequestType & UE_DIR_IN) {
  84200. + ep0->dwc_ep.is_in = 1;
  84201. + pcd->ep0state = EP0_IN_DATA_PHASE;
  84202. + } else {
  84203. + ep0->dwc_ep.is_in = 0;
  84204. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  84205. + }
  84206. +
  84207. + if (UGETW(ctrl.wLength) == 0) {
  84208. + ep0->dwc_ep.is_in = 1;
  84209. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  84210. + }
  84211. +
  84212. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  84213. +
  84214. +#ifdef DWC_UTE_CFI
  84215. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  84216. +
  84217. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  84218. + ctrl.bRequestType, ctrl.bRequest);
  84219. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  84220. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  84221. + retval = cfi_setup(pcd, &cfi_req);
  84222. + if (retval < 0) {
  84223. + ep0_do_stall(pcd, retval);
  84224. + pcd->ep0_pending = 0;
  84225. + return;
  84226. + }
  84227. +
  84228. + /* if need gadget setup then call it and check the retval */
  84229. + if (pcd->cfi->need_gadget_att) {
  84230. + retval =
  84231. + cfi_gadget_setup(pcd,
  84232. + &pcd->
  84233. + cfi->ctrl_req);
  84234. + if (retval < 0) {
  84235. + pcd->ep0_pending = 0;
  84236. + return;
  84237. + }
  84238. + }
  84239. +
  84240. + if (pcd->cfi->need_status_in_complete) {
  84241. + do_setup_in_status_phase(pcd);
  84242. + }
  84243. + return;
  84244. + }
  84245. + }
  84246. +#endif
  84247. +
  84248. + /* handle non-standard (class/vendor) requests in the gadget driver */
  84249. + do_gadget_setup(pcd, &ctrl);
  84250. + return;
  84251. + }
  84252. +
  84253. + /** @todo NGS: Handle bad setup packet? */
  84254. +
  84255. +///////////////////////////////////////////
  84256. +//// --- Standard Request handling --- ////
  84257. +
  84258. + switch (ctrl.bRequest) {
  84259. + case UR_GET_STATUS:
  84260. + do_get_status(pcd);
  84261. + break;
  84262. +
  84263. + case UR_CLEAR_FEATURE:
  84264. + do_clear_feature(pcd);
  84265. + break;
  84266. +
  84267. + case UR_SET_FEATURE:
  84268. + do_set_feature(pcd);
  84269. + break;
  84270. +
  84271. + case UR_SET_ADDRESS:
  84272. + do_set_address(pcd);
  84273. + break;
  84274. +
  84275. + case UR_SET_INTERFACE:
  84276. + case UR_SET_CONFIG:
  84277. +// _pcd->request_config = 1; /* Configuration changed */
  84278. + do_gadget_setup(pcd, &ctrl);
  84279. + break;
  84280. +
  84281. + case UR_SYNCH_FRAME:
  84282. + do_gadget_setup(pcd, &ctrl);
  84283. + break;
  84284. +
  84285. + default:
  84286. + /* Call the Gadget Driver's setup functions */
  84287. + do_gadget_setup(pcd, &ctrl);
  84288. + break;
  84289. + }
  84290. +}
  84291. +
  84292. +/**
  84293. + * This function completes the ep0 control transfer.
  84294. + */
  84295. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  84296. +{
  84297. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  84298. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84299. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  84300. + dev_if->in_ep_regs[ep->dwc_ep.num];
  84301. +#ifdef DEBUG_EP0
  84302. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  84303. + dev_if->out_ep_regs[ep->dwc_ep.num];
  84304. +#endif
  84305. + deptsiz0_data_t deptsiz;
  84306. + dev_dma_desc_sts_t desc_sts;
  84307. + dwc_otg_pcd_request_t *req;
  84308. + int is_last = 0;
  84309. + dwc_otg_pcd_t *pcd = ep->pcd;
  84310. +
  84311. +#ifdef DWC_UTE_CFI
  84312. + struct cfi_usb_ctrlrequest *ctrlreq;
  84313. + int retval = -DWC_E_NOT_SUPPORTED;
  84314. +#endif
  84315. +
  84316. + desc_sts.b.bytes = 0;
  84317. +
  84318. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84319. + if (ep->dwc_ep.is_in) {
  84320. +#ifdef DEBUG_EP0
  84321. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  84322. +#endif
  84323. + do_setup_out_status_phase(pcd);
  84324. + } else {
  84325. +#ifdef DEBUG_EP0
  84326. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  84327. +#endif
  84328. +
  84329. +#ifdef DWC_UTE_CFI
  84330. + ctrlreq = &pcd->cfi->ctrl_req;
  84331. +
  84332. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  84333. + if (ctrlreq->bRequest > 0xB0
  84334. + && ctrlreq->bRequest < 0xBF) {
  84335. +
  84336. + /* Return if the PCD failed to handle the request */
  84337. + if ((retval =
  84338. + pcd->cfi->ops.
  84339. + ctrl_write_complete(pcd->cfi,
  84340. + pcd)) < 0) {
  84341. + CFI_INFO
  84342. + ("ERROR setting a new value in the PCD(%d)\n",
  84343. + retval);
  84344. + ep0_do_stall(pcd, retval);
  84345. + pcd->ep0_pending = 0;
  84346. + return 0;
  84347. + }
  84348. +
  84349. + /* If the gadget needs to be notified on the request */
  84350. + if (pcd->cfi->need_gadget_att == 1) {
  84351. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  84352. + retval =
  84353. + cfi_gadget_setup(pcd,
  84354. + &pcd->cfi->
  84355. + ctrl_req);
  84356. +
  84357. + /* Return from the function if the gadget failed to process
  84358. + * the request properly - this should never happen !!!
  84359. + */
  84360. + if (retval < 0) {
  84361. + CFI_INFO
  84362. + ("ERROR setting a new value in the gadget(%d)\n",
  84363. + retval);
  84364. + pcd->ep0_pending = 0;
  84365. + return 0;
  84366. + }
  84367. + }
  84368. +
  84369. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  84370. + retval);
  84371. + /* If we hit here then the PCD and the gadget has properly
  84372. + * handled the request - so send the ZLP IN to the host.
  84373. + */
  84374. + /* @todo: MAS - decide whether we need to start the setup
  84375. + * stage based on the need_setup value of the cfi object
  84376. + */
  84377. + do_setup_in_status_phase(pcd);
  84378. + pcd->ep0_pending = 0;
  84379. + return 1;
  84380. + }
  84381. + }
  84382. +#endif
  84383. +
  84384. + do_setup_in_status_phase(pcd);
  84385. + }
  84386. + pcd->ep0_pending = 0;
  84387. + return 1;
  84388. + }
  84389. +
  84390. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84391. + return 0;
  84392. + }
  84393. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84394. +
  84395. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  84396. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  84397. + is_last = 1;
  84398. + } else if (ep->dwc_ep.is_in) {
  84399. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  84400. + if (core_if->dma_desc_enable != 0)
  84401. + desc_sts = dev_if->in_desc_addr->status;
  84402. +#ifdef DEBUG_EP0
  84403. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  84404. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  84405. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84406. +#endif
  84407. +
  84408. + if (((core_if->dma_desc_enable == 0)
  84409. + && (deptsiz.b.xfersize == 0))
  84410. + || ((core_if->dma_desc_enable != 0)
  84411. + && (desc_sts.b.bytes == 0))) {
  84412. + req->actual = ep->dwc_ep.xfer_count;
  84413. + /* Is a Zero Len Packet needed? */
  84414. + if (req->sent_zlp) {
  84415. +#ifdef DEBUG_EP0
  84416. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  84417. +#endif
  84418. + req->sent_zlp = 0;
  84419. + }
  84420. + do_setup_out_status_phase(pcd);
  84421. + }
  84422. + } else {
  84423. + /* ep0-OUT */
  84424. +#ifdef DEBUG_EP0
  84425. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  84426. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  84427. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  84428. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84429. +#endif
  84430. + req->actual = ep->dwc_ep.xfer_count;
  84431. +
  84432. + /* Is a Zero Len Packet needed? */
  84433. + if (req->sent_zlp) {
  84434. +#ifdef DEBUG_EP0
  84435. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  84436. +#endif
  84437. + req->sent_zlp = 0;
  84438. + }
  84439. + /* For older cores do setup in status phase in Slave/BDMA modes,
  84440. + * starting from 3.00 do that only in slave, and for DMA modes
  84441. + * just re-enable ep 0 OUT here*/
  84442. + if (core_if->dma_enable == 0
  84443. + || (core_if->dma_desc_enable == 0
  84444. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  84445. + do_setup_in_status_phase(pcd);
  84446. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  84447. + DWC_DEBUGPL(DBG_PCDV,
  84448. + "Enable out ep before in status phase\n");
  84449. + ep0_out_start(core_if, pcd);
  84450. + }
  84451. + }
  84452. +
  84453. + /* Complete the request */
  84454. + if (is_last) {
  84455. + dwc_otg_request_done(ep, req, 0);
  84456. + ep->dwc_ep.start_xfer_buff = 0;
  84457. + ep->dwc_ep.xfer_buff = 0;
  84458. + ep->dwc_ep.xfer_len = 0;
  84459. + return 1;
  84460. + }
  84461. + return 0;
  84462. +}
  84463. +
  84464. +#ifdef DWC_UTE_CFI
  84465. +/**
  84466. + * This function calculates traverses all the CFI DMA descriptors and
  84467. + * and accumulates the bytes that are left to be transfered.
  84468. + *
  84469. + * @return The total bytes left to transfered, or a negative value as failure
  84470. + */
  84471. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  84472. +{
  84473. + int32_t ret = 0;
  84474. + int i;
  84475. + struct dwc_otg_dma_desc *ddesc = NULL;
  84476. + struct cfi_ep *cfiep;
  84477. +
  84478. + /* See if the pcd_ep has its respective cfi_ep mapped */
  84479. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  84480. + if (!cfiep) {
  84481. + CFI_INFO("%s: Failed to find ep\n", __func__);
  84482. + return -1;
  84483. + }
  84484. +
  84485. + ddesc = ep->dwc_ep.descs;
  84486. +
  84487. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  84488. +
  84489. +#if defined(PRINT_CFI_DMA_DESCS)
  84490. + print_desc(ddesc, ep->ep.name, i);
  84491. +#endif
  84492. + ret += ddesc->status.b.bytes;
  84493. + ddesc++;
  84494. + }
  84495. +
  84496. + if (ret)
  84497. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  84498. + ret);
  84499. +
  84500. + return ret;
  84501. +}
  84502. +#endif
  84503. +
  84504. +/**
  84505. + * This function completes the request for the EP. If there are
  84506. + * additional requests for the EP in the queue they will be started.
  84507. + */
  84508. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  84509. +{
  84510. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  84511. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84512. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  84513. + dev_if->in_ep_regs[ep->dwc_ep.num];
  84514. + deptsiz_data_t deptsiz;
  84515. + dev_dma_desc_sts_t desc_sts;
  84516. + dwc_otg_pcd_request_t *req = 0;
  84517. + dwc_otg_dev_dma_desc_t *dma_desc;
  84518. + uint32_t byte_count = 0;
  84519. + int is_last = 0;
  84520. + int i;
  84521. +
  84522. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  84523. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  84524. +
  84525. + /* Get any pending requests */
  84526. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84527. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84528. + if (!req) {
  84529. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  84530. + return;
  84531. + }
  84532. + } else {
  84533. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  84534. + return;
  84535. + }
  84536. +
  84537. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  84538. +
  84539. + if (ep->dwc_ep.is_in) {
  84540. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  84541. +
  84542. + if (core_if->dma_enable) {
  84543. + if (core_if->dma_desc_enable == 0) {
  84544. + if (deptsiz.b.xfersize == 0
  84545. + && deptsiz.b.pktcnt == 0) {
  84546. + byte_count =
  84547. + ep->dwc_ep.xfer_len -
  84548. + ep->dwc_ep.xfer_count;
  84549. +
  84550. + ep->dwc_ep.xfer_buff += byte_count;
  84551. + ep->dwc_ep.dma_addr += byte_count;
  84552. + ep->dwc_ep.xfer_count += byte_count;
  84553. +
  84554. + DWC_DEBUGPL(DBG_PCDV,
  84555. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  84556. + ep->dwc_ep.num,
  84557. + (ep->dwc_ep.
  84558. + is_in ? "IN" : "OUT"),
  84559. + ep->dwc_ep.xfer_len,
  84560. + deptsiz.b.xfersize,
  84561. + deptsiz.b.pktcnt);
  84562. +
  84563. + if (ep->dwc_ep.xfer_len <
  84564. + ep->dwc_ep.total_len) {
  84565. + dwc_otg_ep_start_transfer
  84566. + (core_if, &ep->dwc_ep);
  84567. + } else if (ep->dwc_ep.sent_zlp) {
  84568. + /*
  84569. + * This fragment of code should initiate 0
  84570. + * length transfer in case if it is queued
  84571. + * a transfer with size divisible to EPs max
  84572. + * packet size and with usb_request zero field
  84573. + * is set, which means that after data is transfered,
  84574. + * it is also should be transfered
  84575. + * a 0 length packet at the end. For Slave and
  84576. + * Buffer DMA modes in this case SW has
  84577. + * to initiate 2 transfers one with transfer size,
  84578. + * and the second with 0 size. For Descriptor
  84579. + * DMA mode SW is able to initiate a transfer,
  84580. + * which will handle all the packets including
  84581. + * the last 0 length.
  84582. + */
  84583. + ep->dwc_ep.sent_zlp = 0;
  84584. + dwc_otg_ep_start_zl_transfer
  84585. + (core_if, &ep->dwc_ep);
  84586. + } else {
  84587. + is_last = 1;
  84588. + }
  84589. + } else {
  84590. + if (ep->dwc_ep.type ==
  84591. + DWC_OTG_EP_TYPE_ISOC) {
  84592. + req->actual = 0;
  84593. + dwc_otg_request_done(ep, req, 0);
  84594. +
  84595. + ep->dwc_ep.start_xfer_buff = 0;
  84596. + ep->dwc_ep.xfer_buff = 0;
  84597. + ep->dwc_ep.xfer_len = 0;
  84598. +
  84599. + /* If there is a request in the queue start it. */
  84600. + start_next_request(ep);
  84601. + } else
  84602. + DWC_WARN
  84603. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  84604. + ep->dwc_ep.num,
  84605. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  84606. + deptsiz.b.xfersize,
  84607. + deptsiz.b.pktcnt);
  84608. + }
  84609. + } else {
  84610. + dma_desc = ep->dwc_ep.desc_addr;
  84611. + byte_count = 0;
  84612. + ep->dwc_ep.sent_zlp = 0;
  84613. +
  84614. +#ifdef DWC_UTE_CFI
  84615. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  84616. + ep->dwc_ep.buff_mode);
  84617. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84618. + int residue;
  84619. +
  84620. + residue = cfi_calc_desc_residue(ep);
  84621. + if (residue < 0)
  84622. + return;
  84623. +
  84624. + byte_count = residue;
  84625. + } else {
  84626. +#endif
  84627. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  84628. + ++i) {
  84629. + desc_sts = dma_desc->status;
  84630. + byte_count += desc_sts.b.bytes;
  84631. + dma_desc++;
  84632. + }
  84633. +#ifdef DWC_UTE_CFI
  84634. + }
  84635. +#endif
  84636. + if (byte_count == 0) {
  84637. + ep->dwc_ep.xfer_count =
  84638. + ep->dwc_ep.total_len;
  84639. + is_last = 1;
  84640. + } else {
  84641. + DWC_WARN("Incomplete transfer\n");
  84642. + }
  84643. + }
  84644. + } else {
  84645. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  84646. + DWC_DEBUGPL(DBG_PCDV,
  84647. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  84648. + ep->dwc_ep.num,
  84649. + ep->dwc_ep.is_in ? "IN" : "OUT",
  84650. + ep->dwc_ep.xfer_len,
  84651. + deptsiz.b.xfersize,
  84652. + deptsiz.b.pktcnt);
  84653. +
  84654. + /* Check if the whole transfer was completed,
  84655. + * if no, setup transfer for next portion of data
  84656. + */
  84657. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  84658. + dwc_otg_ep_start_transfer(core_if,
  84659. + &ep->dwc_ep);
  84660. + } else if (ep->dwc_ep.sent_zlp) {
  84661. + /*
  84662. + * This fragment of code should initiate 0
  84663. + * length trasfer in case if it is queued
  84664. + * a trasfer with size divisible to EPs max
  84665. + * packet size and with usb_request zero field
  84666. + * is set, which means that after data is transfered,
  84667. + * it is also should be transfered
  84668. + * a 0 length packet at the end. For Slave and
  84669. + * Buffer DMA modes in this case SW has
  84670. + * to initiate 2 transfers one with transfer size,
  84671. + * and the second with 0 size. For Desriptor
  84672. + * DMA mode SW is able to initiate a transfer,
  84673. + * which will handle all the packets including
  84674. + * the last 0 legth.
  84675. + */
  84676. + ep->dwc_ep.sent_zlp = 0;
  84677. + dwc_otg_ep_start_zl_transfer(core_if,
  84678. + &ep->dwc_ep);
  84679. + } else {
  84680. + is_last = 1;
  84681. + }
  84682. + } else {
  84683. + DWC_WARN
  84684. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  84685. + ep->dwc_ep.num,
  84686. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  84687. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84688. + }
  84689. + }
  84690. + } else {
  84691. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  84692. + dev_if->out_ep_regs[ep->dwc_ep.num];
  84693. + desc_sts.d32 = 0;
  84694. + if (core_if->dma_enable) {
  84695. + if (core_if->dma_desc_enable) {
  84696. + dma_desc = ep->dwc_ep.desc_addr;
  84697. + byte_count = 0;
  84698. + ep->dwc_ep.sent_zlp = 0;
  84699. +
  84700. +#ifdef DWC_UTE_CFI
  84701. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  84702. + ep->dwc_ep.buff_mode);
  84703. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84704. + int residue;
  84705. + residue = cfi_calc_desc_residue(ep);
  84706. + if (residue < 0)
  84707. + return;
  84708. + byte_count = residue;
  84709. + } else {
  84710. +#endif
  84711. +
  84712. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  84713. + ++i) {
  84714. + desc_sts = dma_desc->status;
  84715. + byte_count += desc_sts.b.bytes;
  84716. + dma_desc++;
  84717. + }
  84718. +
  84719. +#ifdef DWC_UTE_CFI
  84720. + }
  84721. +#endif
  84722. + /* Checking for interrupt Out transfers with not
  84723. + * dword aligned mps sizes
  84724. + */
  84725. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  84726. + (ep->dwc_ep.maxpacket%4)) {
  84727. + ep->dwc_ep.xfer_count =
  84728. + ep->dwc_ep.total_len - byte_count;
  84729. + if ((ep->dwc_ep.xfer_len %
  84730. + ep->dwc_ep.maxpacket)
  84731. + && (ep->dwc_ep.xfer_len /
  84732. + ep->dwc_ep.maxpacket <
  84733. + MAX_DMA_DESC_CNT))
  84734. + ep->dwc_ep.xfer_len -=
  84735. + (ep->dwc_ep.desc_cnt -
  84736. + 1) * ep->dwc_ep.maxpacket +
  84737. + ep->dwc_ep.xfer_len %
  84738. + ep->dwc_ep.maxpacket;
  84739. + else
  84740. + ep->dwc_ep.xfer_len -=
  84741. + ep->dwc_ep.desc_cnt *
  84742. + ep->dwc_ep.maxpacket;
  84743. + if (ep->dwc_ep.xfer_len > 0) {
  84744. + dwc_otg_ep_start_transfer
  84745. + (core_if, &ep->dwc_ep);
  84746. + } else {
  84747. + is_last = 1;
  84748. + }
  84749. + } else {
  84750. + ep->dwc_ep.xfer_count =
  84751. + ep->dwc_ep.total_len - byte_count +
  84752. + ((4 -
  84753. + (ep->dwc_ep.
  84754. + total_len & 0x3)) & 0x3);
  84755. + is_last = 1;
  84756. + }
  84757. + } else {
  84758. + deptsiz.d32 = 0;
  84759. + deptsiz.d32 =
  84760. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  84761. +
  84762. + byte_count = (ep->dwc_ep.xfer_len -
  84763. + ep->dwc_ep.xfer_count -
  84764. + deptsiz.b.xfersize);
  84765. + ep->dwc_ep.xfer_buff += byte_count;
  84766. + ep->dwc_ep.dma_addr += byte_count;
  84767. + ep->dwc_ep.xfer_count += byte_count;
  84768. +
  84769. + /* Check if the whole transfer was completed,
  84770. + * if no, setup transfer for next portion of data
  84771. + */
  84772. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  84773. + dwc_otg_ep_start_transfer(core_if,
  84774. + &ep->dwc_ep);
  84775. + } else if (ep->dwc_ep.sent_zlp) {
  84776. + /*
  84777. + * This fragment of code should initiate 0
  84778. + * length trasfer in case if it is queued
  84779. + * a trasfer with size divisible to EPs max
  84780. + * packet size and with usb_request zero field
  84781. + * is set, which means that after data is transfered,
  84782. + * it is also should be transfered
  84783. + * a 0 length packet at the end. For Slave and
  84784. + * Buffer DMA modes in this case SW has
  84785. + * to initiate 2 transfers one with transfer size,
  84786. + * and the second with 0 size. For Desriptor
  84787. + * DMA mode SW is able to initiate a transfer,
  84788. + * which will handle all the packets including
  84789. + * the last 0 legth.
  84790. + */
  84791. + ep->dwc_ep.sent_zlp = 0;
  84792. + dwc_otg_ep_start_zl_transfer(core_if,
  84793. + &ep->dwc_ep);
  84794. + } else {
  84795. + is_last = 1;
  84796. + }
  84797. + }
  84798. + } else {
  84799. + /* Check if the whole transfer was completed,
  84800. + * if no, setup transfer for next portion of data
  84801. + */
  84802. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  84803. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  84804. + } else if (ep->dwc_ep.sent_zlp) {
  84805. + /*
  84806. + * This fragment of code should initiate 0
  84807. + * length transfer in case if it is queued
  84808. + * a transfer with size divisible to EPs max
  84809. + * packet size and with usb_request zero field
  84810. + * is set, which means that after data is transfered,
  84811. + * it is also should be transfered
  84812. + * a 0 length packet at the end. For Slave and
  84813. + * Buffer DMA modes in this case SW has
  84814. + * to initiate 2 transfers one with transfer size,
  84815. + * and the second with 0 size. For Descriptor
  84816. + * DMA mode SW is able to initiate a transfer,
  84817. + * which will handle all the packets including
  84818. + * the last 0 length.
  84819. + */
  84820. + ep->dwc_ep.sent_zlp = 0;
  84821. + dwc_otg_ep_start_zl_transfer(core_if,
  84822. + &ep->dwc_ep);
  84823. + } else {
  84824. + is_last = 1;
  84825. + }
  84826. + }
  84827. +
  84828. + DWC_DEBUGPL(DBG_PCDV,
  84829. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  84830. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  84831. + ep->dwc_ep.is_in ? "IN" : "OUT",
  84832. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  84833. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  84834. + }
  84835. +
  84836. + /* Complete the request */
  84837. + if (is_last) {
  84838. +#ifdef DWC_UTE_CFI
  84839. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84840. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  84841. + } else {
  84842. +#endif
  84843. + req->actual = ep->dwc_ep.xfer_count;
  84844. +#ifdef DWC_UTE_CFI
  84845. + }
  84846. +#endif
  84847. + if (req->dw_align_buf) {
  84848. + if (!ep->dwc_ep.is_in) {
  84849. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  84850. + }
  84851. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  84852. + req->dw_align_buf_dma);
  84853. + }
  84854. +
  84855. + dwc_otg_request_done(ep, req, 0);
  84856. +
  84857. + ep->dwc_ep.start_xfer_buff = 0;
  84858. + ep->dwc_ep.xfer_buff = 0;
  84859. + ep->dwc_ep.xfer_len = 0;
  84860. +
  84861. + /* If there is a request in the queue start it. */
  84862. + start_next_request(ep);
  84863. + }
  84864. +}
  84865. +
  84866. +#ifdef DWC_EN_ISOC
  84867. +
  84868. +/**
  84869. + * This function BNA interrupt for Isochronous EPs
  84870. + *
  84871. + */
  84872. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  84873. +{
  84874. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  84875. + volatile uint32_t *addr;
  84876. + depctl_data_t depctl = {.d32 = 0 };
  84877. + dwc_otg_pcd_t *pcd = ep->pcd;
  84878. + dwc_otg_dev_dma_desc_t *dma_desc;
  84879. + int i;
  84880. +
  84881. + dma_desc =
  84882. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  84883. +
  84884. + if (dwc_ep->is_in) {
  84885. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84886. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  84887. + sts.d32 = dma_desc->status.d32;
  84888. + sts.b_iso_in.bs = BS_HOST_READY;
  84889. + dma_desc->status.d32 = sts.d32;
  84890. + }
  84891. + } else {
  84892. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84893. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  84894. + sts.d32 = dma_desc->status.d32;
  84895. + sts.b_iso_out.bs = BS_HOST_READY;
  84896. + dma_desc->status.d32 = sts.d32;
  84897. + }
  84898. + }
  84899. +
  84900. + if (dwc_ep->is_in == 0) {
  84901. + addr =
  84902. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  84903. + num]->doepctl;
  84904. + } else {
  84905. + addr =
  84906. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  84907. + }
  84908. + depctl.b.epena = 1;
  84909. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  84910. +}
  84911. +
  84912. +/**
  84913. + * This function sets latest iso packet information(non-PTI mode)
  84914. + *
  84915. + * @param core_if Programming view of DWC_otg controller.
  84916. + * @param ep The EP to start the transfer on.
  84917. + *
  84918. + */
  84919. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  84920. +{
  84921. + deptsiz_data_t deptsiz = {.d32 = 0 };
  84922. + dma_addr_t dma_addr;
  84923. + uint32_t offset;
  84924. +
  84925. + if (ep->proc_buf_num)
  84926. + dma_addr = ep->dma_addr1;
  84927. + else
  84928. + dma_addr = ep->dma_addr0;
  84929. +
  84930. + if (ep->is_in) {
  84931. + deptsiz.d32 =
  84932. + DWC_READ_REG32(&core_if->dev_if->
  84933. + in_ep_regs[ep->num]->dieptsiz);
  84934. + offset = ep->data_per_frame;
  84935. + } else {
  84936. + deptsiz.d32 =
  84937. + DWC_READ_REG32(&core_if->dev_if->
  84938. + out_ep_regs[ep->num]->doeptsiz);
  84939. + offset =
  84940. + ep->data_per_frame +
  84941. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  84942. + }
  84943. +
  84944. + if (!deptsiz.b.xfersize) {
  84945. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  84946. + ep->pkt_info[ep->cur_pkt].offset =
  84947. + ep->cur_pkt_dma_addr - dma_addr;
  84948. + ep->pkt_info[ep->cur_pkt].status = 0;
  84949. + } else {
  84950. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  84951. + ep->pkt_info[ep->cur_pkt].offset =
  84952. + ep->cur_pkt_dma_addr - dma_addr;
  84953. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  84954. + }
  84955. + ep->cur_pkt_addr += offset;
  84956. + ep->cur_pkt_dma_addr += offset;
  84957. + ep->cur_pkt++;
  84958. +}
  84959. +
  84960. +/**
  84961. + * This function sets latest iso packet information(DDMA mode)
  84962. + *
  84963. + * @param core_if Programming view of DWC_otg controller.
  84964. + * @param dwc_ep The EP to start the transfer on.
  84965. + *
  84966. + */
  84967. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  84968. + dwc_ep_t * dwc_ep)
  84969. +{
  84970. + dwc_otg_dev_dma_desc_t *dma_desc;
  84971. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  84972. + iso_pkt_info_t *iso_packet;
  84973. + uint32_t data_per_desc;
  84974. + uint32_t offset;
  84975. + int i, j;
  84976. +
  84977. + iso_packet = dwc_ep->pkt_info;
  84978. +
  84979. + /** Reinit closed DMA Descriptors*/
  84980. + /** ISO OUT EP */
  84981. + if (dwc_ep->is_in == 0) {
  84982. + dma_desc =
  84983. + dwc_ep->iso_desc_addr +
  84984. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  84985. + offset = 0;
  84986. +
  84987. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  84988. + i += dwc_ep->pkt_per_frm) {
  84989. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  84990. + data_per_desc =
  84991. + ((j + 1) * dwc_ep->maxpacket >
  84992. + dwc_ep->
  84993. + data_per_frame) ? dwc_ep->data_per_frame -
  84994. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  84995. + data_per_desc +=
  84996. + (data_per_desc % 4) ? (4 -
  84997. + data_per_desc %
  84998. + 4) : 0;
  84999. +
  85000. + sts.d32 = dma_desc->status.d32;
  85001. +
  85002. + /* Write status in iso_packet_decsriptor */
  85003. + iso_packet->status =
  85004. + sts.b_iso_out.rxsts +
  85005. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85006. + if (iso_packet->status) {
  85007. + iso_packet->status = -DWC_E_NO_DATA;
  85008. + }
  85009. +
  85010. + /* Received data length */
  85011. + if (!sts.b_iso_out.rxbytes) {
  85012. + iso_packet->length =
  85013. + data_per_desc -
  85014. + sts.b_iso_out.rxbytes;
  85015. + } else {
  85016. + iso_packet->length =
  85017. + data_per_desc -
  85018. + sts.b_iso_out.rxbytes + (4 -
  85019. + dwc_ep->data_per_frame
  85020. + % 4);
  85021. + }
  85022. +
  85023. + iso_packet->offset = offset;
  85024. +
  85025. + offset += data_per_desc;
  85026. + dma_desc++;
  85027. + iso_packet++;
  85028. + }
  85029. + }
  85030. +
  85031. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  85032. + data_per_desc =
  85033. + ((j + 1) * dwc_ep->maxpacket >
  85034. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85035. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85036. + data_per_desc +=
  85037. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85038. +
  85039. + sts.d32 = dma_desc->status.d32;
  85040. +
  85041. + /* Write status in iso_packet_decsriptor */
  85042. + iso_packet->status =
  85043. + sts.b_iso_out.rxsts +
  85044. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85045. + if (iso_packet->status) {
  85046. + iso_packet->status = -DWC_E_NO_DATA;
  85047. + }
  85048. +
  85049. + /* Received data length */
  85050. + iso_packet->length =
  85051. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  85052. +
  85053. + iso_packet->offset = offset;
  85054. +
  85055. + offset += data_per_desc;
  85056. + iso_packet++;
  85057. + dma_desc++;
  85058. + }
  85059. +
  85060. + sts.d32 = dma_desc->status.d32;
  85061. +
  85062. + /* Write status in iso_packet_decsriptor */
  85063. + iso_packet->status =
  85064. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  85065. + if (iso_packet->status) {
  85066. + iso_packet->status = -DWC_E_NO_DATA;
  85067. + }
  85068. + /* Received data length */
  85069. + if (!sts.b_iso_out.rxbytes) {
  85070. + iso_packet->length =
  85071. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  85072. + } else {
  85073. + iso_packet->length =
  85074. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  85075. + (4 - dwc_ep->data_per_frame % 4);
  85076. + }
  85077. +
  85078. + iso_packet->offset = offset;
  85079. + } else {
  85080. +/** ISO IN EP */
  85081. +
  85082. + dma_desc =
  85083. + dwc_ep->iso_desc_addr +
  85084. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85085. +
  85086. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  85087. + sts.d32 = dma_desc->status.d32;
  85088. +
  85089. + /* Write status in iso packet descriptor */
  85090. + iso_packet->status =
  85091. + sts.b_iso_in.txsts +
  85092. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  85093. + if (iso_packet->status != 0) {
  85094. + iso_packet->status = -DWC_E_NO_DATA;
  85095. +
  85096. + }
  85097. + /* Bytes has been transfered */
  85098. + iso_packet->length =
  85099. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  85100. +
  85101. + dma_desc++;
  85102. + iso_packet++;
  85103. + }
  85104. +
  85105. + sts.d32 = dma_desc->status.d32;
  85106. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  85107. + sts.d32 = dma_desc->status.d32;
  85108. + }
  85109. +
  85110. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  85111. + iso_packet->status =
  85112. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  85113. + if (iso_packet->status != 0) {
  85114. + iso_packet->status = -DWC_E_NO_DATA;
  85115. + }
  85116. +
  85117. + /* Bytes has been transfered */
  85118. + iso_packet->length =
  85119. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  85120. + }
  85121. +}
  85122. +
  85123. +/**
  85124. + * This function reinitialize DMA Descriptors for Isochronous transfer
  85125. + *
  85126. + * @param core_if Programming view of DWC_otg controller.
  85127. + * @param dwc_ep The EP to start the transfer on.
  85128. + *
  85129. + */
  85130. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  85131. +{
  85132. + int i, j;
  85133. + dwc_otg_dev_dma_desc_t *dma_desc;
  85134. + dma_addr_t dma_ad;
  85135. + volatile uint32_t *addr;
  85136. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85137. + uint32_t data_per_desc;
  85138. +
  85139. + if (dwc_ep->is_in == 0) {
  85140. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  85141. + } else {
  85142. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85143. + }
  85144. +
  85145. + if (dwc_ep->proc_buf_num == 0) {
  85146. + /** Buffer 0 descriptors setup */
  85147. + dma_ad = dwc_ep->dma_addr0;
  85148. + } else {
  85149. + /** Buffer 1 descriptors setup */
  85150. + dma_ad = dwc_ep->dma_addr1;
  85151. + }
  85152. +
  85153. + /** Reinit closed DMA Descriptors*/
  85154. + /** ISO OUT EP */
  85155. + if (dwc_ep->is_in == 0) {
  85156. + dma_desc =
  85157. + dwc_ep->iso_desc_addr +
  85158. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85159. +
  85160. + sts.b_iso_out.bs = BS_HOST_READY;
  85161. + sts.b_iso_out.rxsts = 0;
  85162. + sts.b_iso_out.l = 0;
  85163. + sts.b_iso_out.sp = 0;
  85164. + sts.b_iso_out.ioc = 0;
  85165. + sts.b_iso_out.pid = 0;
  85166. + sts.b_iso_out.framenum = 0;
  85167. +
  85168. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  85169. + i += dwc_ep->pkt_per_frm) {
  85170. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  85171. + data_per_desc =
  85172. + ((j + 1) * dwc_ep->maxpacket >
  85173. + dwc_ep->
  85174. + data_per_frame) ? dwc_ep->data_per_frame -
  85175. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85176. + data_per_desc +=
  85177. + (data_per_desc % 4) ? (4 -
  85178. + data_per_desc %
  85179. + 4) : 0;
  85180. + sts.b_iso_out.rxbytes = data_per_desc;
  85181. + dma_desc->buf = dma_ad;
  85182. + dma_desc->status.d32 = sts.d32;
  85183. +
  85184. + dma_ad += data_per_desc;
  85185. + dma_desc++;
  85186. + }
  85187. + }
  85188. +
  85189. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  85190. +
  85191. + data_per_desc =
  85192. + ((j + 1) * dwc_ep->maxpacket >
  85193. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85194. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85195. + data_per_desc +=
  85196. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85197. + sts.b_iso_out.rxbytes = data_per_desc;
  85198. +
  85199. + dma_desc->buf = dma_ad;
  85200. + dma_desc->status.d32 = sts.d32;
  85201. +
  85202. + dma_desc++;
  85203. + dma_ad += data_per_desc;
  85204. + }
  85205. +
  85206. + sts.b_iso_out.ioc = 1;
  85207. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  85208. +
  85209. + data_per_desc =
  85210. + ((j + 1) * dwc_ep->maxpacket >
  85211. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  85212. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  85213. + data_per_desc +=
  85214. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  85215. + sts.b_iso_out.rxbytes = data_per_desc;
  85216. +
  85217. + dma_desc->buf = dma_ad;
  85218. + dma_desc->status.d32 = sts.d32;
  85219. + } else {
  85220. +/** ISO IN EP */
  85221. +
  85222. + dma_desc =
  85223. + dwc_ep->iso_desc_addr +
  85224. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  85225. +
  85226. + sts.b_iso_in.bs = BS_HOST_READY;
  85227. + sts.b_iso_in.txsts = 0;
  85228. + sts.b_iso_in.sp = 0;
  85229. + sts.b_iso_in.ioc = 0;
  85230. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  85231. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  85232. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  85233. + sts.b_iso_in.l = 0;
  85234. +
  85235. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  85236. + dma_desc->buf = dma_ad;
  85237. + dma_desc->status.d32 = sts.d32;
  85238. +
  85239. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  85240. + dma_ad += dwc_ep->data_per_frame;
  85241. + dma_desc++;
  85242. + }
  85243. +
  85244. + sts.b_iso_in.ioc = 1;
  85245. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  85246. +
  85247. + dma_desc->buf = dma_ad;
  85248. + dma_desc->status.d32 = sts.d32;
  85249. +
  85250. + dwc_ep->next_frame =
  85251. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  85252. + }
  85253. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85254. +}
  85255. +
  85256. +/**
  85257. + * This function is to handle Iso EP transfer complete interrupt
  85258. + * in case Iso out packet was dropped
  85259. + *
  85260. + * @param core_if Programming view of DWC_otg controller.
  85261. + * @param dwc_ep The EP for wihich transfer complete was asserted
  85262. + *
  85263. + */
  85264. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  85265. + dwc_ep_t * dwc_ep)
  85266. +{
  85267. + uint32_t dma_addr;
  85268. + uint32_t drp_pkt;
  85269. + uint32_t drp_pkt_cnt;
  85270. + deptsiz_data_t deptsiz = {.d32 = 0 };
  85271. + depctl_data_t depctl = {.d32 = 0 };
  85272. + int i;
  85273. +
  85274. + deptsiz.d32 =
  85275. + DWC_READ_REG32(&core_if->dev_if->
  85276. + out_ep_regs[dwc_ep->num]->doeptsiz);
  85277. +
  85278. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  85279. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  85280. +
  85281. + /* Setting dropped packets status */
  85282. + for (i = 0; i < drp_pkt_cnt; ++i) {
  85283. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  85284. + drp_pkt++;
  85285. + deptsiz.b.pktcnt--;
  85286. + }
  85287. +
  85288. + if (deptsiz.b.pktcnt > 0) {
  85289. + deptsiz.b.xfersize =
  85290. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  85291. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  85292. + } else {
  85293. + deptsiz.b.xfersize = 0;
  85294. + deptsiz.b.pktcnt = 0;
  85295. + }
  85296. +
  85297. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  85298. + deptsiz.d32);
  85299. +
  85300. + if (deptsiz.b.pktcnt > 0) {
  85301. + if (dwc_ep->proc_buf_num) {
  85302. + dma_addr =
  85303. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  85304. + deptsiz.b.xfersize;
  85305. + } else {
  85306. + dma_addr =
  85307. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  85308. + deptsiz.b.xfersize;;
  85309. + }
  85310. +
  85311. + DWC_WRITE_REG32(&core_if->dev_if->
  85312. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  85313. +
  85314. + /** Re-enable endpoint, clear nak */
  85315. + depctl.d32 = 0;
  85316. + depctl.b.epena = 1;
  85317. + depctl.b.cnak = 1;
  85318. +
  85319. + DWC_MODIFY_REG32(&core_if->dev_if->
  85320. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  85321. + depctl.d32);
  85322. + return 0;
  85323. + } else {
  85324. + return 1;
  85325. + }
  85326. +}
  85327. +
  85328. +/**
  85329. + * This function sets iso packets information(PTI mode)
  85330. + *
  85331. + * @param core_if Programming view of DWC_otg controller.
  85332. + * @param ep The EP to start the transfer on.
  85333. + *
  85334. + */
  85335. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  85336. +{
  85337. + int i, j;
  85338. + dma_addr_t dma_ad;
  85339. + iso_pkt_info_t *packet_info = ep->pkt_info;
  85340. + uint32_t offset;
  85341. + uint32_t frame_data;
  85342. + deptsiz_data_t deptsiz;
  85343. +
  85344. + if (ep->proc_buf_num == 0) {
  85345. + /** Buffer 0 descriptors setup */
  85346. + dma_ad = ep->dma_addr0;
  85347. + } else {
  85348. + /** Buffer 1 descriptors setup */
  85349. + dma_ad = ep->dma_addr1;
  85350. + }
  85351. +
  85352. + if (ep->is_in) {
  85353. + deptsiz.d32 =
  85354. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  85355. + dieptsiz);
  85356. + } else {
  85357. + deptsiz.d32 =
  85358. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  85359. + doeptsiz);
  85360. + }
  85361. +
  85362. + if (!deptsiz.b.xfersize) {
  85363. + offset = 0;
  85364. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  85365. + frame_data = ep->data_per_frame;
  85366. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  85367. +
  85368. + /* Packet status - is not set as initially
  85369. + * it is set to 0 and if packet was sent
  85370. + successfully, status field will remain 0*/
  85371. +
  85372. + /* Bytes has been transfered */
  85373. + packet_info->length =
  85374. + (ep->maxpacket <
  85375. + frame_data) ? ep->maxpacket : frame_data;
  85376. +
  85377. + /* Received packet offset */
  85378. + packet_info->offset = offset;
  85379. + offset += packet_info->length;
  85380. + frame_data -= packet_info->length;
  85381. +
  85382. + packet_info++;
  85383. + }
  85384. + }
  85385. + return 1;
  85386. + } else {
  85387. + /* This is a workaround for in case of Transfer Complete with
  85388. + * PktDrpSts interrupts merging - in this case Transfer complete
  85389. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  85390. + * set and with DOEPTSIZ register non zero. Investigations showed,
  85391. + * that this happens when Out packet is dropped, but because of
  85392. + * interrupts merging during first interrupt handling PktDrpSts
  85393. + * bit is cleared and for next merged interrupts it is not reset.
  85394. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  85395. + */
  85396. + if (ep->is_in) {
  85397. + return 1;
  85398. + } else {
  85399. + return handle_iso_out_pkt_dropped(core_if, ep);
  85400. + }
  85401. + }
  85402. +}
  85403. +
  85404. +/**
  85405. + * This function is to handle Iso EP transfer complete interrupt
  85406. + *
  85407. + * @param pcd The PCD
  85408. + * @param ep The EP for which transfer complete was asserted
  85409. + *
  85410. + */
  85411. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  85412. +{
  85413. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  85414. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85415. + uint8_t is_last = 0;
  85416. +
  85417. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  85418. + DWC_WARN("Next frame is not set!\n");
  85419. + return;
  85420. + }
  85421. +
  85422. + if (core_if->dma_enable) {
  85423. + if (core_if->dma_desc_enable) {
  85424. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  85425. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  85426. + is_last = 1;
  85427. + } else {
  85428. + if (core_if->pti_enh_enable) {
  85429. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  85430. + dwc_ep->proc_buf_num =
  85431. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85432. + dwc_otg_iso_ep_start_buf_transfer
  85433. + (core_if, dwc_ep);
  85434. + is_last = 1;
  85435. + }
  85436. + } else {
  85437. + set_current_pkt_info(core_if, dwc_ep);
  85438. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  85439. + is_last = 1;
  85440. + dwc_ep->cur_pkt = 0;
  85441. + dwc_ep->proc_buf_num =
  85442. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85443. + if (dwc_ep->proc_buf_num) {
  85444. + dwc_ep->cur_pkt_addr =
  85445. + dwc_ep->xfer_buff1;
  85446. + dwc_ep->cur_pkt_dma_addr =
  85447. + dwc_ep->dma_addr1;
  85448. + } else {
  85449. + dwc_ep->cur_pkt_addr =
  85450. + dwc_ep->xfer_buff0;
  85451. + dwc_ep->cur_pkt_dma_addr =
  85452. + dwc_ep->dma_addr0;
  85453. + }
  85454. +
  85455. + }
  85456. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  85457. + dwc_ep);
  85458. + }
  85459. + }
  85460. + } else {
  85461. + set_current_pkt_info(core_if, dwc_ep);
  85462. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  85463. + is_last = 1;
  85464. + dwc_ep->cur_pkt = 0;
  85465. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  85466. + if (dwc_ep->proc_buf_num) {
  85467. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  85468. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  85469. + } else {
  85470. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  85471. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  85472. + }
  85473. +
  85474. + }
  85475. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  85476. + }
  85477. + if (is_last)
  85478. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  85479. +}
  85480. +#endif /* DWC_EN_ISOC */
  85481. +
  85482. +/**
  85483. + * This function handle BNA interrupt for Non Isochronous EPs
  85484. + *
  85485. + */
  85486. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  85487. +{
  85488. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  85489. + volatile uint32_t *addr;
  85490. + depctl_data_t depctl = {.d32 = 0 };
  85491. + dwc_otg_pcd_t *pcd = ep->pcd;
  85492. + dwc_otg_dev_dma_desc_t *dma_desc;
  85493. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  85494. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  85495. + int i, start;
  85496. +
  85497. + if (!dwc_ep->desc_cnt)
  85498. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  85499. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  85500. +
  85501. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  85502. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  85503. + uint32_t doepdma;
  85504. + dwc_otg_dev_out_ep_regs_t *out_regs =
  85505. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  85506. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  85507. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  85508. + dma_desc = &(dwc_ep->desc_addr[start]);
  85509. + } else {
  85510. + start = 0;
  85511. + dma_desc = dwc_ep->desc_addr;
  85512. + }
  85513. +
  85514. +
  85515. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  85516. + sts.d32 = dma_desc->status.d32;
  85517. + sts.b.bs = BS_HOST_READY;
  85518. + dma_desc->status.d32 = sts.d32;
  85519. + }
  85520. +
  85521. + if (dwc_ep->is_in == 0) {
  85522. + addr =
  85523. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  85524. + doepctl;
  85525. + } else {
  85526. + addr =
  85527. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  85528. + }
  85529. + depctl.b.epena = 1;
  85530. + depctl.b.cnak = 1;
  85531. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  85532. +}
  85533. +
  85534. +/**
  85535. + * This function handles EP0 Control transfers.
  85536. + *
  85537. + * The state of the control transfers are tracked in
  85538. + * <code>ep0state</code>.
  85539. + */
  85540. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  85541. +{
  85542. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85543. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85544. + dev_dma_desc_sts_t desc_sts;
  85545. + deptsiz0_data_t deptsiz;
  85546. + uint32_t byte_count;
  85547. +
  85548. +#ifdef DEBUG_EP0
  85549. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  85550. + print_ep0_state(pcd);
  85551. +#endif
  85552. +
  85553. +// DWC_PRINTF("HANDLE EP0\n");
  85554. +
  85555. + switch (pcd->ep0state) {
  85556. + case EP0_DISCONNECT:
  85557. + break;
  85558. +
  85559. + case EP0_IDLE:
  85560. + pcd->request_config = 0;
  85561. +
  85562. + pcd_setup(pcd);
  85563. + break;
  85564. +
  85565. + case EP0_IN_DATA_PHASE:
  85566. +#ifdef DEBUG_EP0
  85567. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  85568. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  85569. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  85570. +#endif
  85571. +
  85572. + if (core_if->dma_enable != 0) {
  85573. + /*
  85574. + * For EP0 we can only program 1 packet at a time so we
  85575. + * need to do the make calculations after each complete.
  85576. + * Call write_packet to make the calculations, as in
  85577. + * slave mode, and use those values to determine if we
  85578. + * can complete.
  85579. + */
  85580. + if (core_if->dma_desc_enable == 0) {
  85581. + deptsiz.d32 =
  85582. + DWC_READ_REG32(&core_if->
  85583. + dev_if->in_ep_regs[0]->
  85584. + dieptsiz);
  85585. + byte_count =
  85586. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  85587. + } else {
  85588. + desc_sts =
  85589. + core_if->dev_if->in_desc_addr->status;
  85590. + byte_count =
  85591. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  85592. + }
  85593. + ep0->dwc_ep.xfer_count += byte_count;
  85594. + ep0->dwc_ep.xfer_buff += byte_count;
  85595. + ep0->dwc_ep.dma_addr += byte_count;
  85596. + }
  85597. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  85598. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  85599. + &ep0->dwc_ep);
  85600. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  85601. + } else if (ep0->dwc_ep.sent_zlp) {
  85602. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  85603. + &ep0->dwc_ep);
  85604. + ep0->dwc_ep.sent_zlp = 0;
  85605. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  85606. + } else {
  85607. + ep0_complete_request(ep0);
  85608. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  85609. + }
  85610. + break;
  85611. + case EP0_OUT_DATA_PHASE:
  85612. +#ifdef DEBUG_EP0
  85613. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  85614. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  85615. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  85616. +#endif
  85617. + if (core_if->dma_enable != 0) {
  85618. + if (core_if->dma_desc_enable == 0) {
  85619. + deptsiz.d32 =
  85620. + DWC_READ_REG32(&core_if->
  85621. + dev_if->out_ep_regs[0]->
  85622. + doeptsiz);
  85623. + byte_count =
  85624. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  85625. + } else {
  85626. + desc_sts =
  85627. + core_if->dev_if->out_desc_addr->status;
  85628. + byte_count =
  85629. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  85630. + }
  85631. + ep0->dwc_ep.xfer_count += byte_count;
  85632. + ep0->dwc_ep.xfer_buff += byte_count;
  85633. + ep0->dwc_ep.dma_addr += byte_count;
  85634. + }
  85635. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  85636. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  85637. + &ep0->dwc_ep);
  85638. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  85639. + } else if (ep0->dwc_ep.sent_zlp) {
  85640. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  85641. + &ep0->dwc_ep);
  85642. + ep0->dwc_ep.sent_zlp = 0;
  85643. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  85644. + } else {
  85645. + ep0_complete_request(ep0);
  85646. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  85647. + }
  85648. + break;
  85649. +
  85650. + case EP0_IN_STATUS_PHASE:
  85651. + case EP0_OUT_STATUS_PHASE:
  85652. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  85653. + ep0_complete_request(ep0);
  85654. + pcd->ep0state = EP0_IDLE;
  85655. + ep0->stopped = 1;
  85656. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  85657. +
  85658. + /* Prepare for more SETUP Packets */
  85659. + if (core_if->dma_enable) {
  85660. + ep0_out_start(core_if, pcd);
  85661. + }
  85662. + break;
  85663. +
  85664. + case EP0_STALL:
  85665. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  85666. + break;
  85667. + }
  85668. +#ifdef DEBUG_EP0
  85669. + print_ep0_state(pcd);
  85670. +#endif
  85671. +}
  85672. +
  85673. +/**
  85674. + * Restart transfer
  85675. + */
  85676. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  85677. +{
  85678. + dwc_otg_core_if_t *core_if;
  85679. + dwc_otg_dev_if_t *dev_if;
  85680. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  85681. + dwc_otg_pcd_ep_t *ep;
  85682. +
  85683. + ep = get_in_ep(pcd, epnum);
  85684. +
  85685. +#ifdef DWC_EN_ISOC
  85686. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  85687. + return;
  85688. + }
  85689. +#endif /* DWC_EN_ISOC */
  85690. +
  85691. + core_if = GET_CORE_IF(pcd);
  85692. + dev_if = core_if->dev_if;
  85693. +
  85694. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  85695. +
  85696. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  85697. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  85698. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  85699. + /*
  85700. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  85701. + */
  85702. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  85703. + ep->dwc_ep.start_xfer_buff != 0) {
  85704. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  85705. + ep->dwc_ep.xfer_count = 0;
  85706. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  85707. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  85708. + } else {
  85709. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  85710. + /* convert packet size to dwords. */
  85711. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  85712. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  85713. + }
  85714. + ep->stopped = 0;
  85715. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  85716. + "xfer_len=%0x stopped=%d\n",
  85717. + ep->dwc_ep.xfer_buff,
  85718. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  85719. + ep->stopped);
  85720. + if (epnum == 0) {
  85721. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  85722. + } else {
  85723. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  85724. + }
  85725. + }
  85726. +}
  85727. +
  85728. +/*
  85729. + * This function create new nextep sequnce based on Learn Queue.
  85730. + *
  85731. + * @param core_if Programming view of DWC_otg controller
  85732. + */
  85733. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  85734. +{
  85735. + dwc_otg_device_global_regs_t *dev_global_regs =
  85736. + core_if->dev_if->dev_global_regs;
  85737. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  85738. + /* Number of Token Queue Registers */
  85739. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  85740. + dtknq1_data_t dtknqr1;
  85741. + uint32_t in_tkn_epnums[4];
  85742. + uint8_t seqnum[MAX_EPS_CHANNELS];
  85743. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  85744. + grstctl_t resetctl = {.d32 = 0 };
  85745. + uint8_t temp;
  85746. + int ndx = 0;
  85747. + int start = 0;
  85748. + int end = 0;
  85749. + int sort_done = 0;
  85750. + int i = 0;
  85751. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  85752. +
  85753. +
  85754. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  85755. +
  85756. + /* Read the DTKNQ Registers */
  85757. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  85758. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  85759. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  85760. + in_tkn_epnums[i]);
  85761. + if (addr == &dev_global_regs->dvbusdis) {
  85762. + addr = &dev_global_regs->dtknqr3_dthrctl;
  85763. + } else {
  85764. + ++addr;
  85765. + }
  85766. +
  85767. + }
  85768. +
  85769. + /* Copy the DTKNQR1 data to the bit field. */
  85770. + dtknqr1.d32 = in_tkn_epnums[0];
  85771. + if (dtknqr1.b.wrap_bit) {
  85772. + ndx = dtknqr1.b.intknwptr;
  85773. + end = ndx -1;
  85774. + if (end < 0)
  85775. + end = TOKEN_Q_DEPTH -1;
  85776. + } else {
  85777. + ndx = 0;
  85778. + end = dtknqr1.b.intknwptr -1;
  85779. + if (end < 0)
  85780. + end = 0;
  85781. + }
  85782. + start = ndx;
  85783. +
  85784. + /* Fill seqnum[] by initial values: EP number + 31 */
  85785. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85786. + seqnum[i] = i +31;
  85787. + }
  85788. +
  85789. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  85790. + for (i=0; i < 6; i++)
  85791. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  85792. +
  85793. + if (TOKEN_Q_DEPTH > 6) {
  85794. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85795. + for (i=6; i < 14; i++)
  85796. + intkn_seq[i] =
  85797. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  85798. + }
  85799. +
  85800. + if (TOKEN_Q_DEPTH > 14) {
  85801. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85802. + for (i=14; i < 22; i++)
  85803. + intkn_seq[i] =
  85804. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  85805. + }
  85806. +
  85807. + if (TOKEN_Q_DEPTH > 22) {
  85808. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  85809. + for (i=22; i < 30; i++)
  85810. + intkn_seq[i] =
  85811. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  85812. + }
  85813. +
  85814. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  85815. + start, end);
  85816. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  85817. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  85818. +
  85819. + /* Update seqnum based on intkn_seq[] */
  85820. + i = 0;
  85821. + do {
  85822. + seqnum[intkn_seq[ndx]] = i;
  85823. + ndx++;
  85824. + i++;
  85825. + if (ndx == TOKEN_Q_DEPTH)
  85826. + ndx = 0;
  85827. + } while ( i < TOKEN_Q_DEPTH );
  85828. +
  85829. + /* Mark non active EP's in seqnum[] by 0xff */
  85830. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  85831. + if (core_if->nextep_seq[i] == 0xff )
  85832. + seqnum[i] = 0xff;
  85833. + }
  85834. +
  85835. + /* Sort seqnum[] */
  85836. + sort_done = 0;
  85837. + while (!sort_done) {
  85838. + sort_done = 1;
  85839. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  85840. + if (seqnum[i] > seqnum[i+1]) {
  85841. + temp = seqnum[i];
  85842. + seqnum[i] = seqnum[i+1];
  85843. + seqnum[i+1] = temp;
  85844. + sort_done = 0;
  85845. + }
  85846. + }
  85847. + }
  85848. +
  85849. + ndx = start + seqnum[0];
  85850. + if (ndx >= TOKEN_Q_DEPTH)
  85851. + ndx = ndx % TOKEN_Q_DEPTH;
  85852. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  85853. +
  85854. + /* Update seqnum[] by EP numbers */
  85855. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  85856. + ndx = start + i;
  85857. + if (seqnum[i] < 31) {
  85858. + ndx = start + seqnum[i];
  85859. + if (ndx >= TOKEN_Q_DEPTH)
  85860. + ndx = ndx % TOKEN_Q_DEPTH;
  85861. + seqnum[i] = intkn_seq[ndx];
  85862. + } else {
  85863. + if (seqnum[i] < 0xff) {
  85864. + seqnum[i] = seqnum[i] - 31;
  85865. + } else {
  85866. + break;
  85867. + }
  85868. + }
  85869. + }
  85870. +
  85871. + /* Update nextep_seq[] based on seqnum[] */
  85872. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  85873. + if (seqnum[i] != 0xff) {
  85874. + if (seqnum[i+1] != 0xff) {
  85875. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  85876. + } else {
  85877. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  85878. + break;
  85879. + }
  85880. + } else {
  85881. + break;
  85882. + }
  85883. + }
  85884. +
  85885. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  85886. + __func__, core_if->first_in_nextep_seq);
  85887. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85888. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  85889. + }
  85890. +
  85891. + /* Flush the Learning Queue */
  85892. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  85893. + resetctl.b.intknqflsh = 1;
  85894. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  85895. +
  85896. +
  85897. +}
  85898. +
  85899. +/**
  85900. + * handle the IN EP disable interrupt.
  85901. + */
  85902. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  85903. + const uint32_t epnum)
  85904. +{
  85905. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85906. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85907. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  85908. + dctl_data_t dctl = {.d32 = 0 };
  85909. + dwc_otg_pcd_ep_t *ep;
  85910. + dwc_ep_t *dwc_ep;
  85911. + gintmsk_data_t gintmsk_data;
  85912. + depctl_data_t depctl;
  85913. + uint32_t diepdma;
  85914. + uint32_t remain_to_transfer = 0;
  85915. + uint8_t i;
  85916. + uint32_t xfer_size;
  85917. +
  85918. + ep = get_in_ep(pcd, epnum);
  85919. + dwc_ep = &ep->dwc_ep;
  85920. +
  85921. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  85922. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  85923. + complete_ep(ep);
  85924. + return;
  85925. + }
  85926. +
  85927. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  85928. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  85929. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  85930. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  85931. +
  85932. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  85933. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  85934. +
  85935. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  85936. + if (ep->stopped) {
  85937. + if (core_if->en_multiple_tx_fifo)
  85938. + /* Flush the Tx FIFO */
  85939. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  85940. + /* Clear the Global IN NP NAK */
  85941. + dctl.d32 = 0;
  85942. + dctl.b.cgnpinnak = 1;
  85943. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85944. + /* Restart the transaction */
  85945. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  85946. + restart_transfer(pcd, epnum);
  85947. + }
  85948. + } else {
  85949. + /* Restart the transaction */
  85950. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  85951. + restart_transfer(pcd, epnum);
  85952. + }
  85953. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  85954. + }
  85955. + return;
  85956. + }
  85957. +
  85958. + if (core_if->start_predict > 2) { // NP IN EP
  85959. + core_if->start_predict--;
  85960. + return;
  85961. + }
  85962. +
  85963. + core_if->start_predict--;
  85964. +
  85965. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  85966. +
  85967. + predict_nextep_seq(core_if);
  85968. +
  85969. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  85970. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  85971. + depctl.d32 =
  85972. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85973. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  85974. + depctl.b.nextep = core_if->nextep_seq[i];
  85975. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  85976. + }
  85977. + }
  85978. + /* Flush Shared NP TxFIFO */
  85979. + dwc_otg_flush_tx_fifo(core_if, 0);
  85980. + /* Rewind buffers */
  85981. + if (!core_if->dma_desc_enable) {
  85982. + i = core_if->first_in_nextep_seq;
  85983. + do {
  85984. + ep = get_in_ep(pcd, i);
  85985. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  85986. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  85987. + if (xfer_size > ep->dwc_ep.maxxfer)
  85988. + xfer_size = ep->dwc_ep.maxxfer;
  85989. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  85990. + if (dieptsiz.b.pktcnt != 0) {
  85991. + if (xfer_size == 0) {
  85992. + remain_to_transfer = 0;
  85993. + } else {
  85994. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  85995. + remain_to_transfer =
  85996. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  85997. + } else {
  85998. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  85999. + + (xfer_size % ep->dwc_ep.maxpacket);
  86000. + }
  86001. + }
  86002. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  86003. + dieptsiz.b.xfersize = remain_to_transfer;
  86004. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  86005. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  86006. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  86007. + }
  86008. + i = core_if->nextep_seq[i];
  86009. + } while (i != core_if->first_in_nextep_seq);
  86010. + } else { // dma_desc_enable
  86011. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  86012. + }
  86013. +
  86014. + /* Restart transfers in predicted sequences */
  86015. + i = core_if->first_in_nextep_seq;
  86016. + do {
  86017. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  86018. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86019. + if (dieptsiz.b.pktcnt != 0) {
  86020. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  86021. + depctl.b.epena = 1;
  86022. + depctl.b.cnak = 1;
  86023. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  86024. + }
  86025. + i = core_if->nextep_seq[i];
  86026. + } while (i != core_if->first_in_nextep_seq);
  86027. +
  86028. + /* Clear the global non-periodic IN NAK handshake */
  86029. + dctl.d32 = 0;
  86030. + dctl.b.cgnpinnak = 1;
  86031. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86032. +
  86033. + /* Unmask EP Mismatch interrupt */
  86034. + gintmsk_data.d32 = 0;
  86035. + gintmsk_data.b.epmismatch = 1;
  86036. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  86037. +
  86038. + core_if->start_predict = 0;
  86039. +
  86040. + }
  86041. +}
  86042. +
  86043. +/**
  86044. + * Handler for the IN EP timeout handshake interrupt.
  86045. + */
  86046. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  86047. + const uint32_t epnum)
  86048. +{
  86049. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86050. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86051. +
  86052. +#ifdef DEBUG
  86053. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  86054. + uint32_t num = 0;
  86055. +#endif
  86056. + dctl_data_t dctl = {.d32 = 0 };
  86057. + dwc_otg_pcd_ep_t *ep;
  86058. +
  86059. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86060. +
  86061. + ep = get_in_ep(pcd, epnum);
  86062. +
  86063. + /* Disable the NP Tx Fifo Empty Interrrupt */
  86064. + if (!core_if->dma_enable) {
  86065. + intr_mask.b.nptxfempty = 1;
  86066. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  86067. + intr_mask.d32, 0);
  86068. + }
  86069. + /** @todo NGS Check EP type.
  86070. + * Implement for Periodic EPs */
  86071. + /*
  86072. + * Non-periodic EP
  86073. + */
  86074. + /* Enable the Global IN NAK Effective Interrupt */
  86075. + intr_mask.b.ginnakeff = 1;
  86076. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  86077. +
  86078. + /* Set Global IN NAK */
  86079. + dctl.b.sgnpinnak = 1;
  86080. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  86081. +
  86082. + ep->stopped = 1;
  86083. +
  86084. +#ifdef DEBUG
  86085. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  86086. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  86087. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  86088. +#endif
  86089. +
  86090. +#ifdef DISABLE_PERIODIC_EP
  86091. + /*
  86092. + * Set the NAK bit for this EP to
  86093. + * start the disable process.
  86094. + */
  86095. + diepctl.d32 = 0;
  86096. + diepctl.b.snak = 1;
  86097. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  86098. + diepctl.d32);
  86099. + ep->disabling = 1;
  86100. + ep->stopped = 1;
  86101. +#endif
  86102. +}
  86103. +
  86104. +/**
  86105. + * Handler for the IN EP NAK interrupt.
  86106. + */
  86107. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  86108. + const uint32_t epnum)
  86109. +{
  86110. + /** @todo implement ISR */
  86111. + dwc_otg_core_if_t *core_if;
  86112. + diepmsk_data_t intr_mask = {.d32 = 0 };
  86113. +
  86114. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  86115. + core_if = GET_CORE_IF(pcd);
  86116. + intr_mask.b.nak = 1;
  86117. +
  86118. + if (core_if->multiproc_int_enable) {
  86119. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86120. + diepeachintmsk[epnum], intr_mask.d32, 0);
  86121. + } else {
  86122. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  86123. + intr_mask.d32, 0);
  86124. + }
  86125. +
  86126. + return 1;
  86127. +}
  86128. +
  86129. +/**
  86130. + * Handler for the OUT EP Babble interrupt.
  86131. + */
  86132. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  86133. + const uint32_t epnum)
  86134. +{
  86135. + /** @todo implement ISR */
  86136. + dwc_otg_core_if_t *core_if;
  86137. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86138. +
  86139. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  86140. + "OUT EP Babble");
  86141. + core_if = GET_CORE_IF(pcd);
  86142. + intr_mask.b.babble = 1;
  86143. +
  86144. + if (core_if->multiproc_int_enable) {
  86145. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86146. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86147. + } else {
  86148. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86149. + intr_mask.d32, 0);
  86150. + }
  86151. +
  86152. + return 1;
  86153. +}
  86154. +
  86155. +/**
  86156. + * Handler for the OUT EP NAK interrupt.
  86157. + */
  86158. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  86159. + const uint32_t epnum)
  86160. +{
  86161. + /** @todo implement ISR */
  86162. + dwc_otg_core_if_t *core_if;
  86163. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86164. +
  86165. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  86166. + core_if = GET_CORE_IF(pcd);
  86167. + intr_mask.b.nak = 1;
  86168. +
  86169. + if (core_if->multiproc_int_enable) {
  86170. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86171. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86172. + } else {
  86173. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86174. + intr_mask.d32, 0);
  86175. + }
  86176. +
  86177. + return 1;
  86178. +}
  86179. +
  86180. +/**
  86181. + * Handler for the OUT EP NYET interrupt.
  86182. + */
  86183. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  86184. + const uint32_t epnum)
  86185. +{
  86186. + /** @todo implement ISR */
  86187. + dwc_otg_core_if_t *core_if;
  86188. + doepmsk_data_t intr_mask = {.d32 = 0 };
  86189. +
  86190. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  86191. + core_if = GET_CORE_IF(pcd);
  86192. + intr_mask.b.nyet = 1;
  86193. +
  86194. + if (core_if->multiproc_int_enable) {
  86195. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  86196. + doepeachintmsk[epnum], intr_mask.d32, 0);
  86197. + } else {
  86198. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86199. + intr_mask.d32, 0);
  86200. + }
  86201. +
  86202. + return 1;
  86203. +}
  86204. +
  86205. +/**
  86206. + * This interrupt indicates that an IN EP has a pending Interrupt.
  86207. + * The sequence for handling the IN EP interrupt is shown below:
  86208. + * -# Read the Device All Endpoint Interrupt register
  86209. + * -# Repeat the following for each IN EP interrupt bit set (from
  86210. + * LSB to MSB).
  86211. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  86212. + * -# If "Transfer Complete" call the request complete function
  86213. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  86214. + * -# If "AHB Error Interrupt" log error
  86215. + * -# If "Time-out Handshake" log error
  86216. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  86217. + * FIFO.
  86218. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  86219. + * Mismatch Interrupt)
  86220. + */
  86221. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  86222. +{
  86223. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  86224. +do { \
  86225. + diepint_data_t diepint = {.d32=0}; \
  86226. + diepint.b.__intr = 1; \
  86227. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  86228. + diepint.d32); \
  86229. +} while (0)
  86230. +
  86231. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86232. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86233. + diepint_data_t diepint = {.d32 = 0 };
  86234. + depctl_data_t depctl = {.d32 = 0 };
  86235. + uint32_t ep_intr;
  86236. + uint32_t epnum = 0;
  86237. + dwc_otg_pcd_ep_t *ep;
  86238. + dwc_ep_t *dwc_ep;
  86239. + gintmsk_data_t intr_mask = {.d32 = 0 };
  86240. +
  86241. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  86242. +
  86243. + /* Read in the device interrupt bits */
  86244. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  86245. +
  86246. + /* Service the Device IN interrupts for each endpoint */
  86247. + while (ep_intr) {
  86248. + if (ep_intr & 0x1) {
  86249. + uint32_t empty_msk;
  86250. + /* Get EP pointer */
  86251. + ep = get_in_ep(pcd, epnum);
  86252. + dwc_ep = &ep->dwc_ep;
  86253. +
  86254. + depctl.d32 =
  86255. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86256. + empty_msk =
  86257. + DWC_READ_REG32(&dev_if->
  86258. + dev_global_regs->dtknqr4_fifoemptymsk);
  86259. +
  86260. + DWC_DEBUGPL(DBG_PCDV,
  86261. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  86262. + epnum, empty_msk, depctl.d32);
  86263. +
  86264. + DWC_DEBUGPL(DBG_PCD,
  86265. + "EP%d-%s: type=%d, mps=%d\n",
  86266. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  86267. + dwc_ep->type, dwc_ep->maxpacket);
  86268. +
  86269. + diepint.d32 =
  86270. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  86271. +
  86272. + DWC_DEBUGPL(DBG_PCDV,
  86273. + "EP %d Interrupt Register - 0x%x\n", epnum,
  86274. + diepint.d32);
  86275. + /* Transfer complete */
  86276. + if (diepint.b.xfercompl) {
  86277. + /* Disable the NP Tx FIFO Empty
  86278. + * Interrupt */
  86279. + if (core_if->en_multiple_tx_fifo == 0) {
  86280. + intr_mask.b.nptxfempty = 1;
  86281. + DWC_MODIFY_REG32
  86282. + (&core_if->core_global_regs->gintmsk,
  86283. + intr_mask.d32, 0);
  86284. + } else {
  86285. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  86286. + uint32_t fifoemptymsk =
  86287. + 0x1 << dwc_ep->num;
  86288. + DWC_MODIFY_REG32(&core_if->
  86289. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  86290. + fifoemptymsk, 0);
  86291. + }
  86292. + /* Clear the bit in DIEPINTn for this interrupt */
  86293. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  86294. +
  86295. + /* Complete the transfer */
  86296. + if (epnum == 0) {
  86297. + handle_ep0(pcd);
  86298. + }
  86299. +#ifdef DWC_EN_ISOC
  86300. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86301. + if (!ep->stopped)
  86302. + complete_iso_ep(pcd, ep);
  86303. + }
  86304. +#endif /* DWC_EN_ISOC */
  86305. +#ifdef DWC_UTE_PER_IO
  86306. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86307. + if (!ep->stopped)
  86308. + complete_xiso_ep(ep);
  86309. + }
  86310. +#endif /* DWC_UTE_PER_IO */
  86311. + else {
  86312. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  86313. + dwc_ep->bInterval > 1) {
  86314. + dwc_ep->frame_num += dwc_ep->bInterval;
  86315. + if (dwc_ep->frame_num > 0x3FFF)
  86316. + {
  86317. + dwc_ep->frm_overrun = 1;
  86318. + dwc_ep->frame_num &= 0x3FFF;
  86319. + } else
  86320. + dwc_ep->frm_overrun = 0;
  86321. + }
  86322. + complete_ep(ep);
  86323. + if(diepint.b.nak)
  86324. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  86325. + }
  86326. + }
  86327. + /* Endpoint disable */
  86328. + if (diepint.b.epdisabled) {
  86329. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  86330. + epnum);
  86331. + handle_in_ep_disable_intr(pcd, epnum);
  86332. +
  86333. + /* Clear the bit in DIEPINTn for this interrupt */
  86334. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  86335. + }
  86336. + /* AHB Error */
  86337. + if (diepint.b.ahberr) {
  86338. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  86339. + /* Clear the bit in DIEPINTn for this interrupt */
  86340. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  86341. + }
  86342. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  86343. + if (diepint.b.timeout) {
  86344. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  86345. + handle_in_ep_timeout_intr(pcd, epnum);
  86346. +
  86347. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  86348. + }
  86349. + /** IN Token received with TxF Empty */
  86350. + if (diepint.b.intktxfemp) {
  86351. + DWC_DEBUGPL(DBG_ANY,
  86352. + "EP%d IN TKN TxFifo Empty\n",
  86353. + epnum);
  86354. + if (!ep->stopped && epnum != 0) {
  86355. +
  86356. + diepmsk_data_t diepmsk = {.d32 = 0 };
  86357. + diepmsk.b.intktxfemp = 1;
  86358. +
  86359. + if (core_if->multiproc_int_enable) {
  86360. + DWC_MODIFY_REG32
  86361. + (&dev_if->dev_global_regs->diepeachintmsk
  86362. + [epnum], diepmsk.d32, 0);
  86363. + } else {
  86364. + DWC_MODIFY_REG32
  86365. + (&dev_if->dev_global_regs->diepmsk,
  86366. + diepmsk.d32, 0);
  86367. + }
  86368. + } else if (core_if->dma_desc_enable
  86369. + && epnum == 0
  86370. + && pcd->ep0state ==
  86371. + EP0_OUT_STATUS_PHASE) {
  86372. + // EP0 IN set STALL
  86373. + depctl.d32 =
  86374. + DWC_READ_REG32(&dev_if->in_ep_regs
  86375. + [epnum]->diepctl);
  86376. +
  86377. + /* set the disable and stall bits */
  86378. + if (depctl.b.epena) {
  86379. + depctl.b.epdis = 1;
  86380. + }
  86381. + depctl.b.stall = 1;
  86382. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  86383. + [epnum]->diepctl,
  86384. + depctl.d32);
  86385. + }
  86386. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  86387. + }
  86388. + /** IN Token Received with EP mismatch */
  86389. + if (diepint.b.intknepmis) {
  86390. + DWC_DEBUGPL(DBG_ANY,
  86391. + "EP%d IN TKN EP Mismatch\n", epnum);
  86392. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  86393. + }
  86394. + /** IN Endpoint NAK Effective */
  86395. + if (diepint.b.inepnakeff) {
  86396. + DWC_DEBUGPL(DBG_ANY,
  86397. + "EP%d IN EP NAK Effective\n",
  86398. + epnum);
  86399. + /* Periodic EP */
  86400. + if (ep->disabling) {
  86401. + depctl.d32 = 0;
  86402. + depctl.b.snak = 1;
  86403. + depctl.b.epdis = 1;
  86404. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  86405. + [epnum]->diepctl,
  86406. + depctl.d32,
  86407. + depctl.d32);
  86408. + }
  86409. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  86410. +
  86411. + }
  86412. +
  86413. + /** IN EP Tx FIFO Empty Intr */
  86414. + if (diepint.b.emptyintr) {
  86415. + DWC_DEBUGPL(DBG_ANY,
  86416. + "EP%d Tx FIFO Empty Intr \n",
  86417. + epnum);
  86418. + write_empty_tx_fifo(pcd, epnum);
  86419. +
  86420. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  86421. +
  86422. + }
  86423. +
  86424. + /** IN EP BNA Intr */
  86425. + if (diepint.b.bna) {
  86426. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  86427. + if (core_if->dma_desc_enable) {
  86428. +#ifdef DWC_EN_ISOC
  86429. + if (dwc_ep->type ==
  86430. + DWC_OTG_EP_TYPE_ISOC) {
  86431. + /*
  86432. + * This checking is performed to prevent first "false" BNA
  86433. + * handling occuring right after reconnect
  86434. + */
  86435. + if (dwc_ep->next_frame !=
  86436. + 0xffffffff)
  86437. + dwc_otg_pcd_handle_iso_bna(ep);
  86438. + } else
  86439. +#endif /* DWC_EN_ISOC */
  86440. + {
  86441. + dwc_otg_pcd_handle_noniso_bna(ep);
  86442. + }
  86443. + }
  86444. + }
  86445. + /* NAK Interrutp */
  86446. + if (diepint.b.nak) {
  86447. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  86448. + epnum);
  86449. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86450. + depctl_data_t depctl;
  86451. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  86452. + ep->dwc_ep.frame_num = core_if->frame_num;
  86453. + if (ep->dwc_ep.bInterval > 1) {
  86454. + depctl.d32 = 0;
  86455. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  86456. + if (ep->dwc_ep.frame_num & 0x1) {
  86457. + depctl.b.setd1pid = 1;
  86458. + depctl.b.setd0pid = 0;
  86459. + } else {
  86460. + depctl.b.setd0pid = 1;
  86461. + depctl.b.setd1pid = 0;
  86462. + }
  86463. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  86464. + }
  86465. + start_next_request(ep);
  86466. + }
  86467. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  86468. + if (dwc_ep->frame_num > 0x3FFF) {
  86469. + dwc_ep->frm_overrun = 1;
  86470. + dwc_ep->frame_num &= 0x3FFF;
  86471. + } else
  86472. + dwc_ep->frm_overrun = 0;
  86473. + }
  86474. +
  86475. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  86476. + }
  86477. + }
  86478. + epnum++;
  86479. + ep_intr >>= 1;
  86480. + }
  86481. +
  86482. + return 1;
  86483. +#undef CLEAR_IN_EP_INTR
  86484. +}
  86485. +
  86486. +/**
  86487. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  86488. + * The sequence for handling the OUT EP interrupt is shown below:
  86489. + * -# Read the Device All Endpoint Interrupt register
  86490. + * -# Repeat the following for each OUT EP interrupt bit set (from
  86491. + * LSB to MSB).
  86492. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  86493. + * -# If "Transfer Complete" call the request complete function
  86494. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  86495. + * -# If "AHB Error Interrupt" log error
  86496. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  86497. + * Command Processing)
  86498. + */
  86499. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  86500. +{
  86501. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  86502. +do { \
  86503. + doepint_data_t doepint = {.d32=0}; \
  86504. + doepint.b.__intr = 1; \
  86505. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  86506. + doepint.d32); \
  86507. +} while (0)
  86508. +
  86509. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86510. + uint32_t ep_intr;
  86511. + doepint_data_t doepint = {.d32 = 0 };
  86512. + uint32_t epnum = 0;
  86513. + dwc_otg_pcd_ep_t *ep;
  86514. + dwc_ep_t *dwc_ep;
  86515. + dctl_data_t dctl = {.d32 = 0 };
  86516. + gintmsk_data_t gintmsk = {.d32 = 0 };
  86517. +
  86518. +
  86519. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  86520. +
  86521. + /* Read in the device interrupt bits */
  86522. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  86523. +
  86524. + while (ep_intr) {
  86525. + if (ep_intr & 0x1) {
  86526. + /* Get EP pointer */
  86527. + ep = get_out_ep(pcd, epnum);
  86528. + dwc_ep = &ep->dwc_ep;
  86529. +
  86530. +#ifdef VERBOSE
  86531. + DWC_DEBUGPL(DBG_PCDV,
  86532. + "EP%d-%s: type=%d, mps=%d\n",
  86533. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  86534. + dwc_ep->type, dwc_ep->maxpacket);
  86535. +#endif
  86536. + doepint.d32 =
  86537. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  86538. + /* Moved this interrupt upper due to core deffect of asserting
  86539. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  86540. + if (doepint.b.stsphsercvd) {
  86541. + deptsiz0_data_t deptsiz;
  86542. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  86543. + deptsiz.d32 =
  86544. + DWC_READ_REG32(&core_if->dev_if->
  86545. + out_ep_regs[0]->doeptsiz);
  86546. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  86547. + && core_if->dma_enable
  86548. + && core_if->dma_desc_enable == 0
  86549. + && doepint.b.xfercompl
  86550. + && deptsiz.b.xfersize == 24) {
  86551. + CLEAR_OUT_EP_INTR(core_if, epnum,
  86552. + xfercompl);
  86553. + doepint.b.xfercompl = 0;
  86554. + ep0_out_start(core_if, pcd);
  86555. + }
  86556. + if ((core_if->dma_desc_enable) ||
  86557. + (core_if->dma_enable
  86558. + && core_if->snpsid >=
  86559. + OTG_CORE_REV_3_00a)) {
  86560. + do_setup_in_status_phase(pcd);
  86561. + }
  86562. + }
  86563. + /* Transfer complete */
  86564. + if (doepint.b.xfercompl) {
  86565. +
  86566. + if (epnum == 0) {
  86567. + /* Clear the bit in DOEPINTn for this interrupt */
  86568. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  86569. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86570. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  86571. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  86572. + doepint.d32);
  86573. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  86574. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  86575. +
  86576. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  86577. + && core_if->dma_enable == 0) {
  86578. + doepint_data_t doepint;
  86579. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86580. + out_ep_regs[0]->doepint);
  86581. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  86582. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  86583. + goto exit_xfercompl;
  86584. + }
  86585. + }
  86586. + /* In case of DDMA look at SR bit to go to the Data Stage */
  86587. + if (core_if->dma_desc_enable) {
  86588. + dev_dma_desc_sts_t status = {.d32 = 0};
  86589. + if (pcd->ep0state == EP0_IDLE) {
  86590. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  86591. + dev_if->setup_desc_index]->status.d32;
  86592. + if(pcd->data_terminated) {
  86593. + pcd->data_terminated = 0;
  86594. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  86595. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  86596. + }
  86597. + if (status.b.sr) {
  86598. + if (doepint.b.setup) {
  86599. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  86600. + /* Already started data stage, clear setup */
  86601. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86602. + doepint.b.setup = 0;
  86603. + handle_ep0(pcd);
  86604. + /* Prepare for more setup packets */
  86605. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  86606. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  86607. + ep0_out_start(core_if, pcd);
  86608. + }
  86609. +
  86610. + goto exit_xfercompl;
  86611. + } else {
  86612. + /* Prepare for more setup packets */
  86613. + DWC_DEBUGPL(DBG_PCDV,
  86614. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  86615. + ep0_out_start(core_if, pcd);
  86616. + }
  86617. + }
  86618. + } else {
  86619. + dwc_otg_pcd_request_t *req;
  86620. + dev_dma_desc_sts_t status = {.d32 = 0};
  86621. + diepint_data_t diepint0;
  86622. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86623. + in_ep_regs[0]->diepint);
  86624. +
  86625. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  86626. + DWC_ERROR("EP0 is stalled/disconnected\n");
  86627. + }
  86628. +
  86629. + /* Clear IN xfercompl if set */
  86630. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  86631. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  86632. + DWC_WRITE_REG32(&core_if->dev_if->
  86633. + in_ep_regs[0]->diepint, diepint0.d32);
  86634. + }
  86635. +
  86636. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  86637. + dev_if->setup_desc_index]->status.d32;
  86638. +
  86639. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  86640. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  86641. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  86642. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  86643. + status.d32 = core_if->dev_if->
  86644. + out_desc_addr->status.d32;
  86645. +
  86646. + if (status.b.sr) {
  86647. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86648. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  86649. + } else {
  86650. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  86651. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86652. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  86653. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  86654. + /* Read arrived setup packet from req->buf */
  86655. + dwc_memcpy(&pcd->setup_pkt->req,
  86656. + req->buf + ep->dwc_ep.xfer_count, 8);
  86657. + }
  86658. + req->actual = ep->dwc_ep.xfer_count;
  86659. + dwc_otg_request_done(ep, req, -ECONNRESET);
  86660. + ep->dwc_ep.start_xfer_buff = 0;
  86661. + ep->dwc_ep.xfer_buff = 0;
  86662. + ep->dwc_ep.xfer_len = 0;
  86663. + }
  86664. + pcd->ep0state = EP0_IDLE;
  86665. + if (doepint.b.setup) {
  86666. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  86667. + /* Data stage started, clear setup */
  86668. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86669. + doepint.b.setup = 0;
  86670. + handle_ep0(pcd);
  86671. + /* Prepare for setup packets if ep0in was enabled*/
  86672. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86673. + ep0_out_start(core_if, pcd);
  86674. + }
  86675. +
  86676. + goto exit_xfercompl;
  86677. + } else {
  86678. + /* Prepare for more setup packets */
  86679. + DWC_DEBUGPL(DBG_PCDV,
  86680. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  86681. + ep0_out_start(core_if, pcd);
  86682. + }
  86683. + }
  86684. + }
  86685. + }
  86686. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  86687. + && core_if->dma_desc_enable == 0) {
  86688. + doepint_data_t doepint_temp = {.d32 = 0};
  86689. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86690. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  86691. + out_ep_regs[ep->dwc_ep.num]->doepint);
  86692. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86693. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  86694. + if (pcd->ep0state == EP0_IDLE) {
  86695. + if (doepint_temp.b.sr) {
  86696. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  86697. + }
  86698. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86699. + out_ep_regs[0]->doepint);
  86700. + if (doeptsize0.b.supcnt == 3) {
  86701. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  86702. + ep->dwc_ep.stp_rollover = 1;
  86703. + }
  86704. + if (doepint.b.setup) {
  86705. +retry:
  86706. + /* Already started data stage, clear setup */
  86707. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86708. + doepint.b.setup = 0;
  86709. + handle_ep0(pcd);
  86710. + ep->dwc_ep.stp_rollover = 0;
  86711. + /* Prepare for more setup packets */
  86712. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  86713. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  86714. + ep0_out_start(core_if, pcd);
  86715. + }
  86716. + goto exit_xfercompl;
  86717. + } else {
  86718. + /* Prepare for more setup packets */
  86719. + DWC_DEBUGPL(DBG_ANY,
  86720. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  86721. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86722. + out_ep_regs[0]->doepint);
  86723. + if(doepint.b.setup)
  86724. + goto retry;
  86725. + ep0_out_start(core_if, pcd);
  86726. + }
  86727. + } else {
  86728. + dwc_otg_pcd_request_t *req;
  86729. + diepint_data_t diepint0 = {.d32 = 0};
  86730. + doepint_data_t doepint_temp = {.d32 = 0};
  86731. + depctl_data_t diepctl0;
  86732. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86733. + in_ep_regs[0]->diepint);
  86734. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  86735. + in_ep_regs[0]->diepctl);
  86736. +
  86737. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  86738. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86739. + if (diepint0.b.xfercompl) {
  86740. + DWC_WRITE_REG32(&core_if->dev_if->
  86741. + in_ep_regs[0]->diepint, diepint0.d32);
  86742. + }
  86743. + if (diepctl0.b.epena) {
  86744. + diepint_data_t diepint = {.d32 = 0};
  86745. + diepctl0.b.snak = 1;
  86746. + DWC_WRITE_REG32(&core_if->dev_if->
  86747. + in_ep_regs[0]->diepctl, diepctl0.d32);
  86748. + do {
  86749. + dwc_udelay(10);
  86750. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86751. + in_ep_regs[0]->diepint);
  86752. + } while (!diepint.b.inepnakeff);
  86753. + diepint.b.inepnakeff = 1;
  86754. + DWC_WRITE_REG32(&core_if->dev_if->
  86755. + in_ep_regs[0]->diepint, diepint.d32);
  86756. + diepctl0.d32 = 0;
  86757. + diepctl0.b.epdis = 1;
  86758. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  86759. + diepctl0.d32);
  86760. + do {
  86761. + dwc_udelay(10);
  86762. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  86763. + in_ep_regs[0]->diepint);
  86764. + } while (!diepint.b.epdisabled);
  86765. + diepint.b.epdisabled = 1;
  86766. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  86767. + diepint.d32);
  86768. + }
  86769. + }
  86770. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  86771. + out_ep_regs[ep->dwc_ep.num]->doepint);
  86772. + if (doepint_temp.b.sr) {
  86773. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  86774. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86775. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  86776. + } else {
  86777. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  86778. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86779. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  86780. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  86781. + /* Read arrived setup packet from req->buf */
  86782. + dwc_memcpy(&pcd->setup_pkt->req,
  86783. + req->buf + ep->dwc_ep.xfer_count, 8);
  86784. + }
  86785. + req->actual = ep->dwc_ep.xfer_count;
  86786. + dwc_otg_request_done(ep, req, -ECONNRESET);
  86787. + ep->dwc_ep.start_xfer_buff = 0;
  86788. + ep->dwc_ep.xfer_buff = 0;
  86789. + ep->dwc_ep.xfer_len = 0;
  86790. + }
  86791. + pcd->ep0state = EP0_IDLE;
  86792. + if (doepint.b.setup) {
  86793. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  86794. + /* Data stage started, clear setup */
  86795. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86796. + doepint.b.setup = 0;
  86797. + handle_ep0(pcd);
  86798. + /* Prepare for setup packets if ep0in was enabled*/
  86799. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86800. + ep0_out_start(core_if, pcd);
  86801. + }
  86802. + goto exit_xfercompl;
  86803. + } else {
  86804. + /* Prepare for more setup packets */
  86805. + DWC_DEBUGPL(DBG_PCDV,
  86806. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  86807. + ep0_out_start(core_if, pcd);
  86808. + }
  86809. + }
  86810. + }
  86811. + }
  86812. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  86813. + handle_ep0(pcd);
  86814. +exit_xfercompl:
  86815. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  86816. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  86817. + } else {
  86818. + if (core_if->dma_desc_enable == 0
  86819. + || pcd->ep0state != EP0_IDLE)
  86820. + handle_ep0(pcd);
  86821. + }
  86822. +#ifdef DWC_EN_ISOC
  86823. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86824. + if (doepint.b.pktdrpsts == 0) {
  86825. + /* Clear the bit in DOEPINTn for this interrupt */
  86826. + CLEAR_OUT_EP_INTR(core_if,
  86827. + epnum,
  86828. + xfercompl);
  86829. + complete_iso_ep(pcd, ep);
  86830. + } else {
  86831. +
  86832. + doepint_data_t doepint = {.d32 = 0 };
  86833. + doepint.b.xfercompl = 1;
  86834. + doepint.b.pktdrpsts = 1;
  86835. + DWC_WRITE_REG32
  86836. + (&core_if->dev_if->out_ep_regs
  86837. + [epnum]->doepint,
  86838. + doepint.d32);
  86839. + if (handle_iso_out_pkt_dropped
  86840. + (core_if, dwc_ep)) {
  86841. + complete_iso_ep(pcd,
  86842. + ep);
  86843. + }
  86844. + }
  86845. +#endif /* DWC_EN_ISOC */
  86846. +#ifdef DWC_UTE_PER_IO
  86847. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  86848. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  86849. + if (!ep->stopped)
  86850. + complete_xiso_ep(ep);
  86851. +#endif /* DWC_UTE_PER_IO */
  86852. + } else {
  86853. + /* Clear the bit in DOEPINTn for this interrupt */
  86854. + CLEAR_OUT_EP_INTR(core_if, epnum,
  86855. + xfercompl);
  86856. +
  86857. + if (core_if->core_params->dev_out_nak) {
  86858. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  86859. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  86860. +#ifdef DEBUG
  86861. + print_memory_payload(pcd, dwc_ep);
  86862. +#endif
  86863. + }
  86864. + complete_ep(ep);
  86865. + }
  86866. +
  86867. + }
  86868. +
  86869. + /* Endpoint disable */
  86870. + if (doepint.b.epdisabled) {
  86871. +
  86872. + /* Clear the bit in DOEPINTn for this interrupt */
  86873. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  86874. + if (core_if->core_params->dev_out_nak) {
  86875. +#ifdef DEBUG
  86876. + print_memory_payload(pcd, dwc_ep);
  86877. +#endif
  86878. + /* In case of timeout condition */
  86879. + if (core_if->ep_xfer_info[epnum].state == 2) {
  86880. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86881. + dev_global_regs->dctl);
  86882. + dctl.b.cgoutnak = 1;
  86883. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  86884. + dctl.d32);
  86885. + /* Unmask goutnakeff interrupt which was masked
  86886. + * during handle nak out interrupt */
  86887. + gintmsk.b.goutnakeff = 1;
  86888. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  86889. + 0, gintmsk.d32);
  86890. +
  86891. + complete_ep(ep);
  86892. + }
  86893. + }
  86894. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  86895. + {
  86896. + dctl_data_t dctl;
  86897. + gintmsk_data_t intr_mask = {.d32 = 0};
  86898. + dwc_otg_pcd_request_t *req = 0;
  86899. +
  86900. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86901. + dev_global_regs->dctl);
  86902. + dctl.b.cgoutnak = 1;
  86903. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  86904. + dctl.d32);
  86905. +
  86906. + intr_mask.d32 = 0;
  86907. + intr_mask.b.incomplisoout = 1;
  86908. +
  86909. + /* Get any pending requests */
  86910. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86911. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86912. + if (!req) {
  86913. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  86914. + } else {
  86915. + dwc_otg_request_done(ep, req, 0);
  86916. + start_next_request(ep);
  86917. + }
  86918. + } else {
  86919. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  86920. + }
  86921. + }
  86922. + }
  86923. + /* AHB Error */
  86924. + if (doepint.b.ahberr) {
  86925. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  86926. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  86927. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  86928. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  86929. + }
  86930. + /* Setup Phase Done (contorl EPs) */
  86931. + if (doepint.b.setup) {
  86932. +#ifdef DEBUG_EP0
  86933. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  86934. +#endif
  86935. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  86936. +
  86937. + handle_ep0(pcd);
  86938. + }
  86939. +
  86940. + /** OUT EP BNA Intr */
  86941. + if (doepint.b.bna) {
  86942. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  86943. + if (core_if->dma_desc_enable) {
  86944. +#ifdef DWC_EN_ISOC
  86945. + if (dwc_ep->type ==
  86946. + DWC_OTG_EP_TYPE_ISOC) {
  86947. + /*
  86948. + * This checking is performed to prevent first "false" BNA
  86949. + * handling occuring right after reconnect
  86950. + */
  86951. + if (dwc_ep->next_frame !=
  86952. + 0xffffffff)
  86953. + dwc_otg_pcd_handle_iso_bna(ep);
  86954. + } else
  86955. +#endif /* DWC_EN_ISOC */
  86956. + {
  86957. + dwc_otg_pcd_handle_noniso_bna(ep);
  86958. + }
  86959. + }
  86960. + }
  86961. + /* Babble Interrupt */
  86962. + if (doepint.b.babble) {
  86963. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  86964. + epnum);
  86965. + handle_out_ep_babble_intr(pcd, epnum);
  86966. +
  86967. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  86968. + }
  86969. + if (doepint.b.outtknepdis) {
  86970. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  86971. + disabled\n",epnum);
  86972. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  86973. + doepmsk_data_t doepmsk = {.d32 = 0};
  86974. + ep->dwc_ep.frame_num = core_if->frame_num;
  86975. + if (ep->dwc_ep.bInterval > 1) {
  86976. + depctl_data_t depctl;
  86977. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  86978. + out_ep_regs[epnum]->doepctl);
  86979. + if (ep->dwc_ep.frame_num & 0x1) {
  86980. + depctl.b.setd1pid = 1;
  86981. + depctl.b.setd0pid = 0;
  86982. + } else {
  86983. + depctl.b.setd0pid = 1;
  86984. + depctl.b.setd1pid = 0;
  86985. + }
  86986. + DWC_WRITE_REG32(&core_if->dev_if->
  86987. + out_ep_regs[epnum]->doepctl, depctl.d32);
  86988. + }
  86989. + start_next_request(ep);
  86990. + doepmsk.b.outtknepdis = 1;
  86991. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  86992. + doepmsk.d32, 0);
  86993. + }
  86994. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  86995. + }
  86996. +
  86997. + /* NAK Interrutp */
  86998. + if (doepint.b.nak) {
  86999. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  87000. + handle_out_ep_nak_intr(pcd, epnum);
  87001. +
  87002. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  87003. + }
  87004. + /* NYET Interrutp */
  87005. + if (doepint.b.nyet) {
  87006. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  87007. + handle_out_ep_nyet_intr(pcd, epnum);
  87008. +
  87009. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  87010. + }
  87011. + }
  87012. +
  87013. + epnum++;
  87014. + ep_intr >>= 1;
  87015. + }
  87016. +
  87017. + return 1;
  87018. +
  87019. +#undef CLEAR_OUT_EP_INTR
  87020. +}
  87021. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  87022. +{
  87023. + int retval = 0;
  87024. + if(!frm_overrun && curr_fr >= trgt_fr)
  87025. + retval = 1;
  87026. + else if (frm_overrun
  87027. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  87028. + retval = 1;
  87029. + return retval;
  87030. +}
  87031. +/**
  87032. + * Incomplete ISO IN Transfer Interrupt.
  87033. + * This interrupt indicates one of the following conditions occurred
  87034. + * while transmitting an ISOC transaction.
  87035. + * - Corrupted IN Token for ISOC EP.
  87036. + * - Packet not complete in FIFO.
  87037. + * The follow actions will be taken:
  87038. + * -# Determine the EP
  87039. + * -# Set incomplete flag in dwc_ep structure
  87040. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  87041. + * Flush FIFO
  87042. + */
  87043. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  87044. +{
  87045. + gintsts_data_t gintsts;
  87046. +
  87047. +#ifdef DWC_EN_ISOC
  87048. + dwc_otg_dev_if_t *dev_if;
  87049. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87050. + depctl_data_t depctl = {.d32 = 0 };
  87051. + dsts_data_t dsts = {.d32 = 0 };
  87052. + dwc_ep_t *dwc_ep;
  87053. + int i;
  87054. +
  87055. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87056. +
  87057. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  87058. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  87059. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87060. + deptsiz.d32 =
  87061. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  87062. + depctl.d32 =
  87063. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87064. +
  87065. + if (depctl.b.epdis && deptsiz.d32) {
  87066. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  87067. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87068. + dwc_ep->cur_pkt = 0;
  87069. + dwc_ep->proc_buf_num =
  87070. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87071. +
  87072. + if (dwc_ep->proc_buf_num) {
  87073. + dwc_ep->cur_pkt_addr =
  87074. + dwc_ep->xfer_buff1;
  87075. + dwc_ep->cur_pkt_dma_addr =
  87076. + dwc_ep->dma_addr1;
  87077. + } else {
  87078. + dwc_ep->cur_pkt_addr =
  87079. + dwc_ep->xfer_buff0;
  87080. + dwc_ep->cur_pkt_dma_addr =
  87081. + dwc_ep->dma_addr0;
  87082. + }
  87083. +
  87084. + }
  87085. +
  87086. + dsts.d32 =
  87087. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  87088. + dev_global_regs->dsts);
  87089. + dwc_ep->next_frame = dsts.b.soffn;
  87090. +
  87091. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  87092. + (pcd),
  87093. + dwc_ep);
  87094. + }
  87095. + }
  87096. + }
  87097. +
  87098. +#else
  87099. + depctl_data_t depctl = {.d32 = 0 };
  87100. + dwc_ep_t *dwc_ep;
  87101. + dwc_otg_dev_if_t *dev_if;
  87102. + int i;
  87103. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87104. +
  87105. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  87106. +
  87107. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  87108. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  87109. + depctl.d32 =
  87110. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87111. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87112. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  87113. + dwc_ep->frm_overrun))
  87114. + {
  87115. + depctl.d32 =
  87116. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87117. + depctl.b.snak = 1;
  87118. + depctl.b.epdis = 1;
  87119. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  87120. + }
  87121. + }
  87122. + }
  87123. +
  87124. + /*intr_mask.b.incomplisoin = 1;
  87125. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87126. + intr_mask.d32, 0); */
  87127. +#endif //DWC_EN_ISOC
  87128. +
  87129. + /* Clear interrupt */
  87130. + gintsts.d32 = 0;
  87131. + gintsts.b.incomplisoin = 1;
  87132. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87133. + gintsts.d32);
  87134. +
  87135. + return 1;
  87136. +}
  87137. +
  87138. +/**
  87139. + * Incomplete ISO OUT Transfer Interrupt.
  87140. + *
  87141. + * This interrupt indicates that the core has dropped an ISO OUT
  87142. + * packet. The following conditions can be the cause:
  87143. + * - FIFO Full, the entire packet would not fit in the FIFO.
  87144. + * - CRC Error
  87145. + * - Corrupted Token
  87146. + * The follow actions will be taken:
  87147. + * -# Determine the EP
  87148. + * -# Set incomplete flag in dwc_ep structure
  87149. + * -# Read any data from the FIFO
  87150. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  87151. + * re-enable EP.
  87152. + */
  87153. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  87154. +{
  87155. +
  87156. + gintsts_data_t gintsts;
  87157. +
  87158. +#ifdef DWC_EN_ISOC
  87159. + dwc_otg_dev_if_t *dev_if;
  87160. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87161. + depctl_data_t depctl = {.d32 = 0 };
  87162. + dsts_data_t dsts = {.d32 = 0 };
  87163. + dwc_ep_t *dwc_ep;
  87164. + int i;
  87165. +
  87166. + dev_if = GET_CORE_IF(pcd)->dev_if;
  87167. +
  87168. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  87169. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  87170. + if (pcd->out_ep[i].dwc_ep.active &&
  87171. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87172. + deptsiz.d32 =
  87173. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  87174. + depctl.d32 =
  87175. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  87176. +
  87177. + if (depctl.b.epdis && deptsiz.d32) {
  87178. + set_current_pkt_info(GET_CORE_IF(pcd),
  87179. + &pcd->out_ep[i].dwc_ep);
  87180. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87181. + dwc_ep->cur_pkt = 0;
  87182. + dwc_ep->proc_buf_num =
  87183. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87184. +
  87185. + if (dwc_ep->proc_buf_num) {
  87186. + dwc_ep->cur_pkt_addr =
  87187. + dwc_ep->xfer_buff1;
  87188. + dwc_ep->cur_pkt_dma_addr =
  87189. + dwc_ep->dma_addr1;
  87190. + } else {
  87191. + dwc_ep->cur_pkt_addr =
  87192. + dwc_ep->xfer_buff0;
  87193. + dwc_ep->cur_pkt_dma_addr =
  87194. + dwc_ep->dma_addr0;
  87195. + }
  87196. +
  87197. + }
  87198. +
  87199. + dsts.d32 =
  87200. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  87201. + dev_global_regs->dsts);
  87202. + dwc_ep->next_frame = dsts.b.soffn;
  87203. +
  87204. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  87205. + (pcd),
  87206. + dwc_ep);
  87207. + }
  87208. + }
  87209. + }
  87210. +#else
  87211. + /** @todo implement ISR */
  87212. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87213. + dwc_otg_core_if_t *core_if;
  87214. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87215. + depctl_data_t depctl = {.d32 = 0 };
  87216. + dctl_data_t dctl = {.d32 = 0 };
  87217. + dwc_ep_t *dwc_ep = NULL;
  87218. + int i;
  87219. + core_if = GET_CORE_IF(pcd);
  87220. +
  87221. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  87222. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  87223. + depctl.d32 =
  87224. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  87225. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  87226. + core_if->dev_if->isoc_ep = dwc_ep;
  87227. + deptsiz.d32 =
  87228. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  87229. + break;
  87230. + }
  87231. + }
  87232. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  87233. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  87234. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  87235. +
  87236. + if (!intr_mask.b.goutnakeff) {
  87237. + /* Unmask it */
  87238. + intr_mask.b.goutnakeff = 1;
  87239. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  87240. + }
  87241. + if (!gintsts.b.goutnakeff) {
  87242. + dctl.b.sgoutnak = 1;
  87243. + }
  87244. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  87245. +
  87246. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  87247. + if (depctl.b.epena) {
  87248. + depctl.b.epdis = 1;
  87249. + depctl.b.snak = 1;
  87250. + }
  87251. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  87252. +
  87253. + intr_mask.d32 = 0;
  87254. + intr_mask.b.incomplisoout = 1;
  87255. +
  87256. +#endif /* DWC_EN_ISOC */
  87257. +
  87258. + /* Clear interrupt */
  87259. + gintsts.d32 = 0;
  87260. + gintsts.b.incomplisoout = 1;
  87261. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87262. + gintsts.d32);
  87263. +
  87264. + return 1;
  87265. +}
  87266. +
  87267. +/**
  87268. + * This function handles the Global IN NAK Effective interrupt.
  87269. + *
  87270. + */
  87271. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  87272. +{
  87273. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87274. + depctl_data_t diepctl = {.d32 = 0 };
  87275. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87276. + gintsts_data_t gintsts;
  87277. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87278. + int i;
  87279. +
  87280. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  87281. +
  87282. + /* Disable all active IN EPs */
  87283. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  87284. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  87285. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  87286. + if (core_if->start_predict > 0)
  87287. + core_if->start_predict++;
  87288. + diepctl.b.epdis = 1;
  87289. + diepctl.b.snak = 1;
  87290. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  87291. + }
  87292. + }
  87293. +
  87294. +
  87295. + /* Disable the Global IN NAK Effective Interrupt */
  87296. + intr_mask.b.ginnakeff = 1;
  87297. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87298. + intr_mask.d32, 0);
  87299. +
  87300. + /* Clear interrupt */
  87301. + gintsts.d32 = 0;
  87302. + gintsts.b.ginnakeff = 1;
  87303. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87304. + gintsts.d32);
  87305. +
  87306. + return 1;
  87307. +}
  87308. +
  87309. +/**
  87310. + * OUT NAK Effective.
  87311. + *
  87312. + */
  87313. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  87314. +{
  87315. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  87316. + gintmsk_data_t intr_mask = {.d32 = 0 };
  87317. + gintsts_data_t gintsts;
  87318. + depctl_data_t doepctl;
  87319. + int i;
  87320. +
  87321. + /* Disable the Global OUT NAK Effective Interrupt */
  87322. + intr_mask.b.goutnakeff = 1;
  87323. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  87324. + intr_mask.d32, 0);
  87325. +
  87326. + /* If DEV OUT NAK enabled*/
  87327. + if (pcd->core_if->core_params->dev_out_nak) {
  87328. + /* Run over all out endpoints to determine the ep number on
  87329. + * which the timeout has happened
  87330. + */
  87331. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  87332. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  87333. + break;
  87334. + }
  87335. + if (i > dev_if->num_out_eps) {
  87336. + dctl_data_t dctl;
  87337. + dctl.d32 =
  87338. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  87339. + dctl.b.cgoutnak = 1;
  87340. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  87341. + dctl.d32);
  87342. + goto out;
  87343. + }
  87344. +
  87345. + /* Disable the endpoint */
  87346. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  87347. + if (doepctl.b.epena) {
  87348. + doepctl.b.epdis = 1;
  87349. + doepctl.b.snak = 1;
  87350. + }
  87351. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  87352. + return 1;
  87353. + }
  87354. + /* We come here from Incomplete ISO OUT handler */
  87355. + if (dev_if->isoc_ep) {
  87356. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  87357. + uint32_t epnum = dwc_ep->num;
  87358. + doepint_data_t doepint;
  87359. + doepint.d32 =
  87360. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  87361. + dev_if->isoc_ep = NULL;
  87362. + doepctl.d32 =
  87363. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  87364. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  87365. + if (doepctl.b.epena) {
  87366. + doepctl.b.epdis = 1;
  87367. + doepctl.b.snak = 1;
  87368. + }
  87369. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  87370. + doepctl.d32);
  87371. + return 1;
  87372. + } else
  87373. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  87374. + "Global OUT NAK Effective\n");
  87375. +
  87376. +out:
  87377. + /* Clear interrupt */
  87378. + gintsts.d32 = 0;
  87379. + gintsts.b.goutnakeff = 1;
  87380. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  87381. + gintsts.d32);
  87382. +
  87383. + return 1;
  87384. +}
  87385. +
  87386. +/**
  87387. + * PCD interrupt handler.
  87388. + *
  87389. + * The PCD handles the device interrupts. Many conditions can cause a
  87390. + * device interrupt. When an interrupt occurs, the device interrupt
  87391. + * service routine determines the cause of the interrupt and
  87392. + * dispatches handling to the appropriate function. These interrupt
  87393. + * handling functions are described below.
  87394. + *
  87395. + * All interrupt registers are processed from LSB to MSB.
  87396. + *
  87397. + */
  87398. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  87399. +{
  87400. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87401. +#ifdef VERBOSE
  87402. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  87403. +#endif
  87404. + gintsts_data_t gintr_status;
  87405. + int32_t retval = 0;
  87406. +
  87407. + /* Exit from ISR if core is hibernated */
  87408. + if (core_if->hibernation_suspend == 1) {
  87409. + return retval;
  87410. + }
  87411. +#ifdef VERBOSE
  87412. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  87413. + __func__,
  87414. + DWC_READ_REG32(&global_regs->gintsts),
  87415. + DWC_READ_REG32(&global_regs->gintmsk));
  87416. +#endif
  87417. +
  87418. + if (dwc_otg_is_device_mode(core_if)) {
  87419. + DWC_SPINLOCK(pcd->lock);
  87420. +#ifdef VERBOSE
  87421. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  87422. + __func__,
  87423. + DWC_READ_REG32(&global_regs->gintsts),
  87424. + DWC_READ_REG32(&global_regs->gintmsk));
  87425. +#endif
  87426. +
  87427. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  87428. +
  87429. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  87430. + __func__, gintr_status.d32);
  87431. +
  87432. + if (gintr_status.b.sofintr) {
  87433. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  87434. + }
  87435. + if (gintr_status.b.rxstsqlvl) {
  87436. + retval |=
  87437. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  87438. + }
  87439. + if (gintr_status.b.nptxfempty) {
  87440. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  87441. + }
  87442. + if (gintr_status.b.goutnakeff) {
  87443. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  87444. + }
  87445. + if (gintr_status.b.i2cintr) {
  87446. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  87447. + }
  87448. + if (gintr_status.b.erlysuspend) {
  87449. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  87450. + }
  87451. + if (gintr_status.b.usbreset) {
  87452. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  87453. + }
  87454. + if (gintr_status.b.enumdone) {
  87455. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  87456. + }
  87457. + if (gintr_status.b.isooutdrop) {
  87458. + retval |=
  87459. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  87460. + (pcd);
  87461. + }
  87462. + if (gintr_status.b.eopframe) {
  87463. + retval |=
  87464. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  87465. + }
  87466. + if (gintr_status.b.inepint) {
  87467. + if (!core_if->multiproc_int_enable) {
  87468. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  87469. + }
  87470. + }
  87471. + if (gintr_status.b.outepintr) {
  87472. + if (!core_if->multiproc_int_enable) {
  87473. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  87474. + }
  87475. + }
  87476. + if (gintr_status.b.epmismatch) {
  87477. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  87478. + }
  87479. + if (gintr_status.b.fetsusp) {
  87480. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  87481. + }
  87482. + if (gintr_status.b.ginnakeff) {
  87483. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  87484. + }
  87485. + if (gintr_status.b.incomplisoin) {
  87486. + retval |=
  87487. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  87488. + }
  87489. + if (gintr_status.b.incomplisoout) {
  87490. + retval |=
  87491. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  87492. + }
  87493. +
  87494. + /* In MPI mode Device Endpoints interrupts are asserted
  87495. + * without setting outepintr and inepint bits set, so these
  87496. + * Interrupt handlers are called without checking these bit-fields
  87497. + */
  87498. + if (core_if->multiproc_int_enable) {
  87499. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  87500. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  87501. + }
  87502. +#ifdef VERBOSE
  87503. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  87504. + DWC_READ_REG32(&global_regs->gintsts));
  87505. +#endif
  87506. + DWC_SPINUNLOCK(pcd->lock);
  87507. + }
  87508. + return retval;
  87509. +}
  87510. +
  87511. +#endif /* DWC_HOST_ONLY */
  87512. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  87513. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  87514. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-02-07 19:57:30.000000000 +0100
  87515. @@ -0,0 +1,1358 @@
  87516. + /* ==========================================================================
  87517. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  87518. + * $Revision: #21 $
  87519. + * $Date: 2012/08/10 $
  87520. + * $Change: 2047372 $
  87521. + *
  87522. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  87523. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  87524. + * otherwise expressly agreed to in writing between Synopsys and you.
  87525. + *
  87526. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  87527. + * any End User Software License Agreement or Agreement for Licensed Product
  87528. + * with Synopsys or any supplement thereto. You are permitted to use and
  87529. + * redistribute this Software in source and binary forms, with or without
  87530. + * modification, provided that redistributions of source code must retain this
  87531. + * notice. You may not view, use, disclose, copy or distribute this file or
  87532. + * any information contained herein except pursuant to this license grant from
  87533. + * Synopsys. If you do not agree with this notice, including the disclaimer
  87534. + * below, then you are not authorized to use the Software.
  87535. + *
  87536. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  87537. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  87538. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  87539. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  87540. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  87541. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  87542. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  87543. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  87544. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  87545. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  87546. + * DAMAGE.
  87547. + * ========================================================================== */
  87548. +#ifndef DWC_HOST_ONLY
  87549. +
  87550. +/** @file
  87551. + * This file implements the Peripheral Controller Driver.
  87552. + *
  87553. + * The Peripheral Controller Driver (PCD) is responsible for
  87554. + * translating requests from the Function Driver into the appropriate
  87555. + * actions on the DWC_otg controller. It isolates the Function Driver
  87556. + * from the specifics of the controller by providing an API to the
  87557. + * Function Driver.
  87558. + *
  87559. + * The Peripheral Controller Driver for Linux will implement the
  87560. + * Gadget API, so that the existing Gadget drivers can be used.
  87561. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  87562. + *
  87563. + * The Linux Gadget API is defined in the header file
  87564. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  87565. + * defined in the structure <code>usb_ep_ops</code> and the USB
  87566. + * Controller API is defined in the structure
  87567. + * <code>usb_gadget_ops</code>.
  87568. + *
  87569. + */
  87570. +
  87571. +#include "dwc_otg_os_dep.h"
  87572. +#include "dwc_otg_pcd_if.h"
  87573. +#include "dwc_otg_pcd.h"
  87574. +#include "dwc_otg_driver.h"
  87575. +#include "dwc_otg_dbg.h"
  87576. +
  87577. +static struct gadget_wrapper {
  87578. + dwc_otg_pcd_t *pcd;
  87579. +
  87580. + struct usb_gadget gadget;
  87581. + struct usb_gadget_driver *driver;
  87582. +
  87583. + struct usb_ep ep0;
  87584. + struct usb_ep in_ep[16];
  87585. + struct usb_ep out_ep[16];
  87586. +
  87587. +} *gadget_wrapper;
  87588. +
  87589. +/* Display the contents of the buffer */
  87590. +extern void dump_msg(const u8 * buf, unsigned int length);
  87591. +/**
  87592. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  87593. + * if the endpoint is not found
  87594. + */
  87595. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  87596. +{
  87597. + int i;
  87598. + if (pcd->ep0.priv == handle) {
  87599. + return &pcd->ep0;
  87600. + }
  87601. +
  87602. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  87603. + if (pcd->in_ep[i].priv == handle)
  87604. + return &pcd->in_ep[i];
  87605. + if (pcd->out_ep[i].priv == handle)
  87606. + return &pcd->out_ep[i];
  87607. + }
  87608. +
  87609. + return NULL;
  87610. +}
  87611. +
  87612. +/* USB Endpoint Operations */
  87613. +/*
  87614. + * The following sections briefly describe the behavior of the Gadget
  87615. + * API endpoint operations implemented in the DWC_otg driver
  87616. + * software. Detailed descriptions of the generic behavior of each of
  87617. + * these functions can be found in the Linux header file
  87618. + * include/linux/usb_gadget.h.
  87619. + *
  87620. + * The Gadget API provides wrapper functions for each of the function
  87621. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  87622. + * function, which then calls the underlying PCD function. The
  87623. + * following sections are named according to the wrapper
  87624. + * functions. Within each section, the corresponding DWC_otg PCD
  87625. + * function name is specified.
  87626. + *
  87627. + */
  87628. +
  87629. +/**
  87630. + * This function is called by the Gadget Driver for each EP to be
  87631. + * configured for the current configuration (SET_CONFIGURATION).
  87632. + *
  87633. + * This function initializes the dwc_otg_ep_t data structure, and then
  87634. + * calls dwc_otg_ep_activate.
  87635. + */
  87636. +static int ep_enable(struct usb_ep *usb_ep,
  87637. + const struct usb_endpoint_descriptor *ep_desc)
  87638. +{
  87639. + int retval;
  87640. +
  87641. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  87642. +
  87643. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  87644. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  87645. + return -EINVAL;
  87646. + }
  87647. + if (usb_ep == &gadget_wrapper->ep0) {
  87648. + DWC_WARN("%s, bad ep(0)\n", __func__);
  87649. + return -EINVAL;
  87650. + }
  87651. +
  87652. + /* Check FIFO size? */
  87653. + if (!ep_desc->wMaxPacketSize) {
  87654. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  87655. + return -ERANGE;
  87656. + }
  87657. +
  87658. + if (!gadget_wrapper->driver ||
  87659. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87660. + DWC_WARN("%s, bogus device state\n", __func__);
  87661. + return -ESHUTDOWN;
  87662. + }
  87663. +
  87664. + /* Delete after check - MAS */
  87665. +#if 0
  87666. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  87667. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  87668. + nat = (nat >> 11) & 0x03;
  87669. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  87670. +#endif
  87671. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  87672. + (const uint8_t *)ep_desc,
  87673. + (void *)usb_ep);
  87674. + if (retval) {
  87675. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  87676. + return -EINVAL;
  87677. + }
  87678. +
  87679. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  87680. +
  87681. + return 0;
  87682. +}
  87683. +
  87684. +/**
  87685. + * This function is called when an EP is disabled due to disconnect or
  87686. + * change in configuration. Any pending requests will terminate with a
  87687. + * status of -ESHUTDOWN.
  87688. + *
  87689. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  87690. + * and then calls dwc_otg_ep_deactivate.
  87691. + */
  87692. +static int ep_disable(struct usb_ep *usb_ep)
  87693. +{
  87694. + int retval;
  87695. +
  87696. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  87697. + if (!usb_ep) {
  87698. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  87699. + usb_ep ? usb_ep->name : NULL);
  87700. + return -EINVAL;
  87701. + }
  87702. +
  87703. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  87704. + if (retval) {
  87705. + retval = -EINVAL;
  87706. + }
  87707. +
  87708. + return retval;
  87709. +}
  87710. +
  87711. +/**
  87712. + * This function allocates a request object to use with the specified
  87713. + * endpoint.
  87714. + *
  87715. + * @param ep The endpoint to be used with with the request
  87716. + * @param gfp_flags the GFP_* flags to use.
  87717. + */
  87718. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  87719. + gfp_t gfp_flags)
  87720. +{
  87721. + struct usb_request *usb_req;
  87722. +
  87723. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  87724. + if (0 == ep) {
  87725. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  87726. + return 0;
  87727. + }
  87728. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  87729. + if (0 == usb_req) {
  87730. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  87731. + return 0;
  87732. + }
  87733. + memset(usb_req, 0, sizeof(*usb_req));
  87734. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  87735. +
  87736. + return usb_req;
  87737. +}
  87738. +
  87739. +/**
  87740. + * This function frees a request object.
  87741. + *
  87742. + * @param ep The endpoint associated with the request
  87743. + * @param req The request being freed
  87744. + */
  87745. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  87746. +{
  87747. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  87748. +
  87749. + if (0 == ep || 0 == req) {
  87750. + DWC_WARN("%s() %s\n", __func__,
  87751. + "Invalid ep or req argument!\n");
  87752. + return;
  87753. + }
  87754. +
  87755. + kfree(req);
  87756. +}
  87757. +
  87758. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87759. +/**
  87760. + * This function allocates an I/O buffer to be used for a transfer
  87761. + * to/from the specified endpoint.
  87762. + *
  87763. + * @param usb_ep The endpoint to be used with with the request
  87764. + * @param bytes The desired number of bytes for the buffer
  87765. + * @param dma Pointer to the buffer's DMA address; must be valid
  87766. + * @param gfp_flags the GFP_* flags to use.
  87767. + * @return address of a new buffer or null is buffer could not be allocated.
  87768. + */
  87769. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  87770. + dma_addr_t * dma, gfp_t gfp_flags)
  87771. +{
  87772. + void *buf;
  87773. + dwc_otg_pcd_t *pcd = 0;
  87774. +
  87775. + pcd = gadget_wrapper->pcd;
  87776. +
  87777. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  87778. + dma, gfp_flags);
  87779. +
  87780. + /* Check dword alignment */
  87781. + if ((bytes & 0x3UL) != 0) {
  87782. + DWC_WARN("%s() Buffer size is not a multiple of"
  87783. + "DWORD size (%d)", __func__, bytes);
  87784. + }
  87785. +
  87786. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  87787. +
  87788. + /* Check dword alignment */
  87789. + if (((int)buf & 0x3UL) != 0) {
  87790. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  87791. + __func__, buf);
  87792. + }
  87793. +
  87794. + return buf;
  87795. +}
  87796. +
  87797. +/**
  87798. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  87799. + *
  87800. + * @param usb_ep the endpoint associated with the buffer
  87801. + * @param buf address of the buffer
  87802. + * @param dma The buffer's DMA address
  87803. + * @param bytes The number of bytes of the buffer
  87804. + */
  87805. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  87806. + dma_addr_t dma, unsigned bytes)
  87807. +{
  87808. + dwc_otg_pcd_t *pcd = 0;
  87809. +
  87810. + pcd = gadget_wrapper->pcd;
  87811. +
  87812. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  87813. +
  87814. + dma_free_coherent(NULL, bytes, buf, dma);
  87815. +}
  87816. +#endif
  87817. +
  87818. +/**
  87819. + * This function is used to submit an I/O Request to an EP.
  87820. + *
  87821. + * - When the request completes the request's completion callback
  87822. + * is called to return the request to the driver.
  87823. + * - An EP, except control EPs, may have multiple requests
  87824. + * pending.
  87825. + * - Once submitted the request cannot be examined or modified.
  87826. + * - Each request is turned into one or more packets.
  87827. + * - A BULK EP can queue any amount of data; the transfer is
  87828. + * packetized.
  87829. + * - Zero length Packets are specified with the request 'zero'
  87830. + * flag.
  87831. + */
  87832. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  87833. + gfp_t gfp_flags)
  87834. +{
  87835. + dwc_otg_pcd_t *pcd;
  87836. + struct dwc_otg_pcd_ep *ep = NULL;
  87837. + int retval = 0, is_isoc_ep = 0;
  87838. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  87839. +
  87840. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  87841. + __func__, usb_ep, usb_req, gfp_flags);
  87842. +
  87843. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  87844. + DWC_WARN("bad params\n");
  87845. + return -EINVAL;
  87846. + }
  87847. +
  87848. + if (!usb_ep) {
  87849. + DWC_WARN("bad ep\n");
  87850. + return -EINVAL;
  87851. + }
  87852. +
  87853. + pcd = gadget_wrapper->pcd;
  87854. + if (!gadget_wrapper->driver ||
  87855. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87856. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  87857. + gadget_wrapper->gadget.speed);
  87858. + DWC_WARN("bogus device state\n");
  87859. + return -ESHUTDOWN;
  87860. + }
  87861. +
  87862. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  87863. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  87864. +
  87865. + usb_req->status = -EINPROGRESS;
  87866. + usb_req->actual = 0;
  87867. +
  87868. + ep = ep_from_handle(pcd, usb_ep);
  87869. + if (ep == NULL)
  87870. + is_isoc_ep = 0;
  87871. + else
  87872. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  87873. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  87874. + dma_addr = usb_req->dma;
  87875. +#else
  87876. + if (GET_CORE_IF(pcd)->dma_enable) {
  87877. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  87878. + struct device *dev = NULL;
  87879. +
  87880. + if (otg_dev != NULL)
  87881. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  87882. +
  87883. + if (usb_req->length != 0 &&
  87884. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  87885. + dma_addr = dma_map_single(dev, usb_req->buf,
  87886. + usb_req->length,
  87887. + ep->dwc_ep.is_in ?
  87888. + DMA_TO_DEVICE:
  87889. + DMA_FROM_DEVICE);
  87890. + }
  87891. + }
  87892. +#endif
  87893. +
  87894. +#ifdef DWC_UTE_PER_IO
  87895. + if (is_isoc_ep == 1) {
  87896. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  87897. + usb_req->length, usb_req->zero, usb_req,
  87898. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  87899. + if (retval)
  87900. + return -EINVAL;
  87901. +
  87902. + return 0;
  87903. + }
  87904. +#endif
  87905. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  87906. + usb_req->length, usb_req->zero, usb_req,
  87907. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  87908. + if (retval) {
  87909. + return -EINVAL;
  87910. + }
  87911. +
  87912. + return 0;
  87913. +}
  87914. +
  87915. +/**
  87916. + * This function cancels an I/O request from an EP.
  87917. + */
  87918. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  87919. +{
  87920. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  87921. +
  87922. + if (!usb_ep || !usb_req) {
  87923. + DWC_WARN("bad argument\n");
  87924. + return -EINVAL;
  87925. + }
  87926. + if (!gadget_wrapper->driver ||
  87927. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  87928. + DWC_WARN("bogus device state\n");
  87929. + return -ESHUTDOWN;
  87930. + }
  87931. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  87932. + return -EINVAL;
  87933. + }
  87934. +
  87935. + return 0;
  87936. +}
  87937. +
  87938. +/**
  87939. + * usb_ep_set_halt stalls an endpoint.
  87940. + *
  87941. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  87942. + * toggle.
  87943. + *
  87944. + * Both of these functions are implemented with the same underlying
  87945. + * function. The behavior depends on the value argument.
  87946. + *
  87947. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  87948. + * @param[in] value
  87949. + * - 0 means clear_halt.
  87950. + * - 1 means set_halt,
  87951. + * - 2 means clear stall lock flag.
  87952. + * - 3 means set stall lock flag.
  87953. + */
  87954. +static int ep_halt(struct usb_ep *usb_ep, int value)
  87955. +{
  87956. + int retval = 0;
  87957. +
  87958. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  87959. +
  87960. + if (!usb_ep) {
  87961. + DWC_WARN("bad ep\n");
  87962. + return -EINVAL;
  87963. + }
  87964. +
  87965. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  87966. + if (retval == -DWC_E_AGAIN) {
  87967. + return -EAGAIN;
  87968. + } else if (retval) {
  87969. + retval = -EINVAL;
  87970. + }
  87971. +
  87972. + return retval;
  87973. +}
  87974. +
  87975. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  87976. +#if 0
  87977. +/**
  87978. + * ep_wedge: sets the halt feature and ignores clear requests
  87979. + *
  87980. + * @usb_ep: the endpoint being wedged
  87981. + *
  87982. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  87983. + * requests. If the gadget driver clears the halt status, it will
  87984. + * automatically unwedge the endpoint.
  87985. + *
  87986. + * Returns zero on success, else negative errno. *
  87987. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  87988. + */
  87989. +static int ep_wedge(struct usb_ep *usb_ep)
  87990. +{
  87991. + int retval = 0;
  87992. +
  87993. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  87994. +
  87995. + if (!usb_ep) {
  87996. + DWC_WARN("bad ep\n");
  87997. + return -EINVAL;
  87998. + }
  87999. +
  88000. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  88001. + if (retval == -DWC_E_AGAIN) {
  88002. + retval = -EAGAIN;
  88003. + } else if (retval) {
  88004. + retval = -EINVAL;
  88005. + }
  88006. +
  88007. + return retval;
  88008. +}
  88009. +#endif
  88010. +
  88011. +#ifdef DWC_EN_ISOC
  88012. +/**
  88013. + * This function is used to submit an ISOC Transfer Request to an EP.
  88014. + *
  88015. + * - Every time a sync period completes the request's completion callback
  88016. + * is called to provide data to the gadget driver.
  88017. + * - Once submitted the request cannot be modified.
  88018. + * - Each request is turned into periodic data packets untill ISO
  88019. + * Transfer is stopped..
  88020. + */
  88021. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  88022. + gfp_t gfp_flags)
  88023. +{
  88024. + int retval = 0;
  88025. +
  88026. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  88027. + DWC_WARN("bad params\n");
  88028. + return -EINVAL;
  88029. + }
  88030. +
  88031. + if (!usb_ep) {
  88032. + DWC_PRINTF("bad params\n");
  88033. + return -EINVAL;
  88034. + }
  88035. +
  88036. + req->status = -EINPROGRESS;
  88037. +
  88038. + retval =
  88039. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  88040. + req->buf1, req->dma0, req->dma1,
  88041. + req->sync_frame, req->data_pattern_frame,
  88042. + req->data_per_frame,
  88043. + req->
  88044. + flags & USB_REQ_ISO_ASAP ? -1 :
  88045. + req->start_frame, req->buf_proc_intrvl,
  88046. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  88047. +
  88048. + if (retval) {
  88049. + return -EINVAL;
  88050. + }
  88051. +
  88052. + return retval;
  88053. +}
  88054. +
  88055. +/**
  88056. + * This function stops ISO EP Periodic Data Transfer.
  88057. + */
  88058. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  88059. +{
  88060. + int retval = 0;
  88061. + if (!usb_ep) {
  88062. + DWC_WARN("bad ep\n");
  88063. + }
  88064. +
  88065. + if (!gadget_wrapper->driver ||
  88066. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  88067. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  88068. + gadget_wrapper->gadget.speed);
  88069. + DWC_WARN("bogus device state\n");
  88070. + }
  88071. +
  88072. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  88073. + if (retval) {
  88074. + retval = -EINVAL;
  88075. + }
  88076. +
  88077. + return retval;
  88078. +}
  88079. +
  88080. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  88081. + int packets, gfp_t gfp_flags)
  88082. +{
  88083. + struct usb_iso_request *pReq = NULL;
  88084. + uint32_t req_size;
  88085. +
  88086. + req_size = sizeof(struct usb_iso_request);
  88087. + req_size +=
  88088. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  88089. +
  88090. + pReq = kmalloc(req_size, gfp_flags);
  88091. + if (!pReq) {
  88092. + DWC_WARN("Can't allocate Iso Request\n");
  88093. + return 0;
  88094. + }
  88095. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  88096. +
  88097. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  88098. +
  88099. + return pReq;
  88100. +}
  88101. +
  88102. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  88103. +{
  88104. + kfree(req);
  88105. +}
  88106. +
  88107. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  88108. + .ep_ops = {
  88109. + .enable = ep_enable,
  88110. + .disable = ep_disable,
  88111. +
  88112. + .alloc_request = dwc_otg_pcd_alloc_request,
  88113. + .free_request = dwc_otg_pcd_free_request,
  88114. +
  88115. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88116. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  88117. + .free_buffer = dwc_otg_pcd_free_buffer,
  88118. +#endif
  88119. +
  88120. + .queue = ep_queue,
  88121. + .dequeue = ep_dequeue,
  88122. +
  88123. + .set_halt = ep_halt,
  88124. + .fifo_status = 0,
  88125. + .fifo_flush = 0,
  88126. + },
  88127. + .iso_ep_start = iso_ep_start,
  88128. + .iso_ep_stop = iso_ep_stop,
  88129. + .alloc_iso_request = alloc_iso_request,
  88130. + .free_iso_request = free_iso_request,
  88131. +};
  88132. +
  88133. +#else
  88134. +
  88135. + int (*enable) (struct usb_ep *ep,
  88136. + const struct usb_endpoint_descriptor *desc);
  88137. + int (*disable) (struct usb_ep *ep);
  88138. +
  88139. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  88140. + gfp_t gfp_flags);
  88141. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  88142. +
  88143. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  88144. + gfp_t gfp_flags);
  88145. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  88146. +
  88147. + int (*set_halt) (struct usb_ep *ep, int value);
  88148. + int (*set_wedge) (struct usb_ep *ep);
  88149. +
  88150. + int (*fifo_status) (struct usb_ep *ep);
  88151. + void (*fifo_flush) (struct usb_ep *ep);
  88152. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  88153. + .enable = ep_enable,
  88154. + .disable = ep_disable,
  88155. +
  88156. + .alloc_request = dwc_otg_pcd_alloc_request,
  88157. + .free_request = dwc_otg_pcd_free_request,
  88158. +
  88159. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  88160. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  88161. + .free_buffer = dwc_otg_pcd_free_buffer,
  88162. +#else
  88163. + /* .set_wedge = ep_wedge, */
  88164. + .set_wedge = NULL, /* uses set_halt instead */
  88165. +#endif
  88166. +
  88167. + .queue = ep_queue,
  88168. + .dequeue = ep_dequeue,
  88169. +
  88170. + .set_halt = ep_halt,
  88171. + .fifo_status = 0,
  88172. + .fifo_flush = 0,
  88173. +
  88174. +};
  88175. +
  88176. +#endif /* _EN_ISOC_ */
  88177. +/* Gadget Operations */
  88178. +/**
  88179. + * The following gadget operations will be implemented in the DWC_otg
  88180. + * PCD. Functions in the API that are not described below are not
  88181. + * implemented.
  88182. + *
  88183. + * The Gadget API provides wrapper functions for each of the function
  88184. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  88185. + * wrapper function, which then calls the underlying PCD function. The
  88186. + * following sections are named according to the wrapper functions
  88187. + * (except for ioctl, which doesn't have a wrapper function). Within
  88188. + * each section, the corresponding DWC_otg PCD function name is
  88189. + * specified.
  88190. + *
  88191. + */
  88192. +
  88193. +/**
  88194. + *Gets the USB Frame number of the last SOF.
  88195. + */
  88196. +static int get_frame_number(struct usb_gadget *gadget)
  88197. +{
  88198. + struct gadget_wrapper *d;
  88199. +
  88200. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  88201. +
  88202. + if (gadget == 0) {
  88203. + return -ENODEV;
  88204. + }
  88205. +
  88206. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88207. + return dwc_otg_pcd_get_frame_number(d->pcd);
  88208. +}
  88209. +
  88210. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88211. +static int test_lpm_enabled(struct usb_gadget *gadget)
  88212. +{
  88213. + struct gadget_wrapper *d;
  88214. +
  88215. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88216. +
  88217. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  88218. +}
  88219. +#endif
  88220. +
  88221. +/**
  88222. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  88223. + * session is in progress. If a session is already in progress, but
  88224. + * the device is suspended, remote wakeup signaling is started.
  88225. + *
  88226. + */
  88227. +static int wakeup(struct usb_gadget *gadget)
  88228. +{
  88229. + struct gadget_wrapper *d;
  88230. +
  88231. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  88232. +
  88233. + if (gadget == 0) {
  88234. + return -ENODEV;
  88235. + } else {
  88236. + d = container_of(gadget, struct gadget_wrapper, gadget);
  88237. + }
  88238. + dwc_otg_pcd_wakeup(d->pcd);
  88239. + return 0;
  88240. +}
  88241. +
  88242. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  88243. + .get_frame = get_frame_number,
  88244. + .wakeup = wakeup,
  88245. +#ifdef CONFIG_USB_DWC_OTG_LPM
  88246. + .lpm_support = test_lpm_enabled,
  88247. +#endif
  88248. + // current versions must always be self-powered
  88249. +};
  88250. +
  88251. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  88252. +{
  88253. + int retval = -DWC_E_NOT_SUPPORTED;
  88254. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  88255. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  88256. + (struct usb_ctrlrequest
  88257. + *)bytes);
  88258. + }
  88259. +
  88260. + if (retval == -ENOTSUPP) {
  88261. + retval = -DWC_E_NOT_SUPPORTED;
  88262. + } else if (retval < 0) {
  88263. + retval = -DWC_E_INVALID;
  88264. + }
  88265. +
  88266. + return retval;
  88267. +}
  88268. +
  88269. +#ifdef DWC_EN_ISOC
  88270. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88271. + void *req_handle, int proc_buf_num)
  88272. +{
  88273. + int i, packet_count;
  88274. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  88275. + struct usb_iso_request *iso_req = req_handle;
  88276. +
  88277. + if (proc_buf_num) {
  88278. + iso_packet = iso_req->iso_packet_desc1;
  88279. + } else {
  88280. + iso_packet = iso_req->iso_packet_desc0;
  88281. + }
  88282. + packet_count =
  88283. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  88284. + for (i = 0; i < packet_count; ++i) {
  88285. + int status;
  88286. + int actual;
  88287. + int offset;
  88288. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  88289. + i, &status, &actual, &offset);
  88290. + switch (status) {
  88291. + case -DWC_E_NO_DATA:
  88292. + status = -ENODATA;
  88293. + break;
  88294. + default:
  88295. + if (status) {
  88296. + DWC_PRINTF("unknown status in isoc packet\n");
  88297. + }
  88298. +
  88299. + }
  88300. + iso_packet[i].status = status;
  88301. + iso_packet[i].offset = offset;
  88302. + iso_packet[i].actual_length = actual;
  88303. + }
  88304. +
  88305. + iso_req->status = 0;
  88306. + iso_req->process_buffer(ep_handle, iso_req);
  88307. +
  88308. + return 0;
  88309. +}
  88310. +#endif /* DWC_EN_ISOC */
  88311. +
  88312. +#ifdef DWC_UTE_PER_IO
  88313. +/**
  88314. + * Copy the contents of the extended request to the Linux usb_request's
  88315. + * extended part and call the gadget's completion.
  88316. + *
  88317. + * @param pcd Pointer to the pcd structure
  88318. + * @param ep_handle Void pointer to the usb_ep structure
  88319. + * @param req_handle Void pointer to the usb_request structure
  88320. + * @param status Request status returned from the portable logic
  88321. + * @param ereq_port Void pointer to the extended request structure
  88322. + * created in the the portable part that contains the
  88323. + * results of the processed iso packets.
  88324. + */
  88325. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88326. + void *req_handle, int32_t status, void *ereq_port)
  88327. +{
  88328. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  88329. + struct dwc_iso_xreq_port *ereqport = NULL;
  88330. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  88331. + int i;
  88332. + struct usb_request *req;
  88333. + //struct dwc_ute_iso_packet_descriptor *
  88334. + //int status = 0;
  88335. +
  88336. + req = (struct usb_request *)req_handle;
  88337. + ereqorg = &req->ext_req;
  88338. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  88339. + desc_org = ereqorg->per_io_frame_descs;
  88340. +
  88341. + if (req && req->complete) {
  88342. + /* Copy the request data from the portable logic to our request */
  88343. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  88344. + desc_org[i].actual_length =
  88345. + ereqport->per_io_frame_descs[i].actual_length;
  88346. + desc_org[i].status =
  88347. + ereqport->per_io_frame_descs[i].status;
  88348. + }
  88349. +
  88350. + switch (status) {
  88351. + case -DWC_E_SHUTDOWN:
  88352. + req->status = -ESHUTDOWN;
  88353. + break;
  88354. + case -DWC_E_RESTART:
  88355. + req->status = -ECONNRESET;
  88356. + break;
  88357. + case -DWC_E_INVALID:
  88358. + req->status = -EINVAL;
  88359. + break;
  88360. + case -DWC_E_TIMEOUT:
  88361. + req->status = -ETIMEDOUT;
  88362. + break;
  88363. + default:
  88364. + req->status = status;
  88365. + }
  88366. +
  88367. + /* And call the gadget's completion */
  88368. + req->complete(ep_handle, req);
  88369. + }
  88370. +
  88371. + return 0;
  88372. +}
  88373. +#endif /* DWC_UTE_PER_IO */
  88374. +
  88375. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  88376. + void *req_handle, int32_t status, uint32_t actual)
  88377. +{
  88378. + struct usb_request *req = (struct usb_request *)req_handle;
  88379. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  88380. + struct dwc_otg_pcd_ep *ep = NULL;
  88381. +#endif
  88382. +
  88383. + if (req && req->complete) {
  88384. + switch (status) {
  88385. + case -DWC_E_SHUTDOWN:
  88386. + req->status = -ESHUTDOWN;
  88387. + break;
  88388. + case -DWC_E_RESTART:
  88389. + req->status = -ECONNRESET;
  88390. + break;
  88391. + case -DWC_E_INVALID:
  88392. + req->status = -EINVAL;
  88393. + break;
  88394. + case -DWC_E_TIMEOUT:
  88395. + req->status = -ETIMEDOUT;
  88396. + break;
  88397. + default:
  88398. + req->status = status;
  88399. +
  88400. + }
  88401. +
  88402. + req->actual = actual;
  88403. + DWC_SPINUNLOCK(pcd->lock);
  88404. + req->complete(ep_handle, req);
  88405. + DWC_SPINLOCK(pcd->lock);
  88406. + }
  88407. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  88408. + ep = ep_from_handle(pcd, ep_handle);
  88409. + if (GET_CORE_IF(pcd)->dma_enable) {
  88410. + if (req->length != 0) {
  88411. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  88412. + struct device *dev = NULL;
  88413. +
  88414. + if (otg_dev != NULL)
  88415. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  88416. +
  88417. + dma_unmap_single(dev, req->dma, req->length,
  88418. + ep->dwc_ep.is_in ?
  88419. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  88420. + }
  88421. + }
  88422. +#endif
  88423. +
  88424. + return 0;
  88425. +}
  88426. +
  88427. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  88428. +{
  88429. + gadget_wrapper->gadget.speed = speed;
  88430. + return 0;
  88431. +}
  88432. +
  88433. +static int _disconnect(dwc_otg_pcd_t * pcd)
  88434. +{
  88435. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  88436. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  88437. + }
  88438. + return 0;
  88439. +}
  88440. +
  88441. +static int _resume(dwc_otg_pcd_t * pcd)
  88442. +{
  88443. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  88444. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  88445. + }
  88446. +
  88447. + return 0;
  88448. +}
  88449. +
  88450. +static int _suspend(dwc_otg_pcd_t * pcd)
  88451. +{
  88452. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  88453. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  88454. + }
  88455. + return 0;
  88456. +}
  88457. +
  88458. +/**
  88459. + * This function updates the otg values in the gadget structure.
  88460. + */
  88461. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  88462. +{
  88463. +
  88464. + if (!gadget_wrapper->gadget.is_otg)
  88465. + return 0;
  88466. +
  88467. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  88468. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  88469. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  88470. + return 0;
  88471. +}
  88472. +
  88473. +static int _reset(dwc_otg_pcd_t * pcd)
  88474. +{
  88475. + return 0;
  88476. +}
  88477. +
  88478. +#ifdef DWC_UTE_CFI
  88479. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  88480. +{
  88481. + int retval = -DWC_E_INVALID;
  88482. + if (gadget_wrapper->driver->cfi_feature_setup) {
  88483. + retval =
  88484. + gadget_wrapper->driver->
  88485. + cfi_feature_setup(&gadget_wrapper->gadget,
  88486. + (struct cfi_usb_ctrlrequest *)cfi_req);
  88487. + }
  88488. +
  88489. + return retval;
  88490. +}
  88491. +#endif
  88492. +
  88493. +static const struct dwc_otg_pcd_function_ops fops = {
  88494. + .complete = _complete,
  88495. +#ifdef DWC_EN_ISOC
  88496. + .isoc_complete = _isoc_complete,
  88497. +#endif
  88498. + .setup = _setup,
  88499. + .disconnect = _disconnect,
  88500. + .connect = _connect,
  88501. + .resume = _resume,
  88502. + .suspend = _suspend,
  88503. + .hnp_changed = _hnp_changed,
  88504. + .reset = _reset,
  88505. +#ifdef DWC_UTE_CFI
  88506. + .cfi_setup = _cfi_setup,
  88507. +#endif
  88508. +#ifdef DWC_UTE_PER_IO
  88509. + .xisoc_complete = _xisoc_complete,
  88510. +#endif
  88511. +};
  88512. +
  88513. +/**
  88514. + * This function is the top level PCD interrupt handler.
  88515. + */
  88516. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  88517. +{
  88518. + dwc_otg_pcd_t *pcd = dev;
  88519. + int32_t retval = IRQ_NONE;
  88520. +
  88521. + retval = dwc_otg_pcd_handle_intr(pcd);
  88522. + if (retval != 0) {
  88523. + S3C2410X_CLEAR_EINTPEND();
  88524. + }
  88525. + return IRQ_RETVAL(retval);
  88526. +}
  88527. +
  88528. +/**
  88529. + * This function initialized the usb_ep structures to there default
  88530. + * state.
  88531. + *
  88532. + * @param d Pointer on gadget_wrapper.
  88533. + */
  88534. +void gadget_add_eps(struct gadget_wrapper *d)
  88535. +{
  88536. + static const char *names[] = {
  88537. +
  88538. + "ep0",
  88539. + "ep1in",
  88540. + "ep2in",
  88541. + "ep3in",
  88542. + "ep4in",
  88543. + "ep5in",
  88544. + "ep6in",
  88545. + "ep7in",
  88546. + "ep8in",
  88547. + "ep9in",
  88548. + "ep10in",
  88549. + "ep11in",
  88550. + "ep12in",
  88551. + "ep13in",
  88552. + "ep14in",
  88553. + "ep15in",
  88554. + "ep1out",
  88555. + "ep2out",
  88556. + "ep3out",
  88557. + "ep4out",
  88558. + "ep5out",
  88559. + "ep6out",
  88560. + "ep7out",
  88561. + "ep8out",
  88562. + "ep9out",
  88563. + "ep10out",
  88564. + "ep11out",
  88565. + "ep12out",
  88566. + "ep13out",
  88567. + "ep14out",
  88568. + "ep15out"
  88569. + };
  88570. +
  88571. + int i;
  88572. + struct usb_ep *ep;
  88573. + int8_t dev_endpoints;
  88574. +
  88575. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  88576. +
  88577. + INIT_LIST_HEAD(&d->gadget.ep_list);
  88578. + d->gadget.ep0 = &d->ep0;
  88579. + d->gadget.speed = USB_SPEED_UNKNOWN;
  88580. +
  88581. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  88582. +
  88583. + /**
  88584. + * Initialize the EP0 structure.
  88585. + */
  88586. + ep = &d->ep0;
  88587. +
  88588. + /* Init the usb_ep structure. */
  88589. + ep->name = names[0];
  88590. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  88591. +
  88592. + /**
  88593. + * @todo NGS: What should the max packet size be set to
  88594. + * here? Before EP type is set?
  88595. + */
  88596. + ep->maxpacket = MAX_PACKET_SIZE;
  88597. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  88598. +
  88599. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  88600. +
  88601. + /**
  88602. + * Initialize the EP structures.
  88603. + */
  88604. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  88605. +
  88606. + for (i = 0; i < dev_endpoints; i++) {
  88607. + ep = &d->in_ep[i];
  88608. +
  88609. + /* Init the usb_ep structure. */
  88610. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  88611. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  88612. +
  88613. + /**
  88614. + * @todo NGS: What should the max packet size be set to
  88615. + * here? Before EP type is set?
  88616. + */
  88617. + ep->maxpacket = MAX_PACKET_SIZE;
  88618. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  88619. + }
  88620. +
  88621. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  88622. +
  88623. + for (i = 0; i < dev_endpoints; i++) {
  88624. + ep = &d->out_ep[i];
  88625. +
  88626. + /* Init the usb_ep structure. */
  88627. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  88628. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  88629. +
  88630. + /**
  88631. + * @todo NGS: What should the max packet size be set to
  88632. + * here? Before EP type is set?
  88633. + */
  88634. + ep->maxpacket = MAX_PACKET_SIZE;
  88635. +
  88636. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  88637. + }
  88638. +
  88639. + /* remove ep0 from the list. There is a ep0 pointer. */
  88640. + list_del_init(&d->ep0.ep_list);
  88641. +
  88642. + d->ep0.maxpacket = MAX_EP0_SIZE;
  88643. +}
  88644. +
  88645. +/**
  88646. + * This function releases the Gadget device.
  88647. + * required by device_unregister().
  88648. + *
  88649. + * @todo Should this do something? Should it free the PCD?
  88650. + */
  88651. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  88652. +{
  88653. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  88654. +}
  88655. +
  88656. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  88657. +{
  88658. + static char pcd_name[] = "dwc_otg_pcd";
  88659. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  88660. + struct gadget_wrapper *d;
  88661. + int retval;
  88662. +
  88663. + d = DWC_ALLOC(sizeof(*d));
  88664. + if (d == NULL) {
  88665. + return NULL;
  88666. + }
  88667. +
  88668. + memset(d, 0, sizeof(*d));
  88669. +
  88670. + d->gadget.name = pcd_name;
  88671. + d->pcd = otg_dev->pcd;
  88672. +
  88673. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  88674. + strcpy(d->gadget.dev.bus_id, "gadget");
  88675. +#else
  88676. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  88677. +#endif
  88678. +
  88679. + d->gadget.dev.parent = &_dev->dev;
  88680. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  88681. + d->gadget.ops = &dwc_otg_pcd_ops;
  88682. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  88683. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  88684. +
  88685. + d->driver = 0;
  88686. + /* Register the gadget device */
  88687. + retval = device_register(&d->gadget.dev);
  88688. + if (retval != 0) {
  88689. + DWC_ERROR("device_register failed\n");
  88690. + DWC_FREE(d);
  88691. + return NULL;
  88692. + }
  88693. +
  88694. + return d;
  88695. +}
  88696. +
  88697. +static void free_wrapper(struct gadget_wrapper *d)
  88698. +{
  88699. + if (d->driver) {
  88700. + /* should have been done already by driver model core */
  88701. + DWC_WARN("driver '%s' is still registered\n",
  88702. + d->driver->driver.name);
  88703. + usb_gadget_unregister_driver(d->driver);
  88704. + }
  88705. +
  88706. + device_unregister(&d->gadget.dev);
  88707. + DWC_FREE(d);
  88708. +}
  88709. +
  88710. +/**
  88711. + * This function initialized the PCD portion of the driver.
  88712. + *
  88713. + */
  88714. +int pcd_init(dwc_bus_dev_t *_dev)
  88715. +{
  88716. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  88717. + int retval = 0;
  88718. +
  88719. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  88720. +
  88721. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  88722. +
  88723. + if (!otg_dev->pcd) {
  88724. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  88725. + return -ENOMEM;
  88726. + }
  88727. +
  88728. + otg_dev->pcd->otg_dev = otg_dev;
  88729. + gadget_wrapper = alloc_wrapper(_dev);
  88730. +
  88731. + /*
  88732. + * Initialize EP structures
  88733. + */
  88734. + gadget_add_eps(gadget_wrapper);
  88735. + /*
  88736. + * Setup interupt handler
  88737. + */
  88738. +#ifdef PLATFORM_INTERFACE
  88739. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  88740. + platform_get_irq(_dev, 0));
  88741. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  88742. + IRQF_SHARED, gadget_wrapper->gadget.name,
  88743. + otg_dev->pcd);
  88744. + if (retval != 0) {
  88745. + DWC_ERROR("request of irq%d failed\n",
  88746. + platform_get_irq(_dev, 0));
  88747. + free_wrapper(gadget_wrapper);
  88748. + return -EBUSY;
  88749. + }
  88750. +#else
  88751. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  88752. + _dev->irq);
  88753. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  88754. + IRQF_SHARED | IRQF_DISABLED,
  88755. + gadget_wrapper->gadget.name, otg_dev->pcd);
  88756. + if (retval != 0) {
  88757. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  88758. + free_wrapper(gadget_wrapper);
  88759. + return -EBUSY;
  88760. + }
  88761. +#endif
  88762. +
  88763. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  88764. +
  88765. + return retval;
  88766. +}
  88767. +
  88768. +/**
  88769. + * Cleanup the PCD.
  88770. + */
  88771. +void pcd_remove(dwc_bus_dev_t *_dev)
  88772. +{
  88773. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  88774. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  88775. +
  88776. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  88777. +
  88778. + /*
  88779. + * Free the IRQ
  88780. + */
  88781. +#ifdef PLATFORM_INTERFACE
  88782. + free_irq(platform_get_irq(_dev, 0), pcd);
  88783. +#else
  88784. + free_irq(_dev->irq, pcd);
  88785. +#endif
  88786. + dwc_otg_pcd_remove(otg_dev->pcd);
  88787. + free_wrapper(gadget_wrapper);
  88788. + otg_dev->pcd = 0;
  88789. +}
  88790. +
  88791. +/**
  88792. + * This function registers a gadget driver with the PCD.
  88793. + *
  88794. + * When a driver is successfully registered, it will receive control
  88795. + * requests including set_configuration(), which enables non-control
  88796. + * requests. then usb traffic follows until a disconnect is reported.
  88797. + * then a host may connect again, or the driver might get unbound.
  88798. + *
  88799. + * @param driver The driver being registered
  88800. + * @param bind The bind function of gadget driver
  88801. + */
  88802. +
  88803. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  88804. +{
  88805. + int retval;
  88806. +
  88807. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  88808. + driver->driver.name);
  88809. +
  88810. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  88811. + !driver->bind ||
  88812. + !driver->unbind || !driver->disconnect || !driver->setup) {
  88813. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  88814. + return -EINVAL;
  88815. + }
  88816. + if (gadget_wrapper == 0) {
  88817. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  88818. + return -ENODEV;
  88819. + }
  88820. + if (gadget_wrapper->driver != 0) {
  88821. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  88822. + return -EBUSY;
  88823. + }
  88824. +
  88825. + /* hook up the driver */
  88826. + gadget_wrapper->driver = driver;
  88827. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  88828. +
  88829. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  88830. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  88831. + if (retval) {
  88832. + DWC_ERROR("bind to driver %s --> error %d\n",
  88833. + driver->driver.name, retval);
  88834. + gadget_wrapper->driver = 0;
  88835. + gadget_wrapper->gadget.dev.driver = 0;
  88836. + return retval;
  88837. + }
  88838. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  88839. + driver->driver.name);
  88840. + return 0;
  88841. +}
  88842. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  88843. +
  88844. +/**
  88845. + * This function unregisters a gadget driver
  88846. + *
  88847. + * @param driver The driver being unregistered
  88848. + */
  88849. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  88850. +{
  88851. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  88852. +
  88853. + if (gadget_wrapper == 0) {
  88854. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  88855. + -ENODEV);
  88856. + return -ENODEV;
  88857. + }
  88858. + if (driver == 0 || driver != gadget_wrapper->driver) {
  88859. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  88860. + -EINVAL);
  88861. + return -EINVAL;
  88862. + }
  88863. +
  88864. + driver->unbind(&gadget_wrapper->gadget);
  88865. + gadget_wrapper->driver = 0;
  88866. +
  88867. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  88868. + return 0;
  88869. +}
  88870. +
  88871. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  88872. +
  88873. +#endif /* DWC_HOST_ONLY */
  88874. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  88875. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  88876. +++ linux-3.11.10/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-02-07 19:57:30.000000000 +0100
  88877. @@ -0,0 +1,2550 @@
  88878. +/* ==========================================================================
  88879. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  88880. + * $Revision: #98 $
  88881. + * $Date: 2012/08/10 $
  88882. + * $Change: 2047372 $
  88883. + *
  88884. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  88885. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  88886. + * otherwise expressly agreed to in writing between Synopsys and you.
  88887. + *
  88888. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  88889. + * any End User Software License Agreement or Agreement for Licensed Product
  88890. + * with Synopsys or any supplement thereto. You are permitted to use and
  88891. + * redistribute this Software in source and binary forms, with or without
  88892. + * modification, provided that redistributions of source code must retain this
  88893. + * notice. You may not view, use, disclose, copy or distribute this file or
  88894. + * any information contained herein except pursuant to this license grant from
  88895. + * Synopsys. If you do not agree with this notice, including the disclaimer
  88896. + * below, then you are not authorized to use the Software.
  88897. + *
  88898. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  88899. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  88900. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  88901. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  88902. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  88903. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  88904. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  88905. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  88906. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  88907. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  88908. + * DAMAGE.
  88909. + * ========================================================================== */
  88910. +
  88911. +#ifndef __DWC_OTG_REGS_H__
  88912. +#define __DWC_OTG_REGS_H__
  88913. +
  88914. +#include "dwc_otg_core_if.h"
  88915. +
  88916. +/**
  88917. + * @file
  88918. + *
  88919. + * This file contains the data structures for accessing the DWC_otg core registers.
  88920. + *
  88921. + * The application interfaces with the HS OTG core by reading from and
  88922. + * writing to the Control and Status Register (CSR) space through the
  88923. + * AHB Slave interface. These registers are 32 bits wide, and the
  88924. + * addresses are 32-bit-block aligned.
  88925. + * CSRs are classified as follows:
  88926. + * - Core Global Registers
  88927. + * - Device Mode Registers
  88928. + * - Device Global Registers
  88929. + * - Device Endpoint Specific Registers
  88930. + * - Host Mode Registers
  88931. + * - Host Global Registers
  88932. + * - Host Port CSRs
  88933. + * - Host Channel Specific Registers
  88934. + *
  88935. + * Only the Core Global registers can be accessed in both Device and
  88936. + * Host modes. When the HS OTG core is operating in one mode, either
  88937. + * Device or Host, the application must not access registers from the
  88938. + * other mode. When the core switches from one mode to another, the
  88939. + * registers in the new mode of operation must be reprogrammed as they
  88940. + * would be after a power-on reset.
  88941. + */
  88942. +
  88943. +/****************************************************************************/
  88944. +/** DWC_otg Core registers .
  88945. + * The dwc_otg_core_global_regs structure defines the size
  88946. + * and relative field offsets for the Core Global registers.
  88947. + */
  88948. +typedef struct dwc_otg_core_global_regs {
  88949. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  88950. + volatile uint32_t gotgctl;
  88951. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  88952. + volatile uint32_t gotgint;
  88953. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  88954. + volatile uint32_t gahbcfg;
  88955. +
  88956. +#define DWC_GLBINTRMASK 0x0001
  88957. +#define DWC_DMAENABLE 0x0020
  88958. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  88959. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  88960. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  88961. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  88962. +
  88963. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  88964. + volatile uint32_t gusbcfg;
  88965. + /**Core Reset Register. <i>Offset: 010h</i> */
  88966. + volatile uint32_t grstctl;
  88967. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  88968. + volatile uint32_t gintsts;
  88969. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  88970. + volatile uint32_t gintmsk;
  88971. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  88972. + volatile uint32_t grxstsr;
  88973. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  88974. + volatile uint32_t grxstsp;
  88975. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  88976. + volatile uint32_t grxfsiz;
  88977. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  88978. + volatile uint32_t gnptxfsiz;
  88979. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  88980. + * Only). <i>Offset: 02Ch</i> */
  88981. + volatile uint32_t gnptxsts;
  88982. + /**I2C Access Register. <i>Offset: 030h</i> */
  88983. + volatile uint32_t gi2cctl;
  88984. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  88985. + volatile uint32_t gpvndctl;
  88986. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  88987. + volatile uint32_t ggpio;
  88988. + /**User ID Register. <i>Offset: 03Ch</i> */
  88989. + volatile uint32_t guid;
  88990. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  88991. + volatile uint32_t gsnpsid;
  88992. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  88993. + volatile uint32_t ghwcfg1;
  88994. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  88995. + volatile uint32_t ghwcfg2;
  88996. +#define DWC_SLAVE_ONLY_ARCH 0
  88997. +#define DWC_EXT_DMA_ARCH 1
  88998. +#define DWC_INT_DMA_ARCH 2
  88999. +
  89000. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  89001. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  89002. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  89003. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  89004. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  89005. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  89006. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  89007. +
  89008. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  89009. + volatile uint32_t ghwcfg3;
  89010. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  89011. + volatile uint32_t ghwcfg4;
  89012. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  89013. + volatile uint32_t glpmcfg;
  89014. + /** Global PowerDn Register <i>Offset: 058h</i> */
  89015. + volatile uint32_t gpwrdn;
  89016. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  89017. + volatile uint32_t gdfifocfg;
  89018. + /** ADP Control Register <i>Offset: 060h</i> */
  89019. + volatile uint32_t adpctl;
  89020. + /** Reserved <i>Offset: 064h-0FFh</i> */
  89021. + volatile uint32_t reserved39[39];
  89022. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  89023. + volatile uint32_t hptxfsiz;
  89024. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  89025. + otherwise Device Transmit FIFO#n Register.
  89026. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  89027. + volatile uint32_t dtxfsiz[15];
  89028. +} dwc_otg_core_global_regs_t;
  89029. +
  89030. +/**
  89031. + * This union represents the bit fields of the Core OTG Control
  89032. + * and Status Register (GOTGCTL). Set the bits using the bit
  89033. + * fields then write the <i>d32</i> value to the register.
  89034. + */
  89035. +typedef union gotgctl_data {
  89036. + /** raw register data */
  89037. + uint32_t d32;
  89038. + /** register bits */
  89039. + struct {
  89040. + unsigned sesreqscs:1;
  89041. + unsigned sesreq:1;
  89042. + unsigned vbvalidoven:1;
  89043. + unsigned vbvalidovval:1;
  89044. + unsigned avalidoven:1;
  89045. + unsigned avalidovval:1;
  89046. + unsigned bvalidoven:1;
  89047. + unsigned bvalidovval:1;
  89048. + unsigned hstnegscs:1;
  89049. + unsigned hnpreq:1;
  89050. + unsigned hstsethnpen:1;
  89051. + unsigned devhnpen:1;
  89052. + unsigned reserved12_15:4;
  89053. + unsigned conidsts:1;
  89054. + unsigned dbnctime:1;
  89055. + unsigned asesvld:1;
  89056. + unsigned bsesvld:1;
  89057. + unsigned otgver:1;
  89058. + unsigned reserved1:1;
  89059. + unsigned multvalidbc:5;
  89060. + unsigned chirpen:1;
  89061. + unsigned reserved28_31:4;
  89062. + } b;
  89063. +} gotgctl_data_t;
  89064. +
  89065. +/**
  89066. + * This union represents the bit fields of the Core OTG Interrupt Register
  89067. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  89068. + * value to the register.
  89069. + */
  89070. +typedef union gotgint_data {
  89071. + /** raw register data */
  89072. + uint32_t d32;
  89073. + /** register bits */
  89074. + struct {
  89075. + /** Current Mode */
  89076. + unsigned reserved0_1:2;
  89077. +
  89078. + /** Session End Detected */
  89079. + unsigned sesenddet:1;
  89080. +
  89081. + unsigned reserved3_7:5;
  89082. +
  89083. + /** Session Request Success Status Change */
  89084. + unsigned sesreqsucstschng:1;
  89085. + /** Host Negotiation Success Status Change */
  89086. + unsigned hstnegsucstschng:1;
  89087. +
  89088. + unsigned reserved10_16:7;
  89089. +
  89090. + /** Host Negotiation Detected */
  89091. + unsigned hstnegdet:1;
  89092. + /** A-Device Timeout Change */
  89093. + unsigned adevtoutchng:1;
  89094. + /** Debounce Done */
  89095. + unsigned debdone:1;
  89096. + /** Multi-Valued input changed */
  89097. + unsigned mvic:1;
  89098. +
  89099. + unsigned reserved31_21:11;
  89100. +
  89101. + } b;
  89102. +} gotgint_data_t;
  89103. +
  89104. +/**
  89105. + * This union represents the bit fields of the Core AHB Configuration
  89106. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  89107. + * write the <i>d32</i> value to the register.
  89108. + */
  89109. +typedef union gahbcfg_data {
  89110. + /** raw register data */
  89111. + uint32_t d32;
  89112. + /** register bits */
  89113. + struct {
  89114. + unsigned glblintrmsk:1;
  89115. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  89116. +
  89117. + unsigned hburstlen:4;
  89118. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  89119. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  89120. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  89121. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  89122. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  89123. +
  89124. + unsigned dmaenable:1;
  89125. +#define DWC_GAHBCFG_DMAENABLE 1
  89126. + unsigned reserved:1;
  89127. + unsigned nptxfemplvl_txfemplvl:1;
  89128. + unsigned ptxfemplvl:1;
  89129. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  89130. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  89131. + unsigned reserved9_20:12;
  89132. + unsigned remmemsupp:1;
  89133. + unsigned notialldmawrit:1;
  89134. + unsigned ahbsingle:1;
  89135. + unsigned reserved24_31:8;
  89136. + } b;
  89137. +} gahbcfg_data_t;
  89138. +
  89139. +/**
  89140. + * This union represents the bit fields of the Core USB Configuration
  89141. + * Register (GUSBCFG). Set the bits using the bit fields then write
  89142. + * the <i>d32</i> value to the register.
  89143. + */
  89144. +typedef union gusbcfg_data {
  89145. + /** raw register data */
  89146. + uint32_t d32;
  89147. + /** register bits */
  89148. + struct {
  89149. + unsigned toutcal:3;
  89150. + unsigned phyif:1;
  89151. + unsigned ulpi_utmi_sel:1;
  89152. + unsigned fsintf:1;
  89153. + unsigned physel:1;
  89154. + unsigned ddrsel:1;
  89155. + unsigned srpcap:1;
  89156. + unsigned hnpcap:1;
  89157. + unsigned usbtrdtim:4;
  89158. + unsigned reserved1:1;
  89159. + unsigned phylpwrclksel:1;
  89160. + unsigned otgutmifssel:1;
  89161. + unsigned ulpi_fsls:1;
  89162. + unsigned ulpi_auto_res:1;
  89163. + unsigned ulpi_clk_sus_m:1;
  89164. + unsigned ulpi_ext_vbus_drv:1;
  89165. + unsigned ulpi_int_vbus_indicator:1;
  89166. + unsigned term_sel_dl_pulse:1;
  89167. + unsigned indicator_complement:1;
  89168. + unsigned indicator_pass_through:1;
  89169. + unsigned ulpi_int_prot_dis:1;
  89170. + unsigned ic_usb_cap:1;
  89171. + unsigned ic_traffic_pull_remove:1;
  89172. + unsigned tx_end_delay:1;
  89173. + unsigned force_host_mode:1;
  89174. + unsigned force_dev_mode:1;
  89175. + unsigned reserved31:1;
  89176. + } b;
  89177. +} gusbcfg_data_t;
  89178. +
  89179. +/**
  89180. + * This union represents the bit fields of the Core Reset Register
  89181. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  89182. + * <i>d32</i> value to the register.
  89183. + */
  89184. +typedef union grstctl_data {
  89185. + /** raw register data */
  89186. + uint32_t d32;
  89187. + /** register bits */
  89188. + struct {
  89189. + /** Core Soft Reset (CSftRst) (Device and Host)
  89190. + *
  89191. + * The application can flush the control logic in the
  89192. + * entire core using this bit. This bit resets the
  89193. + * pipelines in the AHB Clock domain as well as the
  89194. + * PHY Clock domain.
  89195. + *
  89196. + * The state machines are reset to an IDLE state, the
  89197. + * control bits in the CSRs are cleared, all the
  89198. + * transmit FIFOs and the receive FIFO are flushed.
  89199. + *
  89200. + * The status mask bits that control the generation of
  89201. + * the interrupt, are cleared, to clear the
  89202. + * interrupt. The interrupt status bits are not
  89203. + * cleared, so the application can get the status of
  89204. + * any events that occurred in the core after it has
  89205. + * set this bit.
  89206. + *
  89207. + * Any transactions on the AHB are terminated as soon
  89208. + * as possible following the protocol. Any
  89209. + * transactions on the USB are terminated immediately.
  89210. + *
  89211. + * The configuration settings in the CSRs are
  89212. + * unchanged, so the software doesn't have to
  89213. + * reprogram these registers (Device
  89214. + * Configuration/Host Configuration/Core System
  89215. + * Configuration/Core PHY Configuration).
  89216. + *
  89217. + * The application can write to this bit, any time it
  89218. + * wants to reset the core. This is a self clearing
  89219. + * bit and the core clears this bit after all the
  89220. + * necessary logic is reset in the core, which may
  89221. + * take several clocks, depending on the current state
  89222. + * of the core.
  89223. + */
  89224. + unsigned csftrst:1;
  89225. + /** Hclk Soft Reset
  89226. + *
  89227. + * The application uses this bit to reset the control logic in
  89228. + * the AHB clock domain. Only AHB clock domain pipelines are
  89229. + * reset.
  89230. + */
  89231. + unsigned hsftrst:1;
  89232. + /** Host Frame Counter Reset (Host Only)<br>
  89233. + *
  89234. + * The application can reset the (micro)frame number
  89235. + * counter inside the core, using this bit. When the
  89236. + * (micro)frame counter is reset, the subsequent SOF
  89237. + * sent out by the core, will have a (micro)frame
  89238. + * number of 0.
  89239. + */
  89240. + unsigned hstfrm:1;
  89241. + /** In Token Sequence Learning Queue Flush
  89242. + * (INTknQFlsh) (Device Only)
  89243. + */
  89244. + unsigned intknqflsh:1;
  89245. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  89246. + *
  89247. + * The application can flush the entire Receive FIFO
  89248. + * using this bit. The application must first
  89249. + * ensure that the core is not in the middle of a
  89250. + * transaction. The application should write into
  89251. + * this bit, only after making sure that neither the
  89252. + * DMA engine is reading from the RxFIFO nor the MAC
  89253. + * is writing the data in to the FIFO. The
  89254. + * application should wait until the bit is cleared
  89255. + * before performing any other operations. This bit
  89256. + * will takes 8 clocks (slowest of PHY or AHB clock)
  89257. + * to clear.
  89258. + */
  89259. + unsigned rxfflsh:1;
  89260. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  89261. + *
  89262. + * This bit is used to selectively flush a single or
  89263. + * all transmit FIFOs. The application must first
  89264. + * ensure that the core is not in the middle of a
  89265. + * transaction. The application should write into
  89266. + * this bit, only after making sure that neither the
  89267. + * DMA engine is writing into the TxFIFO nor the MAC
  89268. + * is reading the data out of the FIFO. The
  89269. + * application should wait until the core clears this
  89270. + * bit, before performing any operations. This bit
  89271. + * will takes 8 clocks (slowest of PHY or AHB clock)
  89272. + * to clear.
  89273. + */
  89274. + unsigned txfflsh:1;
  89275. +
  89276. + /** TxFIFO Number (TxFNum) (Device and Host).
  89277. + *
  89278. + * This is the FIFO number which needs to be flushed,
  89279. + * using the TxFIFO Flush bit. This field should not
  89280. + * be changed until the TxFIFO Flush bit is cleared by
  89281. + * the core.
  89282. + * - 0x0 : Non Periodic TxFIFO Flush
  89283. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  89284. + * or Periodic TxFIFO in host mode
  89285. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  89286. + * - ...
  89287. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  89288. + * - 0x10: Flush all the Transmit NonPeriodic and
  89289. + * Transmit Periodic FIFOs in the core
  89290. + */
  89291. + unsigned txfnum:5;
  89292. + /** Reserved */
  89293. + unsigned reserved11_29:19;
  89294. + /** DMA Request Signal. Indicated DMA request is in
  89295. + * probress. Used for debug purpose. */
  89296. + unsigned dmareq:1;
  89297. + /** AHB Master Idle. Indicates the AHB Master State
  89298. + * Machine is in IDLE condition. */
  89299. + unsigned ahbidle:1;
  89300. + } b;
  89301. +} grstctl_t;
  89302. +
  89303. +/**
  89304. + * This union represents the bit fields of the Core Interrupt Mask
  89305. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  89306. + * write the <i>d32</i> value to the register.
  89307. + */
  89308. +typedef union gintmsk_data {
  89309. + /** raw register data */
  89310. + uint32_t d32;
  89311. + /** register bits */
  89312. + struct {
  89313. + unsigned reserved0:1;
  89314. + unsigned modemismatch:1;
  89315. + unsigned otgintr:1;
  89316. + unsigned sofintr:1;
  89317. + unsigned rxstsqlvl:1;
  89318. + unsigned nptxfempty:1;
  89319. + unsigned ginnakeff:1;
  89320. + unsigned goutnakeff:1;
  89321. + unsigned ulpickint:1;
  89322. + unsigned i2cintr:1;
  89323. + unsigned erlysuspend:1;
  89324. + unsigned usbsuspend:1;
  89325. + unsigned usbreset:1;
  89326. + unsigned enumdone:1;
  89327. + unsigned isooutdrop:1;
  89328. + unsigned eopframe:1;
  89329. + unsigned restoredone:1;
  89330. + unsigned epmismatch:1;
  89331. + unsigned inepintr:1;
  89332. + unsigned outepintr:1;
  89333. + unsigned incomplisoin:1;
  89334. + unsigned incomplisoout:1;
  89335. + unsigned fetsusp:1;
  89336. + unsigned resetdet:1;
  89337. + unsigned portintr:1;
  89338. + unsigned hcintr:1;
  89339. + unsigned ptxfempty:1;
  89340. + unsigned lpmtranrcvd:1;
  89341. + unsigned conidstschng:1;
  89342. + unsigned disconnect:1;
  89343. + unsigned sessreqintr:1;
  89344. + unsigned wkupintr:1;
  89345. + } b;
  89346. +} gintmsk_data_t;
  89347. +/**
  89348. + * This union represents the bit fields of the Core Interrupt Register
  89349. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  89350. + * <i>d32</i> value to the register.
  89351. + */
  89352. +typedef union gintsts_data {
  89353. + /** raw register data */
  89354. + uint32_t d32;
  89355. +#define DWC_SOF_INTR_MASK 0x0008
  89356. + /** register bits */
  89357. + struct {
  89358. +#define DWC_HOST_MODE 1
  89359. + unsigned curmode:1;
  89360. + unsigned modemismatch:1;
  89361. + unsigned otgintr:1;
  89362. + unsigned sofintr:1;
  89363. + unsigned rxstsqlvl:1;
  89364. + unsigned nptxfempty:1;
  89365. + unsigned ginnakeff:1;
  89366. + unsigned goutnakeff:1;
  89367. + unsigned ulpickint:1;
  89368. + unsigned i2cintr:1;
  89369. + unsigned erlysuspend:1;
  89370. + unsigned usbsuspend:1;
  89371. + unsigned usbreset:1;
  89372. + unsigned enumdone:1;
  89373. + unsigned isooutdrop:1;
  89374. + unsigned eopframe:1;
  89375. + unsigned restoredone:1;
  89376. + unsigned epmismatch:1;
  89377. + unsigned inepint:1;
  89378. + unsigned outepintr:1;
  89379. + unsigned incomplisoin:1;
  89380. + unsigned incomplisoout:1;
  89381. + unsigned fetsusp:1;
  89382. + unsigned resetdet:1;
  89383. + unsigned portintr:1;
  89384. + unsigned hcintr:1;
  89385. + unsigned ptxfempty:1;
  89386. + unsigned lpmtranrcvd:1;
  89387. + unsigned conidstschng:1;
  89388. + unsigned disconnect:1;
  89389. + unsigned sessreqintr:1;
  89390. + unsigned wkupintr:1;
  89391. + } b;
  89392. +} gintsts_data_t;
  89393. +
  89394. +/**
  89395. + * This union represents the bit fields in the Device Receive Status Read and
  89396. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  89397. + * element then read out the bits using the <i>b</i>it elements.
  89398. + */
  89399. +typedef union device_grxsts_data {
  89400. + /** raw register data */
  89401. + uint32_t d32;
  89402. + /** register bits */
  89403. + struct {
  89404. + unsigned epnum:4;
  89405. + unsigned bcnt:11;
  89406. + unsigned dpid:2;
  89407. +
  89408. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  89409. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  89410. +
  89411. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  89412. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  89413. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  89414. + unsigned pktsts:4;
  89415. + unsigned fn:4;
  89416. + unsigned reserved25_31:7;
  89417. + } b;
  89418. +} device_grxsts_data_t;
  89419. +
  89420. +/**
  89421. + * This union represents the bit fields in the Host Receive Status Read and
  89422. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  89423. + * element then read out the bits using the <i>b</i>it elements.
  89424. + */
  89425. +typedef union host_grxsts_data {
  89426. + /** raw register data */
  89427. + uint32_t d32;
  89428. + /** register bits */
  89429. + struct {
  89430. + unsigned chnum:4;
  89431. + unsigned bcnt:11;
  89432. + unsigned dpid:2;
  89433. +
  89434. + unsigned pktsts:4;
  89435. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  89436. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  89437. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  89438. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  89439. +
  89440. + unsigned reserved21_31:11;
  89441. + } b;
  89442. +} host_grxsts_data_t;
  89443. +
  89444. +/**
  89445. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  89446. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  89447. + * then read out the bits using the <i>b</i>it elements.
  89448. + */
  89449. +typedef union fifosize_data {
  89450. + /** raw register data */
  89451. + uint32_t d32;
  89452. + /** register bits */
  89453. + struct {
  89454. + unsigned startaddr:16;
  89455. + unsigned depth:16;
  89456. + } b;
  89457. +} fifosize_data_t;
  89458. +
  89459. +/**
  89460. + * This union represents the bit fields in the Non-Periodic Transmit
  89461. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  89462. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  89463. + * elements.
  89464. + */
  89465. +typedef union gnptxsts_data {
  89466. + /** raw register data */
  89467. + uint32_t d32;
  89468. + /** register bits */
  89469. + struct {
  89470. + unsigned nptxfspcavail:16;
  89471. + unsigned nptxqspcavail:8;
  89472. + /** Top of the Non-Periodic Transmit Request Queue
  89473. + * - bit 24 - Terminate (Last entry for the selected
  89474. + * channel/EP)
  89475. + * - bits 26:25 - Token Type
  89476. + * - 2'b00 - IN/OUT
  89477. + * - 2'b01 - Zero Length OUT
  89478. + * - 2'b10 - PING/Complete Split
  89479. + * - 2'b11 - Channel Halt
  89480. + * - bits 30:27 - Channel/EP Number
  89481. + */
  89482. + unsigned nptxqtop_terminate:1;
  89483. + unsigned nptxqtop_token:2;
  89484. + unsigned nptxqtop_chnep:4;
  89485. + unsigned reserved:1;
  89486. + } b;
  89487. +} gnptxsts_data_t;
  89488. +
  89489. +/**
  89490. + * This union represents the bit fields in the Transmit
  89491. + * FIFO Status Register (DTXFSTS). Read the register into the
  89492. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  89493. + * elements.
  89494. + */
  89495. +typedef union dtxfsts_data {
  89496. + /** raw register data */
  89497. + uint32_t d32;
  89498. + /** register bits */
  89499. + struct {
  89500. + unsigned txfspcavail:16;
  89501. + unsigned reserved:16;
  89502. + } b;
  89503. +} dtxfsts_data_t;
  89504. +
  89505. +/**
  89506. + * This union represents the bit fields in the I2C Control Register
  89507. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  89508. + * bits using the <i>b</i>it elements.
  89509. + */
  89510. +typedef union gi2cctl_data {
  89511. + /** raw register data */
  89512. + uint32_t d32;
  89513. + /** register bits */
  89514. + struct {
  89515. + unsigned rwdata:8;
  89516. + unsigned regaddr:8;
  89517. + unsigned addr:7;
  89518. + unsigned i2cen:1;
  89519. + unsigned ack:1;
  89520. + unsigned i2csuspctl:1;
  89521. + unsigned i2cdevaddr:2;
  89522. + unsigned i2cdatse0:1;
  89523. + unsigned reserved:1;
  89524. + unsigned rw:1;
  89525. + unsigned bsydne:1;
  89526. + } b;
  89527. +} gi2cctl_data_t;
  89528. +
  89529. +/**
  89530. + * This union represents the bit fields in the PHY Vendor Control Register
  89531. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  89532. + * bits using the <i>b</i>it elements.
  89533. + */
  89534. +typedef union gpvndctl_data {
  89535. + /** raw register data */
  89536. + uint32_t d32;
  89537. + /** register bits */
  89538. + struct {
  89539. + unsigned regdata:8;
  89540. + unsigned vctrl:8;
  89541. + unsigned regaddr16_21:6;
  89542. + unsigned regwr:1;
  89543. + unsigned reserved23_24:2;
  89544. + unsigned newregreq:1;
  89545. + unsigned vstsbsy:1;
  89546. + unsigned vstsdone:1;
  89547. + unsigned reserved28_30:3;
  89548. + unsigned disulpidrvr:1;
  89549. + } b;
  89550. +} gpvndctl_data_t;
  89551. +
  89552. +/**
  89553. + * This union represents the bit fields in the General Purpose
  89554. + * Input/Output Register (GGPIO).
  89555. + * Read the register into the <i>d32</i> element then read out the
  89556. + * bits using the <i>b</i>it elements.
  89557. + */
  89558. +typedef union ggpio_data {
  89559. + /** raw register data */
  89560. + uint32_t d32;
  89561. + /** register bits */
  89562. + struct {
  89563. + unsigned gpi:16;
  89564. + unsigned gpo:16;
  89565. + } b;
  89566. +} ggpio_data_t;
  89567. +
  89568. +/**
  89569. + * This union represents the bit fields in the User ID Register
  89570. + * (GUID). Read the register into the <i>d32</i> element then read out the
  89571. + * bits using the <i>b</i>it elements.
  89572. + */
  89573. +typedef union guid_data {
  89574. + /** raw register data */
  89575. + uint32_t d32;
  89576. + /** register bits */
  89577. + struct {
  89578. + unsigned rwdata:32;
  89579. + } b;
  89580. +} guid_data_t;
  89581. +
  89582. +/**
  89583. + * This union represents the bit fields in the Synopsys ID Register
  89584. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  89585. + * bits using the <i>b</i>it elements.
  89586. + */
  89587. +typedef union gsnpsid_data {
  89588. + /** raw register data */
  89589. + uint32_t d32;
  89590. + /** register bits */
  89591. + struct {
  89592. + unsigned rwdata:32;
  89593. + } b;
  89594. +} gsnpsid_data_t;
  89595. +
  89596. +/**
  89597. + * This union represents the bit fields in the User HW Config1
  89598. + * Register. Read the register into the <i>d32</i> element then read
  89599. + * out the bits using the <i>b</i>it elements.
  89600. + */
  89601. +typedef union hwcfg1_data {
  89602. + /** raw register data */
  89603. + uint32_t d32;
  89604. + /** register bits */
  89605. + struct {
  89606. + unsigned ep_dir0:2;
  89607. + unsigned ep_dir1:2;
  89608. + unsigned ep_dir2:2;
  89609. + unsigned ep_dir3:2;
  89610. + unsigned ep_dir4:2;
  89611. + unsigned ep_dir5:2;
  89612. + unsigned ep_dir6:2;
  89613. + unsigned ep_dir7:2;
  89614. + unsigned ep_dir8:2;
  89615. + unsigned ep_dir9:2;
  89616. + unsigned ep_dir10:2;
  89617. + unsigned ep_dir11:2;
  89618. + unsigned ep_dir12:2;
  89619. + unsigned ep_dir13:2;
  89620. + unsigned ep_dir14:2;
  89621. + unsigned ep_dir15:2;
  89622. + } b;
  89623. +} hwcfg1_data_t;
  89624. +
  89625. +/**
  89626. + * This union represents the bit fields in the User HW Config2
  89627. + * Register. Read the register into the <i>d32</i> element then read
  89628. + * out the bits using the <i>b</i>it elements.
  89629. + */
  89630. +typedef union hwcfg2_data {
  89631. + /** raw register data */
  89632. + uint32_t d32;
  89633. + /** register bits */
  89634. + struct {
  89635. + /* GHWCFG2 */
  89636. + unsigned op_mode:3;
  89637. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  89638. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  89639. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  89640. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  89641. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  89642. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  89643. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  89644. +
  89645. + unsigned architecture:2;
  89646. + unsigned point2point:1;
  89647. + unsigned hs_phy_type:2;
  89648. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  89649. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  89650. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  89651. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  89652. +
  89653. + unsigned fs_phy_type:2;
  89654. + unsigned num_dev_ep:4;
  89655. + unsigned num_host_chan:4;
  89656. + unsigned perio_ep_supported:1;
  89657. + unsigned dynamic_fifo:1;
  89658. + unsigned multi_proc_int:1;
  89659. + unsigned reserved21:1;
  89660. + unsigned nonperio_tx_q_depth:2;
  89661. + unsigned host_perio_tx_q_depth:2;
  89662. + unsigned dev_token_q_depth:5;
  89663. + unsigned otg_enable_ic_usb:1;
  89664. + } b;
  89665. +} hwcfg2_data_t;
  89666. +
  89667. +/**
  89668. + * This union represents the bit fields in the User HW Config3
  89669. + * Register. Read the register into the <i>d32</i> element then read
  89670. + * out the bits using the <i>b</i>it elements.
  89671. + */
  89672. +typedef union hwcfg3_data {
  89673. + /** raw register data */
  89674. + uint32_t d32;
  89675. + /** register bits */
  89676. + struct {
  89677. + /* GHWCFG3 */
  89678. + unsigned xfer_size_cntr_width:4;
  89679. + unsigned packet_size_cntr_width:3;
  89680. + unsigned otg_func:1;
  89681. + unsigned i2c:1;
  89682. + unsigned vendor_ctrl_if:1;
  89683. + unsigned optional_features:1;
  89684. + unsigned synch_reset_type:1;
  89685. + unsigned adp_supp:1;
  89686. + unsigned otg_enable_hsic:1;
  89687. + unsigned bc_support:1;
  89688. + unsigned otg_lpm_en:1;
  89689. + unsigned dfifo_depth:16;
  89690. + } b;
  89691. +} hwcfg3_data_t;
  89692. +
  89693. +/**
  89694. + * This union represents the bit fields in the User HW Config4
  89695. + * Register. Read the register into the <i>d32</i> element then read
  89696. + * out the bits using the <i>b</i>it elements.
  89697. + */
  89698. +typedef union hwcfg4_data {
  89699. + /** raw register data */
  89700. + uint32_t d32;
  89701. + /** register bits */
  89702. + struct {
  89703. + unsigned num_dev_perio_in_ep:4;
  89704. + unsigned power_optimiz:1;
  89705. + unsigned min_ahb_freq:1;
  89706. + unsigned hiber:1;
  89707. + unsigned xhiber:1;
  89708. + unsigned reserved:6;
  89709. + unsigned utmi_phy_data_width:2;
  89710. + unsigned num_dev_mode_ctrl_ep:4;
  89711. + unsigned iddig_filt_en:1;
  89712. + unsigned vbus_valid_filt_en:1;
  89713. + unsigned a_valid_filt_en:1;
  89714. + unsigned b_valid_filt_en:1;
  89715. + unsigned session_end_filt_en:1;
  89716. + unsigned ded_fifo_en:1;
  89717. + unsigned num_in_eps:4;
  89718. + unsigned desc_dma:1;
  89719. + unsigned desc_dma_dyn:1;
  89720. + } b;
  89721. +} hwcfg4_data_t;
  89722. +
  89723. +/**
  89724. + * This union represents the bit fields of the Core LPM Configuration
  89725. + * Register (GLPMCFG). Set the bits using bit fields then write
  89726. + * the <i>d32</i> value to the register.
  89727. + */
  89728. +typedef union glpmctl_data {
  89729. + /** raw register data */
  89730. + uint32_t d32;
  89731. + /** register bits */
  89732. + struct {
  89733. + /** LPM-Capable (LPMCap) (Device and Host)
  89734. + * The application uses this bit to control
  89735. + * the DWC_otg core LPM capabilities.
  89736. + */
  89737. + unsigned lpm_cap_en:1;
  89738. + /** LPM response programmed by application (AppL1Res) (Device)
  89739. + * Handshake response to LPM token pre-programmed
  89740. + * by device application software.
  89741. + */
  89742. + unsigned appl_resp:1;
  89743. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  89744. + * In Host mode this field indicates the value of HIRD
  89745. + * to be sent in an LPM transaction.
  89746. + * In Device mode this field is updated with the
  89747. + * Received LPM Token HIRD bmAttribute
  89748. + * when an ACK/NYET/STALL response is sent
  89749. + * to an LPM transaction.
  89750. + */
  89751. + unsigned hird:4;
  89752. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  89753. + * In Host mode this bit indicates the value of remote
  89754. + * wake up to be sent in wIndex field of LPM transaction.
  89755. + * In Device mode this field is updated with the
  89756. + * Received LPM Token bRemoteWake bmAttribute
  89757. + * when an ACK/NYET/STALL response is sent
  89758. + * to an LPM transaction.
  89759. + */
  89760. + unsigned rem_wkup_en:1;
  89761. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  89762. + * The application uses this bit to control
  89763. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  89764. + */
  89765. + unsigned en_utmi_sleep:1;
  89766. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  89767. + */
  89768. + unsigned hird_thres:5;
  89769. + /** LPM Response (CoreL1Res) (Device and Host)
  89770. + * In Host mode this bit contains handsake response to
  89771. + * LPM transaction.
  89772. + * In Device mode the response of the core to
  89773. + * LPM transaction received is reflected in these two bits.
  89774. + - 0x0 : ERROR (No handshake response)
  89775. + - 0x1 : STALL
  89776. + - 0x2 : NYET
  89777. + - 0x3 : ACK
  89778. + */
  89779. + unsigned lpm_resp:2;
  89780. + /** Port Sleep Status (SlpSts) (Device and Host)
  89781. + * This bit is set as long as a Sleep condition
  89782. + * is present on the USB bus.
  89783. + */
  89784. + unsigned prt_sleep_sts:1;
  89785. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  89786. + * Indicates that the application or host
  89787. + * can start resume from Sleep state.
  89788. + */
  89789. + unsigned sleep_state_resumeok:1;
  89790. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  89791. + * The channel number on which the LPM transaction
  89792. + * has to be applied while sending
  89793. + * an LPM transaction to the local device.
  89794. + */
  89795. + unsigned lpm_chan_index:4;
  89796. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  89797. + * Number host retries that would be performed
  89798. + * if the device response was not valid response.
  89799. + */
  89800. + unsigned retry_count:3;
  89801. + /** Send LPM Transaction (SndLPM) (Host)
  89802. + * When set by application software,
  89803. + * an LPM transaction containing two tokens
  89804. + * is sent.
  89805. + */
  89806. + unsigned send_lpm:1;
  89807. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  89808. + * Number of LPM Host Retries still remaining
  89809. + * to be transmitted for the current LPM sequence
  89810. + */
  89811. + unsigned retry_count_sts:3;
  89812. + unsigned reserved28_29:2;
  89813. + /** In host mode once this bit is set, the host
  89814. + * configures to drive the HSIC Idle state on the bus.
  89815. + * It then waits for the device to initiate the Connect sequence.
  89816. + * In device mode once this bit is set, the device waits for
  89817. + * the HSIC Idle line state on the bus. Upon receving the Idle
  89818. + * line state, it initiates the HSIC Connect sequence.
  89819. + */
  89820. + unsigned hsic_connect:1;
  89821. + /** This bit overrides and functionally inverts
  89822. + * the if_select_hsic input port signal.
  89823. + */
  89824. + unsigned inv_sel_hsic:1;
  89825. + } b;
  89826. +} glpmcfg_data_t;
  89827. +
  89828. +/**
  89829. + * This union represents the bit fields of the Core ADP Timer, Control and
  89830. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  89831. + * the <i>d32</i> value to the register.
  89832. + */
  89833. +typedef union adpctl_data {
  89834. + /** raw register data */
  89835. + uint32_t d32;
  89836. + /** register bits */
  89837. + struct {
  89838. + /** Probe Discharge (PRB_DSCHG)
  89839. + * These bits set the times for TADP_DSCHG.
  89840. + * These bits are defined as follows:
  89841. + * 2'b00 - 4 msec
  89842. + * 2'b01 - 8 msec
  89843. + * 2'b10 - 16 msec
  89844. + * 2'b11 - 32 msec
  89845. + */
  89846. + unsigned prb_dschg:2;
  89847. + /** Probe Delta (PRB_DELTA)
  89848. + * These bits set the resolution for RTIM value.
  89849. + * The bits are defined in units of 32 kHz clock cycles as follows:
  89850. + * 2'b00 - 1 cycles
  89851. + * 2'b01 - 2 cycles
  89852. + * 2'b10 - 3 cycles
  89853. + * 2'b11 - 4 cycles
  89854. + * For example if this value is chosen to 2'b01, it means that RTIM
  89855. + * increments for every 3(three) 32Khz clock cycles.
  89856. + */
  89857. + unsigned prb_delta:2;
  89858. + /** Probe Period (PRB_PER)
  89859. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  89860. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  89861. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  89862. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  89863. + * 2'b11 - Reserved
  89864. + */
  89865. + unsigned prb_per:2;
  89866. + /** These bits capture the latest time it took for VBUS to ramp from
  89867. + * VADP_SINK to VADP_PRB.
  89868. + * 0x000 - 1 cycles
  89869. + * 0x001 - 2 cycles
  89870. + * 0x002 - 3 cycles
  89871. + * etc
  89872. + * 0x7FF - 2048 cycles
  89873. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  89874. + */
  89875. + unsigned rtim:11;
  89876. + /** Enable Probe (EnaPrb)
  89877. + * When programmed to 1'b1, the core performs a probe operation.
  89878. + * This bit is valid only if OTG_Ver = 1'b1.
  89879. + */
  89880. + unsigned enaprb:1;
  89881. + /** Enable Sense (EnaSns)
  89882. + * When programmed to 1'b1, the core performs a Sense operation.
  89883. + * This bit is valid only if OTG_Ver = 1'b1.
  89884. + */
  89885. + unsigned enasns:1;
  89886. + /** ADP Reset (ADPRes)
  89887. + * When set, ADP controller is reset.
  89888. + * This bit is valid only if OTG_Ver = 1'b1.
  89889. + */
  89890. + unsigned adpres:1;
  89891. + /** ADP Enable (ADPEn)
  89892. + * When set, the core performs either ADP probing or sensing
  89893. + * based on EnaPrb or EnaSns.
  89894. + * This bit is valid only if OTG_Ver = 1'b1.
  89895. + */
  89896. + unsigned adpen:1;
  89897. + /** ADP Probe Interrupt (ADP_PRB_INT)
  89898. + * When this bit is set, it means that the VBUS
  89899. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  89900. + * This bit is valid only if OTG_Ver = 1'b1.
  89901. + */
  89902. + unsigned adp_prb_int:1;
  89903. + /**
  89904. + * ADP Sense Interrupt (ADP_SNS_INT)
  89905. + * When this bit is set, it means that the VBUS voltage is greater than
  89906. + * VADP_SNS value or VADP_SNS is reached.
  89907. + * This bit is valid only if OTG_Ver = 1'b1.
  89908. + */
  89909. + unsigned adp_sns_int:1;
  89910. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  89911. + * This bit is relevant only for an ADP probe.
  89912. + * When this bit is set, it means that the ramp time has
  89913. + * completed ie ADPCTL.RTIM has reached its terminal value
  89914. + * of 0x7FF. This is a debug feature that allows software
  89915. + * to read the ramp time after each cycle.
  89916. + * This bit is valid only if OTG_Ver = 1'b1.
  89917. + */
  89918. + unsigned adp_tmout_int:1;
  89919. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  89920. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  89921. + * This bit is valid only if OTG_Ver = 1'b1.
  89922. + */
  89923. + unsigned adp_prb_int_msk:1;
  89924. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  89925. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  89926. + * This bit is valid only if OTG_Ver = 1'b1.
  89927. + */
  89928. + unsigned adp_sns_int_msk:1;
  89929. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  89930. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  89931. + * This bit is valid only if OTG_Ver = 1'b1.
  89932. + */
  89933. + unsigned adp_tmout_int_msk:1;
  89934. + /** Access Request
  89935. + * 2'b00 - Read/Write Valid (updated by the core)
  89936. + * 2'b01 - Read
  89937. + * 2'b00 - Write
  89938. + * 2'b00 - Reserved
  89939. + */
  89940. + unsigned ar:2;
  89941. + /** Reserved */
  89942. + unsigned reserved29_31:3;
  89943. + } b;
  89944. +} adpctl_data_t;
  89945. +
  89946. +////////////////////////////////////////////
  89947. +// Device Registers
  89948. +/**
  89949. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  89950. + *
  89951. + * The following structures define the size and relative field offsets
  89952. + * for the Device Mode Registers.
  89953. + *
  89954. + * <i>These registers are visible only in Device mode and must not be
  89955. + * accessed in Host mode, as the results are unknown.</i>
  89956. + */
  89957. +typedef struct dwc_otg_dev_global_regs {
  89958. + /** Device Configuration Register. <i>Offset 800h</i> */
  89959. + volatile uint32_t dcfg;
  89960. + /** Device Control Register. <i>Offset: 804h</i> */
  89961. + volatile uint32_t dctl;
  89962. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  89963. + volatile uint32_t dsts;
  89964. + /** Reserved. <i>Offset: 80Ch</i> */
  89965. + uint32_t unused;
  89966. + /** Device IN Endpoint Common Interrupt Mask
  89967. + * Register. <i>Offset: 810h</i> */
  89968. + volatile uint32_t diepmsk;
  89969. + /** Device OUT Endpoint Common Interrupt Mask
  89970. + * Register. <i>Offset: 814h</i> */
  89971. + volatile uint32_t doepmsk;
  89972. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  89973. + volatile uint32_t daint;
  89974. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  89975. + * 81Ch</i> */
  89976. + volatile uint32_t daintmsk;
  89977. + /** Device IN Token Queue Read Register-1 (Read Only).
  89978. + * <i>Offset: 820h</i> */
  89979. + volatile uint32_t dtknqr1;
  89980. + /** Device IN Token Queue Read Register-2 (Read Only).
  89981. + * <i>Offset: 824h</i> */
  89982. + volatile uint32_t dtknqr2;
  89983. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  89984. + volatile uint32_t dvbusdis;
  89985. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  89986. + volatile uint32_t dvbuspulse;
  89987. + /** Device IN Token Queue Read Register-3 (Read Only). /
  89988. + * Device Thresholding control register (Read/Write)
  89989. + * <i>Offset: 830h</i> */
  89990. + volatile uint32_t dtknqr3_dthrctl;
  89991. + /** Device IN Token Queue Read Register-4 (Read Only). /
  89992. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  89993. + * <i>Offset: 834h</i> */
  89994. + volatile uint32_t dtknqr4_fifoemptymsk;
  89995. + /** Device Each Endpoint Interrupt Register (Read Only). /
  89996. + * <i>Offset: 838h</i> */
  89997. + volatile uint32_t deachint;
  89998. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  89999. + * <i>Offset: 83Ch</i> */
  90000. + volatile uint32_t deachintmsk;
  90001. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  90002. + * <i>Offset: 840h</i> */
  90003. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  90004. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  90005. + * <i>Offset: 880h</i> */
  90006. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  90007. +} dwc_otg_device_global_regs_t;
  90008. +
  90009. +/**
  90010. + * This union represents the bit fields in the Device Configuration
  90011. + * Register. Read the register into the <i>d32</i> member then
  90012. + * set/clear the bits using the <i>b</i>it elements. Write the
  90013. + * <i>d32</i> member to the dcfg register.
  90014. + */
  90015. +typedef union dcfg_data {
  90016. + /** raw register data */
  90017. + uint32_t d32;
  90018. + /** register bits */
  90019. + struct {
  90020. + /** Device Speed */
  90021. + unsigned devspd:2;
  90022. + /** Non Zero Length Status OUT Handshake */
  90023. + unsigned nzstsouthshk:1;
  90024. +#define DWC_DCFG_SEND_STALL 1
  90025. +
  90026. + unsigned ena32khzs:1;
  90027. + /** Device Addresses */
  90028. + unsigned devaddr:7;
  90029. + /** Periodic Frame Interval */
  90030. + unsigned perfrint:2;
  90031. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  90032. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  90033. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  90034. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  90035. +
  90036. + /** Enable Device OUT NAK for bulk in DDMA mode */
  90037. + unsigned endevoutnak:1;
  90038. +
  90039. + unsigned reserved14_17:4;
  90040. + /** In Endpoint Mis-match count */
  90041. + unsigned epmscnt:5;
  90042. + /** Enable Descriptor DMA in Device mode */
  90043. + unsigned descdma:1;
  90044. + unsigned perschintvl:2;
  90045. + unsigned resvalid:6;
  90046. + } b;
  90047. +} dcfg_data_t;
  90048. +
  90049. +/**
  90050. + * This union represents the bit fields in the Device Control
  90051. + * Register. Read the register into the <i>d32</i> member then
  90052. + * set/clear the bits using the <i>b</i>it elements.
  90053. + */
  90054. +typedef union dctl_data {
  90055. + /** raw register data */
  90056. + uint32_t d32;
  90057. + /** register bits */
  90058. + struct {
  90059. + /** Remote Wakeup */
  90060. + unsigned rmtwkupsig:1;
  90061. + /** Soft Disconnect */
  90062. + unsigned sftdiscon:1;
  90063. + /** Global Non-Periodic IN NAK Status */
  90064. + unsigned gnpinnaksts:1;
  90065. + /** Global OUT NAK Status */
  90066. + unsigned goutnaksts:1;
  90067. + /** Test Control */
  90068. + unsigned tstctl:3;
  90069. + /** Set Global Non-Periodic IN NAK */
  90070. + unsigned sgnpinnak:1;
  90071. + /** Clear Global Non-Periodic IN NAK */
  90072. + unsigned cgnpinnak:1;
  90073. + /** Set Global OUT NAK */
  90074. + unsigned sgoutnak:1;
  90075. + /** Clear Global OUT NAK */
  90076. + unsigned cgoutnak:1;
  90077. + /** Power-On Programming Done */
  90078. + unsigned pwronprgdone:1;
  90079. + /** Reserved */
  90080. + unsigned reserved:1;
  90081. + /** Global Multi Count */
  90082. + unsigned gmc:2;
  90083. + /** Ignore Frame Number for ISOC EPs */
  90084. + unsigned ifrmnum:1;
  90085. + /** NAK on Babble */
  90086. + unsigned nakonbble:1;
  90087. + /** Enable Continue on BNA */
  90088. + unsigned encontonbna:1;
  90089. +
  90090. + unsigned reserved18_31:14;
  90091. + } b;
  90092. +} dctl_data_t;
  90093. +
  90094. +/**
  90095. + * This union represents the bit fields in the Device Status
  90096. + * Register. Read the register into the <i>d32</i> member then
  90097. + * set/clear the bits using the <i>b</i>it elements.
  90098. + */
  90099. +typedef union dsts_data {
  90100. + /** raw register data */
  90101. + uint32_t d32;
  90102. + /** register bits */
  90103. + struct {
  90104. + /** Suspend Status */
  90105. + unsigned suspsts:1;
  90106. + /** Enumerated Speed */
  90107. + unsigned enumspd:2;
  90108. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  90109. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  90110. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  90111. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  90112. + /** Erratic Error */
  90113. + unsigned errticerr:1;
  90114. + unsigned reserved4_7:4;
  90115. + /** Frame or Microframe Number of the received SOF */
  90116. + unsigned soffn:14;
  90117. + unsigned reserved22_31:10;
  90118. + } b;
  90119. +} dsts_data_t;
  90120. +
  90121. +/**
  90122. + * This union represents the bit fields in the Device IN EP Interrupt
  90123. + * Register and the Device IN EP Common Mask Register.
  90124. + *
  90125. + * - Read the register into the <i>d32</i> member then set/clear the
  90126. + * bits using the <i>b</i>it elements.
  90127. + */
  90128. +typedef union diepint_data {
  90129. + /** raw register data */
  90130. + uint32_t d32;
  90131. + /** register bits */
  90132. + struct {
  90133. + /** Transfer complete mask */
  90134. + unsigned xfercompl:1;
  90135. + /** Endpoint disable mask */
  90136. + unsigned epdisabled:1;
  90137. + /** AHB Error mask */
  90138. + unsigned ahberr:1;
  90139. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  90140. + unsigned timeout:1;
  90141. + /** IN Token received with TxF Empty mask */
  90142. + unsigned intktxfemp:1;
  90143. + /** IN Token Received with EP mismatch mask */
  90144. + unsigned intknepmis:1;
  90145. + /** IN Endpoint NAK Effective mask */
  90146. + unsigned inepnakeff:1;
  90147. + /** Reserved */
  90148. + unsigned emptyintr:1;
  90149. +
  90150. + unsigned txfifoundrn:1;
  90151. +
  90152. + /** BNA Interrupt mask */
  90153. + unsigned bna:1;
  90154. +
  90155. + unsigned reserved10_12:3;
  90156. + /** BNA Interrupt mask */
  90157. + unsigned nak:1;
  90158. +
  90159. + unsigned reserved14_31:18;
  90160. + } b;
  90161. +} diepint_data_t;
  90162. +
  90163. +/**
  90164. + * This union represents the bit fields in the Device IN EP
  90165. + * Common/Dedicated Interrupt Mask Register.
  90166. + */
  90167. +typedef union diepint_data diepmsk_data_t;
  90168. +
  90169. +/**
  90170. + * This union represents the bit fields in the Device OUT EP Interrupt
  90171. + * Registerand Device OUT EP Common Interrupt Mask Register.
  90172. + *
  90173. + * - Read the register into the <i>d32</i> member then set/clear the
  90174. + * bits using the <i>b</i>it elements.
  90175. + */
  90176. +typedef union doepint_data {
  90177. + /** raw register data */
  90178. + uint32_t d32;
  90179. + /** register bits */
  90180. + struct {
  90181. + /** Transfer complete */
  90182. + unsigned xfercompl:1;
  90183. + /** Endpoint disable */
  90184. + unsigned epdisabled:1;
  90185. + /** AHB Error */
  90186. + unsigned ahberr:1;
  90187. + /** Setup Phase Done (contorl EPs) */
  90188. + unsigned setup:1;
  90189. + /** OUT Token Received when Endpoint Disabled */
  90190. + unsigned outtknepdis:1;
  90191. +
  90192. + unsigned stsphsercvd:1;
  90193. + /** Back-to-Back SETUP Packets Received */
  90194. + unsigned back2backsetup:1;
  90195. +
  90196. + unsigned reserved7:1;
  90197. + /** OUT packet Error */
  90198. + unsigned outpkterr:1;
  90199. + /** BNA Interrupt */
  90200. + unsigned bna:1;
  90201. +
  90202. + unsigned reserved10:1;
  90203. + /** Packet Drop Status */
  90204. + unsigned pktdrpsts:1;
  90205. + /** Babble Interrupt */
  90206. + unsigned babble:1;
  90207. + /** NAK Interrupt */
  90208. + unsigned nak:1;
  90209. + /** NYET Interrupt */
  90210. + unsigned nyet:1;
  90211. + /** Bit indicating setup packet received */
  90212. + unsigned sr:1;
  90213. +
  90214. + unsigned reserved16_31:16;
  90215. + } b;
  90216. +} doepint_data_t;
  90217. +
  90218. +/**
  90219. + * This union represents the bit fields in the Device OUT EP
  90220. + * Common/Dedicated Interrupt Mask Register.
  90221. + */
  90222. +typedef union doepint_data doepmsk_data_t;
  90223. +
  90224. +/**
  90225. + * This union represents the bit fields in the Device All EP Interrupt
  90226. + * and Mask Registers.
  90227. + * - Read the register into the <i>d32</i> member then set/clear the
  90228. + * bits using the <i>b</i>it elements.
  90229. + */
  90230. +typedef union daint_data {
  90231. + /** raw register data */
  90232. + uint32_t d32;
  90233. + /** register bits */
  90234. + struct {
  90235. + /** IN Endpoint bits */
  90236. + unsigned in:16;
  90237. + /** OUT Endpoint bits */
  90238. + unsigned out:16;
  90239. + } ep;
  90240. + struct {
  90241. + /** IN Endpoint bits */
  90242. + unsigned inep0:1;
  90243. + unsigned inep1:1;
  90244. + unsigned inep2:1;
  90245. + unsigned inep3:1;
  90246. + unsigned inep4:1;
  90247. + unsigned inep5:1;
  90248. + unsigned inep6:1;
  90249. + unsigned inep7:1;
  90250. + unsigned inep8:1;
  90251. + unsigned inep9:1;
  90252. + unsigned inep10:1;
  90253. + unsigned inep11:1;
  90254. + unsigned inep12:1;
  90255. + unsigned inep13:1;
  90256. + unsigned inep14:1;
  90257. + unsigned inep15:1;
  90258. + /** OUT Endpoint bits */
  90259. + unsigned outep0:1;
  90260. + unsigned outep1:1;
  90261. + unsigned outep2:1;
  90262. + unsigned outep3:1;
  90263. + unsigned outep4:1;
  90264. + unsigned outep5:1;
  90265. + unsigned outep6:1;
  90266. + unsigned outep7:1;
  90267. + unsigned outep8:1;
  90268. + unsigned outep9:1;
  90269. + unsigned outep10:1;
  90270. + unsigned outep11:1;
  90271. + unsigned outep12:1;
  90272. + unsigned outep13:1;
  90273. + unsigned outep14:1;
  90274. + unsigned outep15:1;
  90275. + } b;
  90276. +} daint_data_t;
  90277. +
  90278. +/**
  90279. + * This union represents the bit fields in the Device IN Token Queue
  90280. + * Read Registers.
  90281. + * - Read the register into the <i>d32</i> member.
  90282. + * - READ-ONLY Register
  90283. + */
  90284. +typedef union dtknq1_data {
  90285. + /** raw register data */
  90286. + uint32_t d32;
  90287. + /** register bits */
  90288. + struct {
  90289. + /** In Token Queue Write Pointer */
  90290. + unsigned intknwptr:5;
  90291. + /** Reserved */
  90292. + unsigned reserved05_06:2;
  90293. + /** write pointer has wrapped. */
  90294. + unsigned wrap_bit:1;
  90295. + /** EP Numbers of IN Tokens 0 ... 4 */
  90296. + unsigned epnums0_5:24;
  90297. + } b;
  90298. +} dtknq1_data_t;
  90299. +
  90300. +/**
  90301. + * This union represents Threshold control Register
  90302. + * - Read and write the register into the <i>d32</i> member.
  90303. + * - READ-WRITABLE Register
  90304. + */
  90305. +typedef union dthrctl_data {
  90306. + /** raw register data */
  90307. + uint32_t d32;
  90308. + /** register bits */
  90309. + struct {
  90310. + /** non ISO Tx Thr. Enable */
  90311. + unsigned non_iso_thr_en:1;
  90312. + /** ISO Tx Thr. Enable */
  90313. + unsigned iso_thr_en:1;
  90314. + /** Tx Thr. Length */
  90315. + unsigned tx_thr_len:9;
  90316. + /** AHB Threshold ratio */
  90317. + unsigned ahb_thr_ratio:2;
  90318. + /** Reserved */
  90319. + unsigned reserved13_15:3;
  90320. + /** Rx Thr. Enable */
  90321. + unsigned rx_thr_en:1;
  90322. + /** Rx Thr. Length */
  90323. + unsigned rx_thr_len:9;
  90324. + unsigned reserved26:1;
  90325. + /** Arbiter Parking Enable*/
  90326. + unsigned arbprken:1;
  90327. + /** Reserved */
  90328. + unsigned reserved28_31:4;
  90329. + } b;
  90330. +} dthrctl_data_t;
  90331. +
  90332. +/**
  90333. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  90334. + * 900h-AFCh</i>
  90335. + *
  90336. + * There will be one set of endpoint registers per logical endpoint
  90337. + * implemented.
  90338. + *
  90339. + * <i>These registers are visible only in Device mode and must not be
  90340. + * accessed in Host mode, as the results are unknown.</i>
  90341. + */
  90342. +typedef struct dwc_otg_dev_in_ep_regs {
  90343. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  90344. + * (ep_num * 20h) + 00h</i> */
  90345. + volatile uint32_t diepctl;
  90346. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  90347. + uint32_t reserved04;
  90348. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  90349. + * (ep_num * 20h) + 08h</i> */
  90350. + volatile uint32_t diepint;
  90351. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  90352. + uint32_t reserved0C;
  90353. + /** Device IN Endpoint Transfer Size
  90354. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  90355. + volatile uint32_t dieptsiz;
  90356. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  90357. + * (ep_num * 20h) + 14h</i> */
  90358. + volatile uint32_t diepdma;
  90359. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  90360. + * (ep_num * 20h) + 18h</i> */
  90361. + volatile uint32_t dtxfsts;
  90362. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  90363. + * (ep_num * 20h) + 1Ch</i> */
  90364. + volatile uint32_t diepdmab;
  90365. +} dwc_otg_dev_in_ep_regs_t;
  90366. +
  90367. +/**
  90368. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  90369. + * B00h-CFCh</i>
  90370. + *
  90371. + * There will be one set of endpoint registers per logical endpoint
  90372. + * implemented.
  90373. + *
  90374. + * <i>These registers are visible only in Device mode and must not be
  90375. + * accessed in Host mode, as the results are unknown.</i>
  90376. + */
  90377. +typedef struct dwc_otg_dev_out_ep_regs {
  90378. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  90379. + * (ep_num * 20h) + 00h</i> */
  90380. + volatile uint32_t doepctl;
  90381. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  90382. + uint32_t reserved04;
  90383. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  90384. + * (ep_num * 20h) + 08h</i> */
  90385. + volatile uint32_t doepint;
  90386. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  90387. + uint32_t reserved0C;
  90388. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  90389. + * B00h + (ep_num * 20h) + 10h</i> */
  90390. + volatile uint32_t doeptsiz;
  90391. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  90392. + * + (ep_num * 20h) + 14h</i> */
  90393. + volatile uint32_t doepdma;
  90394. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  90395. + uint32_t unused;
  90396. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  90397. + * + (ep_num * 20h) + 1Ch</i> */
  90398. + uint32_t doepdmab;
  90399. +} dwc_otg_dev_out_ep_regs_t;
  90400. +
  90401. +/**
  90402. + * This union represents the bit fields in the Device EP Control
  90403. + * Register. Read the register into the <i>d32</i> member then
  90404. + * set/clear the bits using the <i>b</i>it elements.
  90405. + */
  90406. +typedef union depctl_data {
  90407. + /** raw register data */
  90408. + uint32_t d32;
  90409. + /** register bits */
  90410. + struct {
  90411. + /** Maximum Packet Size
  90412. + * IN/OUT EPn
  90413. + * IN/OUT EP0 - 2 bits
  90414. + * 2'b00: 64 Bytes
  90415. + * 2'b01: 32
  90416. + * 2'b10: 16
  90417. + * 2'b11: 8 */
  90418. + unsigned mps:11;
  90419. +#define DWC_DEP0CTL_MPS_64 0
  90420. +#define DWC_DEP0CTL_MPS_32 1
  90421. +#define DWC_DEP0CTL_MPS_16 2
  90422. +#define DWC_DEP0CTL_MPS_8 3
  90423. +
  90424. + /** Next Endpoint
  90425. + * IN EPn/IN EP0
  90426. + * OUT EPn/OUT EP0 - reserved */
  90427. + unsigned nextep:4;
  90428. +
  90429. + /** USB Active Endpoint */
  90430. + unsigned usbactep:1;
  90431. +
  90432. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  90433. + * This field contains the PID of the packet going to
  90434. + * be received or transmitted on this endpoint. The
  90435. + * application should program the PID of the first
  90436. + * packet going to be received or transmitted on this
  90437. + * endpoint , after the endpoint is
  90438. + * activated. Application use the SetD1PID and
  90439. + * SetD0PID fields of this register to program either
  90440. + * D0 or D1 PID.
  90441. + *
  90442. + * The encoding for this field is
  90443. + * - 0: D0
  90444. + * - 1: D1
  90445. + */
  90446. + unsigned dpid:1;
  90447. +
  90448. + /** NAK Status */
  90449. + unsigned naksts:1;
  90450. +
  90451. + /** Endpoint Type
  90452. + * 2'b00: Control
  90453. + * 2'b01: Isochronous
  90454. + * 2'b10: Bulk
  90455. + * 2'b11: Interrupt */
  90456. + unsigned eptype:2;
  90457. +
  90458. + /** Snoop Mode
  90459. + * OUT EPn/OUT EP0
  90460. + * IN EPn/IN EP0 - reserved */
  90461. + unsigned snp:1;
  90462. +
  90463. + /** Stall Handshake */
  90464. + unsigned stall:1;
  90465. +
  90466. + /** Tx Fifo Number
  90467. + * IN EPn/IN EP0
  90468. + * OUT EPn/OUT EP0 - reserved */
  90469. + unsigned txfnum:4;
  90470. +
  90471. + /** Clear NAK */
  90472. + unsigned cnak:1;
  90473. + /** Set NAK */
  90474. + unsigned snak:1;
  90475. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  90476. + * Writing to this field sets the Endpoint DPID (DPID)
  90477. + * field in this register to DATA0. Set Even
  90478. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  90479. + * Writing to this field sets the Even/Odd
  90480. + * (micro)frame (EO_FrNum) field to even (micro)
  90481. + * frame.
  90482. + */
  90483. + unsigned setd0pid:1;
  90484. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  90485. + * Writing to this field sets the Endpoint DPID (DPID)
  90486. + * field in this register to DATA1 Set Odd
  90487. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  90488. + * Writing to this field sets the Even/Odd
  90489. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  90490. + */
  90491. + unsigned setd1pid:1;
  90492. +
  90493. + /** Endpoint Disable */
  90494. + unsigned epdis:1;
  90495. + /** Endpoint Enable */
  90496. + unsigned epena:1;
  90497. + } b;
  90498. +} depctl_data_t;
  90499. +
  90500. +/**
  90501. + * This union represents the bit fields in the Device EP Transfer
  90502. + * Size Register. Read the register into the <i>d32</i> member then
  90503. + * set/clear the bits using the <i>b</i>it elements.
  90504. + */
  90505. +typedef union deptsiz_data {
  90506. + /** raw register data */
  90507. + uint32_t d32;
  90508. + /** register bits */
  90509. + struct {
  90510. + /** Transfer size */
  90511. + unsigned xfersize:19;
  90512. +/** Max packet count for EP (pow(2,10)-1) */
  90513. +#define MAX_PKT_CNT 1023
  90514. + /** Packet Count */
  90515. + unsigned pktcnt:10;
  90516. + /** Multi Count - Periodic IN endpoints */
  90517. + unsigned mc:2;
  90518. + unsigned reserved:1;
  90519. + } b;
  90520. +} deptsiz_data_t;
  90521. +
  90522. +/**
  90523. + * This union represents the bit fields in the Device EP 0 Transfer
  90524. + * Size Register. Read the register into the <i>d32</i> member then
  90525. + * set/clear the bits using the <i>b</i>it elements.
  90526. + */
  90527. +typedef union deptsiz0_data {
  90528. + /** raw register data */
  90529. + uint32_t d32;
  90530. + /** register bits */
  90531. + struct {
  90532. + /** Transfer size */
  90533. + unsigned xfersize:7;
  90534. + /** Reserved */
  90535. + unsigned reserved7_18:12;
  90536. + /** Packet Count */
  90537. + unsigned pktcnt:2;
  90538. + /** Reserved */
  90539. + unsigned reserved21_28:8;
  90540. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  90541. + unsigned supcnt:2;
  90542. + unsigned reserved31;
  90543. + } b;
  90544. +} deptsiz0_data_t;
  90545. +
  90546. +/////////////////////////////////////////////////
  90547. +// DMA Descriptor Specific Structures
  90548. +//
  90549. +
  90550. +/** Buffer status definitions */
  90551. +
  90552. +#define BS_HOST_READY 0x0
  90553. +#define BS_DMA_BUSY 0x1
  90554. +#define BS_DMA_DONE 0x2
  90555. +#define BS_HOST_BUSY 0x3
  90556. +
  90557. +/** Receive/Transmit status definitions */
  90558. +
  90559. +#define RTS_SUCCESS 0x0
  90560. +#define RTS_BUFFLUSH 0x1
  90561. +#define RTS_RESERVED 0x2
  90562. +#define RTS_BUFERR 0x3
  90563. +
  90564. +/**
  90565. + * This union represents the bit fields in the DMA Descriptor
  90566. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  90567. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  90568. + * <i>b_iso_in</i> elements.
  90569. + */
  90570. +typedef union dev_dma_desc_sts {
  90571. + /** raw register data */
  90572. + uint32_t d32;
  90573. + /** quadlet bits */
  90574. + struct {
  90575. + /** Received number of bytes */
  90576. + unsigned bytes:16;
  90577. + /** NAK bit - only for OUT EPs */
  90578. + unsigned nak:1;
  90579. + unsigned reserved17_22:6;
  90580. + /** Multiple Transfer - only for OUT EPs */
  90581. + unsigned mtrf:1;
  90582. + /** Setup Packet received - only for OUT EPs */
  90583. + unsigned sr:1;
  90584. + /** Interrupt On Complete */
  90585. + unsigned ioc:1;
  90586. + /** Short Packet */
  90587. + unsigned sp:1;
  90588. + /** Last */
  90589. + unsigned l:1;
  90590. + /** Receive Status */
  90591. + unsigned sts:2;
  90592. + /** Buffer Status */
  90593. + unsigned bs:2;
  90594. + } b;
  90595. +
  90596. +//#ifdef DWC_EN_ISOC
  90597. + /** iso out quadlet bits */
  90598. + struct {
  90599. + /** Received number of bytes */
  90600. + unsigned rxbytes:11;
  90601. +
  90602. + unsigned reserved11:1;
  90603. + /** Frame Number */
  90604. + unsigned framenum:11;
  90605. + /** Received ISO Data PID */
  90606. + unsigned pid:2;
  90607. + /** Interrupt On Complete */
  90608. + unsigned ioc:1;
  90609. + /** Short Packet */
  90610. + unsigned sp:1;
  90611. + /** Last */
  90612. + unsigned l:1;
  90613. + /** Receive Status */
  90614. + unsigned rxsts:2;
  90615. + /** Buffer Status */
  90616. + unsigned bs:2;
  90617. + } b_iso_out;
  90618. +
  90619. + /** iso in quadlet bits */
  90620. + struct {
  90621. + /** Transmited number of bytes */
  90622. + unsigned txbytes:12;
  90623. + /** Frame Number */
  90624. + unsigned framenum:11;
  90625. + /** Transmited ISO Data PID */
  90626. + unsigned pid:2;
  90627. + /** Interrupt On Complete */
  90628. + unsigned ioc:1;
  90629. + /** Short Packet */
  90630. + unsigned sp:1;
  90631. + /** Last */
  90632. + unsigned l:1;
  90633. + /** Transmit Status */
  90634. + unsigned txsts:2;
  90635. + /** Buffer Status */
  90636. + unsigned bs:2;
  90637. + } b_iso_in;
  90638. +//#endif /* DWC_EN_ISOC */
  90639. +} dev_dma_desc_sts_t;
  90640. +
  90641. +/**
  90642. + * DMA Descriptor structure
  90643. + *
  90644. + * DMA Descriptor structure contains two quadlets:
  90645. + * Status quadlet and Data buffer pointer.
  90646. + */
  90647. +typedef struct dwc_otg_dev_dma_desc {
  90648. + /** DMA Descriptor status quadlet */
  90649. + dev_dma_desc_sts_t status;
  90650. + /** DMA Descriptor data buffer pointer */
  90651. + uint32_t buf;
  90652. +} dwc_otg_dev_dma_desc_t;
  90653. +
  90654. +/**
  90655. + * The dwc_otg_dev_if structure contains information needed to manage
  90656. + * the DWC_otg controller acting in device mode. It represents the
  90657. + * programming view of the device-specific aspects of the controller.
  90658. + */
  90659. +typedef struct dwc_otg_dev_if {
  90660. + /** Pointer to device Global registers.
  90661. + * Device Global Registers starting at offset 800h
  90662. + */
  90663. + dwc_otg_device_global_regs_t *dev_global_regs;
  90664. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  90665. +
  90666. + /**
  90667. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  90668. + */
  90669. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  90670. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  90671. +#define DWC_EP_REG_OFFSET 0x20
  90672. +
  90673. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  90674. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  90675. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  90676. +
  90677. + /* Device configuration information */
  90678. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  90679. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  90680. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  90681. +
  90682. + /** Size of periodic FIFOs (Bytes) */
  90683. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  90684. +
  90685. + /** Size of Tx FIFOs (Bytes) */
  90686. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  90687. +
  90688. + /** Thresholding enable flags and length varaiables **/
  90689. + uint16_t rx_thr_en;
  90690. + uint16_t iso_tx_thr_en;
  90691. + uint16_t non_iso_tx_thr_en;
  90692. +
  90693. + uint16_t rx_thr_length;
  90694. + uint16_t tx_thr_length;
  90695. +
  90696. + /**
  90697. + * Pointers to the DMA Descriptors for EP0 Control
  90698. + * transfers (virtual and physical)
  90699. + */
  90700. +
  90701. + /** 2 descriptors for SETUP packets */
  90702. + dwc_dma_t dma_setup_desc_addr[2];
  90703. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  90704. +
  90705. + /** Pointer to Descriptor with latest SETUP packet */
  90706. + dwc_otg_dev_dma_desc_t *psetup;
  90707. +
  90708. + /** Index of current SETUP handler descriptor */
  90709. + uint32_t setup_desc_index;
  90710. +
  90711. + /** Descriptor for Data In or Status In phases */
  90712. + dwc_dma_t dma_in_desc_addr;
  90713. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  90714. +
  90715. + /** Descriptor for Data Out or Status Out phases */
  90716. + dwc_dma_t dma_out_desc_addr;
  90717. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  90718. +
  90719. + /** Setup Packet Detected - if set clear NAK when queueing */
  90720. + uint32_t spd;
  90721. + /** Isoc ep pointer on which incomplete happens */
  90722. + void *isoc_ep;
  90723. +
  90724. +} dwc_otg_dev_if_t;
  90725. +
  90726. +/////////////////////////////////////////////////
  90727. +// Host Mode Register Structures
  90728. +//
  90729. +/**
  90730. + * The Host Global Registers structure defines the size and relative
  90731. + * field offsets for the Host Mode Global Registers. Host Global
  90732. + * Registers offsets 400h-7FFh.
  90733. +*/
  90734. +typedef struct dwc_otg_host_global_regs {
  90735. + /** Host Configuration Register. <i>Offset: 400h</i> */
  90736. + volatile uint32_t hcfg;
  90737. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  90738. + volatile uint32_t hfir;
  90739. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  90740. + volatile uint32_t hfnum;
  90741. + /** Reserved. <i>Offset: 40Ch</i> */
  90742. + uint32_t reserved40C;
  90743. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  90744. + volatile uint32_t hptxsts;
  90745. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  90746. + volatile uint32_t haint;
  90747. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  90748. + volatile uint32_t haintmsk;
  90749. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  90750. + volatile uint32_t hflbaddr;
  90751. +} dwc_otg_host_global_regs_t;
  90752. +
  90753. +/**
  90754. + * This union represents the bit fields in the Host Configuration Register.
  90755. + * Read the register into the <i>d32</i> member then set/clear the bits using
  90756. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  90757. + */
  90758. +typedef union hcfg_data {
  90759. + /** raw register data */
  90760. + uint32_t d32;
  90761. +
  90762. + /** register bits */
  90763. + struct {
  90764. + /** FS/LS Phy Clock Select */
  90765. + unsigned fslspclksel:2;
  90766. +#define DWC_HCFG_30_60_MHZ 0
  90767. +#define DWC_HCFG_48_MHZ 1
  90768. +#define DWC_HCFG_6_MHZ 2
  90769. +
  90770. + /** FS/LS Only Support */
  90771. + unsigned fslssupp:1;
  90772. + unsigned reserved3_6:4;
  90773. + /** Enable 32-KHz Suspend Mode */
  90774. + unsigned ena32khzs:1;
  90775. + /** Resume Validation Periiod */
  90776. + unsigned resvalid:8;
  90777. + unsigned reserved16_22:7;
  90778. + /** Enable Scatter/gather DMA in Host mode */
  90779. + unsigned descdma:1;
  90780. + /** Frame List Entries */
  90781. + unsigned frlisten:2;
  90782. + /** Enable Periodic Scheduling */
  90783. + unsigned perschedena:1;
  90784. + unsigned reserved27_30:4;
  90785. + unsigned modechtimen:1;
  90786. + } b;
  90787. +} hcfg_data_t;
  90788. +
  90789. +/**
  90790. + * This union represents the bit fields in the Host Frame Remaing/Number
  90791. + * Register.
  90792. + */
  90793. +typedef union hfir_data {
  90794. + /** raw register data */
  90795. + uint32_t d32;
  90796. +
  90797. + /** register bits */
  90798. + struct {
  90799. + unsigned frint:16;
  90800. + unsigned hfirrldctrl:1;
  90801. + unsigned reserved:15;
  90802. + } b;
  90803. +} hfir_data_t;
  90804. +
  90805. +/**
  90806. + * This union represents the bit fields in the Host Frame Remaing/Number
  90807. + * Register.
  90808. + */
  90809. +typedef union hfnum_data {
  90810. + /** raw register data */
  90811. + uint32_t d32;
  90812. +
  90813. + /** register bits */
  90814. + struct {
  90815. + unsigned frnum:16;
  90816. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  90817. + unsigned frrem:16;
  90818. + } b;
  90819. +} hfnum_data_t;
  90820. +
  90821. +typedef union hptxsts_data {
  90822. + /** raw register data */
  90823. + uint32_t d32;
  90824. +
  90825. + /** register bits */
  90826. + struct {
  90827. + unsigned ptxfspcavail:16;
  90828. + unsigned ptxqspcavail:8;
  90829. + /** Top of the Periodic Transmit Request Queue
  90830. + * - bit 24 - Terminate (last entry for the selected channel)
  90831. + * - bits 26:25 - Token Type
  90832. + * - 2'b00 - Zero length
  90833. + * - 2'b01 - Ping
  90834. + * - 2'b10 - Disable
  90835. + * - bits 30:27 - Channel Number
  90836. + * - bit 31 - Odd/even microframe
  90837. + */
  90838. + unsigned ptxqtop_terminate:1;
  90839. + unsigned ptxqtop_token:2;
  90840. + unsigned ptxqtop_chnum:4;
  90841. + unsigned ptxqtop_odd:1;
  90842. + } b;
  90843. +} hptxsts_data_t;
  90844. +
  90845. +/**
  90846. + * This union represents the bit fields in the Host Port Control and Status
  90847. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90848. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90849. + * hprt0 register.
  90850. + */
  90851. +typedef union hprt0_data {
  90852. + /** raw register data */
  90853. + uint32_t d32;
  90854. + /** register bits */
  90855. + struct {
  90856. + unsigned prtconnsts:1;
  90857. + unsigned prtconndet:1;
  90858. + unsigned prtena:1;
  90859. + unsigned prtenchng:1;
  90860. + unsigned prtovrcurract:1;
  90861. + unsigned prtovrcurrchng:1;
  90862. + unsigned prtres:1;
  90863. + unsigned prtsusp:1;
  90864. + unsigned prtrst:1;
  90865. + unsigned reserved9:1;
  90866. + unsigned prtlnsts:2;
  90867. + unsigned prtpwr:1;
  90868. + unsigned prttstctl:4;
  90869. + unsigned prtspd:2;
  90870. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  90871. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  90872. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  90873. + unsigned reserved19_31:13;
  90874. + } b;
  90875. +} hprt0_data_t;
  90876. +
  90877. +/**
  90878. + * This union represents the bit fields in the Host All Interrupt
  90879. + * Register.
  90880. + */
  90881. +typedef union haint_data {
  90882. + /** raw register data */
  90883. + uint32_t d32;
  90884. + /** register bits */
  90885. + struct {
  90886. + unsigned ch0:1;
  90887. + unsigned ch1:1;
  90888. + unsigned ch2:1;
  90889. + unsigned ch3:1;
  90890. + unsigned ch4:1;
  90891. + unsigned ch5:1;
  90892. + unsigned ch6:1;
  90893. + unsigned ch7:1;
  90894. + unsigned ch8:1;
  90895. + unsigned ch9:1;
  90896. + unsigned ch10:1;
  90897. + unsigned ch11:1;
  90898. + unsigned ch12:1;
  90899. + unsigned ch13:1;
  90900. + unsigned ch14:1;
  90901. + unsigned ch15:1;
  90902. + unsigned reserved:16;
  90903. + } b;
  90904. +
  90905. + struct {
  90906. + unsigned chint:16;
  90907. + unsigned reserved:16;
  90908. + } b2;
  90909. +} haint_data_t;
  90910. +
  90911. +/**
  90912. + * This union represents the bit fields in the Host All Interrupt
  90913. + * Register.
  90914. + */
  90915. +typedef union haintmsk_data {
  90916. + /** raw register data */
  90917. + uint32_t d32;
  90918. + /** register bits */
  90919. + struct {
  90920. + unsigned ch0:1;
  90921. + unsigned ch1:1;
  90922. + unsigned ch2:1;
  90923. + unsigned ch3:1;
  90924. + unsigned ch4:1;
  90925. + unsigned ch5:1;
  90926. + unsigned ch6:1;
  90927. + unsigned ch7:1;
  90928. + unsigned ch8:1;
  90929. + unsigned ch9:1;
  90930. + unsigned ch10:1;
  90931. + unsigned ch11:1;
  90932. + unsigned ch12:1;
  90933. + unsigned ch13:1;
  90934. + unsigned ch14:1;
  90935. + unsigned ch15:1;
  90936. + unsigned reserved:16;
  90937. + } b;
  90938. +
  90939. + struct {
  90940. + unsigned chint:16;
  90941. + unsigned reserved:16;
  90942. + } b2;
  90943. +} haintmsk_data_t;
  90944. +
  90945. +/**
  90946. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  90947. + */
  90948. +typedef struct dwc_otg_hc_regs {
  90949. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  90950. + volatile uint32_t hcchar;
  90951. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  90952. + volatile uint32_t hcsplt;
  90953. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  90954. + volatile uint32_t hcint;
  90955. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  90956. + volatile uint32_t hcintmsk;
  90957. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  90958. + volatile uint32_t hctsiz;
  90959. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  90960. + volatile uint32_t hcdma;
  90961. + volatile uint32_t reserved;
  90962. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  90963. + volatile uint32_t hcdmab;
  90964. +} dwc_otg_hc_regs_t;
  90965. +
  90966. +/**
  90967. + * This union represents the bit fields in the Host Channel Characteristics
  90968. + * Register. Read the register into the <i>d32</i> member then set/clear the
  90969. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  90970. + * hcchar register.
  90971. + */
  90972. +typedef union hcchar_data {
  90973. + /** raw register data */
  90974. + uint32_t d32;
  90975. +
  90976. + /** register bits */
  90977. + struct {
  90978. + /** Maximum packet size in bytes */
  90979. + unsigned mps:11;
  90980. +
  90981. + /** Endpoint number */
  90982. + unsigned epnum:4;
  90983. +
  90984. + /** 0: OUT, 1: IN */
  90985. + unsigned epdir:1;
  90986. +
  90987. + unsigned reserved:1;
  90988. +
  90989. + /** 0: Full/high speed device, 1: Low speed device */
  90990. + unsigned lspddev:1;
  90991. +
  90992. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  90993. + unsigned eptype:2;
  90994. +
  90995. + /** Packets per frame for periodic transfers. 0 is reserved. */
  90996. + unsigned multicnt:2;
  90997. +
  90998. + /** Device address */
  90999. + unsigned devaddr:7;
  91000. +
  91001. + /**
  91002. + * Frame to transmit periodic transaction.
  91003. + * 0: even, 1: odd
  91004. + */
  91005. + unsigned oddfrm:1;
  91006. +
  91007. + /** Channel disable */
  91008. + unsigned chdis:1;
  91009. +
  91010. + /** Channel enable */
  91011. + unsigned chen:1;
  91012. + } b;
  91013. +} hcchar_data_t;
  91014. +
  91015. +typedef union hcsplt_data {
  91016. + /** raw register data */
  91017. + uint32_t d32;
  91018. +
  91019. + /** register bits */
  91020. + struct {
  91021. + /** Port Address */
  91022. + unsigned prtaddr:7;
  91023. +
  91024. + /** Hub Address */
  91025. + unsigned hubaddr:7;
  91026. +
  91027. + /** Transaction Position */
  91028. + unsigned xactpos:2;
  91029. +#define DWC_HCSPLIT_XACTPOS_MID 0
  91030. +#define DWC_HCSPLIT_XACTPOS_END 1
  91031. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  91032. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  91033. +
  91034. + /** Do Complete Split */
  91035. + unsigned compsplt:1;
  91036. +
  91037. + /** Reserved */
  91038. + unsigned reserved:14;
  91039. +
  91040. + /** Split Enble */
  91041. + unsigned spltena:1;
  91042. + } b;
  91043. +} hcsplt_data_t;
  91044. +
  91045. +/**
  91046. + * This union represents the bit fields in the Host All Interrupt
  91047. + * Register.
  91048. + */
  91049. +typedef union hcint_data {
  91050. + /** raw register data */
  91051. + uint32_t d32;
  91052. + /** register bits */
  91053. + struct {
  91054. + /** Transfer Complete */
  91055. + unsigned xfercomp:1;
  91056. + /** Channel Halted */
  91057. + unsigned chhltd:1;
  91058. + /** AHB Error */
  91059. + unsigned ahberr:1;
  91060. + /** STALL Response Received */
  91061. + unsigned stall:1;
  91062. + /** NAK Response Received */
  91063. + unsigned nak:1;
  91064. + /** ACK Response Received */
  91065. + unsigned ack:1;
  91066. + /** NYET Response Received */
  91067. + unsigned nyet:1;
  91068. + /** Transaction Err */
  91069. + unsigned xacterr:1;
  91070. + /** Babble Error */
  91071. + unsigned bblerr:1;
  91072. + /** Frame Overrun */
  91073. + unsigned frmovrun:1;
  91074. + /** Data Toggle Error */
  91075. + unsigned datatglerr:1;
  91076. + /** Buffer Not Available (only for DDMA mode) */
  91077. + unsigned bna:1;
  91078. + /** Exessive transaction error (only for DDMA mode) */
  91079. + unsigned xcs_xact:1;
  91080. + /** Frame List Rollover interrupt */
  91081. + unsigned frm_list_roll:1;
  91082. + /** Reserved */
  91083. + unsigned reserved14_31:18;
  91084. + } b;
  91085. +} hcint_data_t;
  91086. +
  91087. +/**
  91088. + * This union represents the bit fields in the Host Channel Interrupt Mask
  91089. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91090. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91091. + * hcintmsk register.
  91092. + */
  91093. +typedef union hcintmsk_data {
  91094. + /** raw register data */
  91095. + uint32_t d32;
  91096. +
  91097. + /** register bits */
  91098. + struct {
  91099. + unsigned xfercompl:1;
  91100. + unsigned chhltd:1;
  91101. + unsigned ahberr:1;
  91102. + unsigned stall:1;
  91103. + unsigned nak:1;
  91104. + unsigned ack:1;
  91105. + unsigned nyet:1;
  91106. + unsigned xacterr:1;
  91107. + unsigned bblerr:1;
  91108. + unsigned frmovrun:1;
  91109. + unsigned datatglerr:1;
  91110. + unsigned bna:1;
  91111. + unsigned xcs_xact:1;
  91112. + unsigned frm_list_roll:1;
  91113. + unsigned reserved14_31:18;
  91114. + } b;
  91115. +} hcintmsk_data_t;
  91116. +
  91117. +/**
  91118. + * This union represents the bit fields in the Host Channel Transfer Size
  91119. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91120. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  91121. + * hcchar register.
  91122. + */
  91123. +
  91124. +typedef union hctsiz_data {
  91125. + /** raw register data */
  91126. + uint32_t d32;
  91127. +
  91128. + /** register bits */
  91129. + struct {
  91130. + /** Total transfer size in bytes */
  91131. + unsigned xfersize:19;
  91132. +
  91133. + /** Data packets to transfer */
  91134. + unsigned pktcnt:10;
  91135. +
  91136. + /**
  91137. + * Packet ID for next data packet
  91138. + * 0: DATA0
  91139. + * 1: DATA2
  91140. + * 2: DATA1
  91141. + * 3: MDATA (non-Control), SETUP (Control)
  91142. + */
  91143. + unsigned pid:2;
  91144. +#define DWC_HCTSIZ_DATA0 0
  91145. +#define DWC_HCTSIZ_DATA1 2
  91146. +#define DWC_HCTSIZ_DATA2 1
  91147. +#define DWC_HCTSIZ_MDATA 3
  91148. +#define DWC_HCTSIZ_SETUP 3
  91149. +
  91150. + /** Do PING protocol when 1 */
  91151. + unsigned dopng:1;
  91152. + } b;
  91153. +
  91154. + /** register bits */
  91155. + struct {
  91156. + /** Scheduling information */
  91157. + unsigned schinfo:8;
  91158. +
  91159. + /** Number of transfer descriptors.
  91160. + * Max value:
  91161. + * 64 in general,
  91162. + * 256 only for HS isochronous endpoint.
  91163. + */
  91164. + unsigned ntd:8;
  91165. +
  91166. + /** Data packets to transfer */
  91167. + unsigned reserved16_28:13;
  91168. +
  91169. + /**
  91170. + * Packet ID for next data packet
  91171. + * 0: DATA0
  91172. + * 1: DATA2
  91173. + * 2: DATA1
  91174. + * 3: MDATA (non-Control)
  91175. + */
  91176. + unsigned pid:2;
  91177. +
  91178. + /** Do PING protocol when 1 */
  91179. + unsigned dopng:1;
  91180. + } b_ddma;
  91181. +} hctsiz_data_t;
  91182. +
  91183. +/**
  91184. + * This union represents the bit fields in the Host DMA Address
  91185. + * Register used in Descriptor DMA mode.
  91186. + */
  91187. +typedef union hcdma_data {
  91188. + /** raw register data */
  91189. + uint32_t d32;
  91190. + /** register bits */
  91191. + struct {
  91192. + unsigned reserved0_2:3;
  91193. + /** Current Transfer Descriptor. Not used for ISOC */
  91194. + unsigned ctd:8;
  91195. + /** Start Address of Descriptor List */
  91196. + unsigned dma_addr:21;
  91197. + } b;
  91198. +} hcdma_data_t;
  91199. +
  91200. +/**
  91201. + * This union represents the bit fields in the DMA Descriptor
  91202. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  91203. + * set/clear the bits using the <i>b</i>it elements.
  91204. + */
  91205. +typedef union host_dma_desc_sts {
  91206. + /** raw register data */
  91207. + uint32_t d32;
  91208. + /** quadlet bits */
  91209. +
  91210. + /* for non-isochronous */
  91211. + struct {
  91212. + /** Number of bytes */
  91213. + unsigned n_bytes:17;
  91214. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  91215. + unsigned qtd_offset:6;
  91216. + /**
  91217. + * Set to request the core to jump to alternate QTD if
  91218. + * Short Packet received - only for IN EPs
  91219. + */
  91220. + unsigned a_qtd:1;
  91221. + /**
  91222. + * Setup Packet bit. When set indicates that buffer contains
  91223. + * setup packet.
  91224. + */
  91225. + unsigned sup:1;
  91226. + /** Interrupt On Complete */
  91227. + unsigned ioc:1;
  91228. + /** End of List */
  91229. + unsigned eol:1;
  91230. + unsigned reserved27:1;
  91231. + /** Rx/Tx Status */
  91232. + unsigned sts:2;
  91233. +#define DMA_DESC_STS_PKTERR 1
  91234. + unsigned reserved30:1;
  91235. + /** Active Bit */
  91236. + unsigned a:1;
  91237. + } b;
  91238. + /* for isochronous */
  91239. + struct {
  91240. + /** Number of bytes */
  91241. + unsigned n_bytes:12;
  91242. + unsigned reserved12_24:13;
  91243. + /** Interrupt On Complete */
  91244. + unsigned ioc:1;
  91245. + unsigned reserved26_27:2;
  91246. + /** Rx/Tx Status */
  91247. + unsigned sts:2;
  91248. + unsigned reserved30:1;
  91249. + /** Active Bit */
  91250. + unsigned a:1;
  91251. + } b_isoc;
  91252. +} host_dma_desc_sts_t;
  91253. +
  91254. +#define MAX_DMA_DESC_SIZE 131071
  91255. +#define MAX_DMA_DESC_NUM_GENERIC 64
  91256. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  91257. +#define MAX_FRLIST_EN_NUM 64
  91258. +/**
  91259. + * Host-mode DMA Descriptor structure
  91260. + *
  91261. + * DMA Descriptor structure contains two quadlets:
  91262. + * Status quadlet and Data buffer pointer.
  91263. + */
  91264. +typedef struct dwc_otg_host_dma_desc {
  91265. + /** DMA Descriptor status quadlet */
  91266. + host_dma_desc_sts_t status;
  91267. + /** DMA Descriptor data buffer pointer */
  91268. + uint32_t buf;
  91269. +} dwc_otg_host_dma_desc_t;
  91270. +
  91271. +/** OTG Host Interface Structure.
  91272. + *
  91273. + * The OTG Host Interface Structure structure contains information
  91274. + * needed to manage the DWC_otg controller acting in host mode. It
  91275. + * represents the programming view of the host-specific aspects of the
  91276. + * controller.
  91277. + */
  91278. +typedef struct dwc_otg_host_if {
  91279. + /** Host Global Registers starting at offset 400h.*/
  91280. + dwc_otg_host_global_regs_t *host_global_regs;
  91281. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  91282. +
  91283. + /** Host Port 0 Control and Status Register */
  91284. + volatile uint32_t *hprt0;
  91285. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  91286. +
  91287. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  91288. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  91289. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  91290. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  91291. +
  91292. + /* Host configuration information */
  91293. + /** Number of Host Channels (range: 1-16) */
  91294. + uint8_t num_host_channels;
  91295. + /** Periodic EPs supported (0: no, 1: yes) */
  91296. + uint8_t perio_eps_supported;
  91297. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  91298. + uint16_t perio_tx_fifo_size;
  91299. +
  91300. +} dwc_otg_host_if_t;
  91301. +
  91302. +/**
  91303. + * This union represents the bit fields in the Power and Clock Gating Control
  91304. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91305. + * bits using the <i>b</i>it elements.
  91306. + */
  91307. +typedef union pcgcctl_data {
  91308. + /** raw register data */
  91309. + uint32_t d32;
  91310. +
  91311. + /** register bits */
  91312. + struct {
  91313. + /** Stop Pclk */
  91314. + unsigned stoppclk:1;
  91315. + /** Gate Hclk */
  91316. + unsigned gatehclk:1;
  91317. + /** Power Clamp */
  91318. + unsigned pwrclmp:1;
  91319. + /** Reset Power Down Modules */
  91320. + unsigned rstpdwnmodule:1;
  91321. + /** Reserved */
  91322. + unsigned reserved:1;
  91323. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  91324. + unsigned enbl_sleep_gating:1;
  91325. + /** PHY In Sleep (PhySleep) */
  91326. + unsigned phy_in_sleep:1;
  91327. + /** Deep Sleep*/
  91328. + unsigned deep_sleep:1;
  91329. + unsigned resetaftsusp:1;
  91330. + unsigned restoremode:1;
  91331. + unsigned enbl_extnd_hiber:1;
  91332. + unsigned extnd_hiber_pwrclmp:1;
  91333. + unsigned extnd_hiber_switch:1;
  91334. + unsigned ess_reg_restored:1;
  91335. + unsigned prt_clk_sel:2;
  91336. + unsigned port_power:1;
  91337. + unsigned max_xcvrselect:2;
  91338. + unsigned max_termsel:1;
  91339. + unsigned mac_dev_addr:7;
  91340. + unsigned p2hd_dev_enum_spd:2;
  91341. + unsigned p2hd_prt_spd:2;
  91342. + unsigned if_dev_mode:1;
  91343. + } b;
  91344. +} pcgcctl_data_t;
  91345. +
  91346. +/**
  91347. + * This union represents the bit fields in the Global Data FIFO Software
  91348. + * Configuration Register. Read the register into the <i>d32</i> member then
  91349. + * set/clear the bits using the <i>b</i>it elements.
  91350. + */
  91351. +typedef union gdfifocfg_data {
  91352. + /* raw register data */
  91353. + uint32_t d32;
  91354. + /** register bits */
  91355. + struct {
  91356. + /** OTG Data FIFO depth */
  91357. + unsigned gdfifocfg:16;
  91358. + /** Start address of EP info controller */
  91359. + unsigned epinfobase:16;
  91360. + } b;
  91361. +} gdfifocfg_data_t;
  91362. +
  91363. +/**
  91364. + * This union represents the bit fields in the Global Power Down Register
  91365. + * Register. Read the register into the <i>d32</i> member then set/clear the
  91366. + * bits using the <i>b</i>it elements.
  91367. + */
  91368. +typedef union gpwrdn_data {
  91369. + /* raw register data */
  91370. + uint32_t d32;
  91371. +
  91372. + /** register bits */
  91373. + struct {
  91374. + /** PMU Interrupt Select */
  91375. + unsigned pmuintsel:1;
  91376. + /** PMU Active */
  91377. + unsigned pmuactv:1;
  91378. + /** Restore */
  91379. + unsigned restore:1;
  91380. + /** Power Down Clamp */
  91381. + unsigned pwrdnclmp:1;
  91382. + /** Power Down Reset */
  91383. + unsigned pwrdnrstn:1;
  91384. + /** Power Down Switch */
  91385. + unsigned pwrdnswtch:1;
  91386. + /** Disable VBUS */
  91387. + unsigned dis_vbus:1;
  91388. + /** Line State Change */
  91389. + unsigned lnstschng:1;
  91390. + /** Line state change mask */
  91391. + unsigned lnstchng_msk:1;
  91392. + /** Reset Detected */
  91393. + unsigned rst_det:1;
  91394. + /** Reset Detect mask */
  91395. + unsigned rst_det_msk:1;
  91396. + /** Disconnect Detected */
  91397. + unsigned disconn_det:1;
  91398. + /** Disconnect Detect mask */
  91399. + unsigned disconn_det_msk:1;
  91400. + /** Connect Detected*/
  91401. + unsigned connect_det:1;
  91402. + /** Connect Detected Mask*/
  91403. + unsigned connect_det_msk:1;
  91404. + /** SRP Detected */
  91405. + unsigned srp_det:1;
  91406. + /** SRP Detect mask */
  91407. + unsigned srp_det_msk:1;
  91408. + /** Status Change Interrupt */
  91409. + unsigned sts_chngint:1;
  91410. + /** Status Change Interrupt Mask */
  91411. + unsigned sts_chngint_msk:1;
  91412. + /** Line State */
  91413. + unsigned linestate:2;
  91414. + /** Indicates current mode(status of IDDIG signal) */
  91415. + unsigned idsts:1;
  91416. + /** B Session Valid signal status*/
  91417. + unsigned bsessvld:1;
  91418. + /** ADP Event Detected */
  91419. + unsigned adp_int:1;
  91420. + /** Multi Valued ID pin */
  91421. + unsigned mult_val_id_bc:5;
  91422. + /** Reserved 24_31 */
  91423. + unsigned reserved29_31:3;
  91424. + } b;
  91425. +} gpwrdn_data_t;
  91426. +
  91427. +#endif
  91428. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/Makefile linux-3.11.10/drivers/usb/host/dwc_otg/Makefile
  91429. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  91430. +++ linux-3.11.10/drivers/usb/host/dwc_otg/Makefile 2014-02-07 19:57:30.000000000 +0100
  91431. @@ -0,0 +1,81 @@
  91432. +#
  91433. +# Makefile for DWC_otg Highspeed USB controller driver
  91434. +#
  91435. +
  91436. +ifneq ($(KERNELRELEASE),)
  91437. +
  91438. +# Use the BUS_INTERFACE variable to compile the software for either
  91439. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  91440. +ifeq ($(BUS_INTERFACE),)
  91441. +# BUS_INTERFACE = -DPCI_INTERFACE
  91442. +# BUS_INTERFACE = -DLM_INTERFACE
  91443. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  91444. +endif
  91445. +
  91446. +#EXTRA_CFLAGS += -DDEBUG
  91447. +#EXTRA_CFLAGS += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  91448. +
  91449. +# Use one of the following flags to compile the software in host-only or
  91450. +# device-only mode.
  91451. +#EXTRA_CFLAGS += -DDWC_HOST_ONLY
  91452. +#EXTRA_CFLAGS += -DDWC_DEVICE_ONLY
  91453. +
  91454. +EXTRA_CFLAGS += -Dlinux -DDWC_HS_ELECT_TST
  91455. +#EXTRA_CFLAGS += -DDWC_EN_ISOC
  91456. +EXTRA_CFLAGS += -I$(obj)/../dwc_common_port
  91457. +#EXTRA_CFLAGS += -I$(PORTLIB)
  91458. +EXTRA_CFLAGS += -DDWC_LINUX
  91459. +EXTRA_CFLAGS += $(CFI)
  91460. +EXTRA_CFLAGS += $(BUS_INTERFACE)
  91461. +#EXTRA_CFLAGS += -DDWC_DEV_SRPCAP
  91462. +
  91463. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  91464. +
  91465. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  91466. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  91467. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  91468. +dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_linux.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o dwc_otg_hcd_ddma.o
  91469. +dwc_otg-objs += dwc_otg_adp.o
  91470. +dwc_otg-objs += dwc_otg_mphi_fix.o
  91471. +ifneq ($(CFI),)
  91472. +dwc_otg-objs += dwc_otg_cfi.o
  91473. +endif
  91474. +
  91475. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  91476. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  91477. +
  91478. +ifneq ($(kernrel3),2.6.20)
  91479. +EXTRA_CFLAGS += $(CPPFLAGS)
  91480. +endif
  91481. +
  91482. +else
  91483. +
  91484. +PWD := $(shell pwd)
  91485. +PORTLIB := $(PWD)/../dwc_common_port
  91486. +
  91487. +# Command paths
  91488. +CTAGS := $(CTAGS)
  91489. +DOXYGEN := $(DOXYGEN)
  91490. +
  91491. +default: portlib
  91492. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  91493. +
  91494. +install: default
  91495. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  91496. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  91497. +
  91498. +portlib:
  91499. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  91500. + cp $(PORTLIB)/Module.symvers $(PWD)/
  91501. +
  91502. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  91503. + $(DOXYGEN) doc/doxygen.cfg
  91504. +
  91505. +tags: $(wildcard *.[hc])
  91506. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  91507. +
  91508. +
  91509. +clean:
  91510. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  91511. +
  91512. +endif
  91513. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-3.11.10/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  91514. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  91515. +++ linux-3.11.10/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-02-07 19:57:30.000000000 +0100
  91516. @@ -0,0 +1,337 @@
  91517. +package dwc_otg_test;
  91518. +
  91519. +use strict;
  91520. +use Exporter ();
  91521. +
  91522. +use vars qw(@ISA @EXPORT
  91523. +$sysfsdir $paramdir $errors $params
  91524. +);
  91525. +
  91526. +@ISA = qw(Exporter);
  91527. +
  91528. +#
  91529. +# Globals
  91530. +#
  91531. +$sysfsdir = "/sys/devices/lm0";
  91532. +$paramdir = "/sys/module/dwc_otg";
  91533. +$errors = 0;
  91534. +
  91535. +$params = [
  91536. + {
  91537. + NAME => "otg_cap",
  91538. + DEFAULT => 0,
  91539. + ENUM => [],
  91540. + LOW => 0,
  91541. + HIGH => 2
  91542. + },
  91543. + {
  91544. + NAME => "dma_enable",
  91545. + DEFAULT => 0,
  91546. + ENUM => [],
  91547. + LOW => 0,
  91548. + HIGH => 1
  91549. + },
  91550. + {
  91551. + NAME => "dma_burst_size",
  91552. + DEFAULT => 32,
  91553. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  91554. + LOW => 1,
  91555. + HIGH => 256
  91556. + },
  91557. + {
  91558. + NAME => "host_speed",
  91559. + DEFAULT => 0,
  91560. + ENUM => [],
  91561. + LOW => 0,
  91562. + HIGH => 1
  91563. + },
  91564. + {
  91565. + NAME => "host_support_fs_ls_low_power",
  91566. + DEFAULT => 0,
  91567. + ENUM => [],
  91568. + LOW => 0,
  91569. + HIGH => 1
  91570. + },
  91571. + {
  91572. + NAME => "host_ls_low_power_phy_clk",
  91573. + DEFAULT => 0,
  91574. + ENUM => [],
  91575. + LOW => 0,
  91576. + HIGH => 1
  91577. + },
  91578. + {
  91579. + NAME => "dev_speed",
  91580. + DEFAULT => 0,
  91581. + ENUM => [],
  91582. + LOW => 0,
  91583. + HIGH => 1
  91584. + },
  91585. + {
  91586. + NAME => "enable_dynamic_fifo",
  91587. + DEFAULT => 1,
  91588. + ENUM => [],
  91589. + LOW => 0,
  91590. + HIGH => 1
  91591. + },
  91592. + {
  91593. + NAME => "data_fifo_size",
  91594. + DEFAULT => 8192,
  91595. + ENUM => [],
  91596. + LOW => 32,
  91597. + HIGH => 32768
  91598. + },
  91599. + {
  91600. + NAME => "dev_rx_fifo_size",
  91601. + DEFAULT => 1064,
  91602. + ENUM => [],
  91603. + LOW => 16,
  91604. + HIGH => 32768
  91605. + },
  91606. + {
  91607. + NAME => "dev_nperio_tx_fifo_size",
  91608. + DEFAULT => 1024,
  91609. + ENUM => [],
  91610. + LOW => 16,
  91611. + HIGH => 32768
  91612. + },
  91613. + {
  91614. + NAME => "dev_perio_tx_fifo_size_1",
  91615. + DEFAULT => 256,
  91616. + ENUM => [],
  91617. + LOW => 4,
  91618. + HIGH => 768
  91619. + },
  91620. + {
  91621. + NAME => "dev_perio_tx_fifo_size_2",
  91622. + DEFAULT => 256,
  91623. + ENUM => [],
  91624. + LOW => 4,
  91625. + HIGH => 768
  91626. + },
  91627. + {
  91628. + NAME => "dev_perio_tx_fifo_size_3",
  91629. + DEFAULT => 256,
  91630. + ENUM => [],
  91631. + LOW => 4,
  91632. + HIGH => 768
  91633. + },
  91634. + {
  91635. + NAME => "dev_perio_tx_fifo_size_4",
  91636. + DEFAULT => 256,
  91637. + ENUM => [],
  91638. + LOW => 4,
  91639. + HIGH => 768
  91640. + },
  91641. + {
  91642. + NAME => "dev_perio_tx_fifo_size_5",
  91643. + DEFAULT => 256,
  91644. + ENUM => [],
  91645. + LOW => 4,
  91646. + HIGH => 768
  91647. + },
  91648. + {
  91649. + NAME => "dev_perio_tx_fifo_size_6",
  91650. + DEFAULT => 256,
  91651. + ENUM => [],
  91652. + LOW => 4,
  91653. + HIGH => 768
  91654. + },
  91655. + {
  91656. + NAME => "dev_perio_tx_fifo_size_7",
  91657. + DEFAULT => 256,
  91658. + ENUM => [],
  91659. + LOW => 4,
  91660. + HIGH => 768
  91661. + },
  91662. + {
  91663. + NAME => "dev_perio_tx_fifo_size_8",
  91664. + DEFAULT => 256,
  91665. + ENUM => [],
  91666. + LOW => 4,
  91667. + HIGH => 768
  91668. + },
  91669. + {
  91670. + NAME => "dev_perio_tx_fifo_size_9",
  91671. + DEFAULT => 256,
  91672. + ENUM => [],
  91673. + LOW => 4,
  91674. + HIGH => 768
  91675. + },
  91676. + {
  91677. + NAME => "dev_perio_tx_fifo_size_10",
  91678. + DEFAULT => 256,
  91679. + ENUM => [],
  91680. + LOW => 4,
  91681. + HIGH => 768
  91682. + },
  91683. + {
  91684. + NAME => "dev_perio_tx_fifo_size_11",
  91685. + DEFAULT => 256,
  91686. + ENUM => [],
  91687. + LOW => 4,
  91688. + HIGH => 768
  91689. + },
  91690. + {
  91691. + NAME => "dev_perio_tx_fifo_size_12",
  91692. + DEFAULT => 256,
  91693. + ENUM => [],
  91694. + LOW => 4,
  91695. + HIGH => 768
  91696. + },
  91697. + {
  91698. + NAME => "dev_perio_tx_fifo_size_13",
  91699. + DEFAULT => 256,
  91700. + ENUM => [],
  91701. + LOW => 4,
  91702. + HIGH => 768
  91703. + },
  91704. + {
  91705. + NAME => "dev_perio_tx_fifo_size_14",
  91706. + DEFAULT => 256,
  91707. + ENUM => [],
  91708. + LOW => 4,
  91709. + HIGH => 768
  91710. + },
  91711. + {
  91712. + NAME => "dev_perio_tx_fifo_size_15",
  91713. + DEFAULT => 256,
  91714. + ENUM => [],
  91715. + LOW => 4,
  91716. + HIGH => 768
  91717. + },
  91718. + {
  91719. + NAME => "host_rx_fifo_size",
  91720. + DEFAULT => 1024,
  91721. + ENUM => [],
  91722. + LOW => 16,
  91723. + HIGH => 32768
  91724. + },
  91725. + {
  91726. + NAME => "host_nperio_tx_fifo_size",
  91727. + DEFAULT => 1024,
  91728. + ENUM => [],
  91729. + LOW => 16,
  91730. + HIGH => 32768
  91731. + },
  91732. + {
  91733. + NAME => "host_perio_tx_fifo_size",
  91734. + DEFAULT => 1024,
  91735. + ENUM => [],
  91736. + LOW => 16,
  91737. + HIGH => 32768
  91738. + },
  91739. + {
  91740. + NAME => "max_transfer_size",
  91741. + DEFAULT => 65535,
  91742. + ENUM => [],
  91743. + LOW => 2047,
  91744. + HIGH => 65535
  91745. + },
  91746. + {
  91747. + NAME => "max_packet_count",
  91748. + DEFAULT => 511,
  91749. + ENUM => [],
  91750. + LOW => 15,
  91751. + HIGH => 511
  91752. + },
  91753. + {
  91754. + NAME => "host_channels",
  91755. + DEFAULT => 12,
  91756. + ENUM => [],
  91757. + LOW => 1,
  91758. + HIGH => 16
  91759. + },
  91760. + {
  91761. + NAME => "dev_endpoints",
  91762. + DEFAULT => 6,
  91763. + ENUM => [],
  91764. + LOW => 1,
  91765. + HIGH => 15
  91766. + },
  91767. + {
  91768. + NAME => "phy_type",
  91769. + DEFAULT => 1,
  91770. + ENUM => [],
  91771. + LOW => 0,
  91772. + HIGH => 2
  91773. + },
  91774. + {
  91775. + NAME => "phy_utmi_width",
  91776. + DEFAULT => 16,
  91777. + ENUM => [8, 16],
  91778. + LOW => 8,
  91779. + HIGH => 16
  91780. + },
  91781. + {
  91782. + NAME => "phy_ulpi_ddr",
  91783. + DEFAULT => 0,
  91784. + ENUM => [],
  91785. + LOW => 0,
  91786. + HIGH => 1
  91787. + },
  91788. + ];
  91789. +
  91790. +
  91791. +#
  91792. +#
  91793. +sub check_arch {
  91794. + $_ = `uname -m`;
  91795. + chomp;
  91796. + unless (m/armv4tl/) {
  91797. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  91798. + return 0;
  91799. + }
  91800. + return 1;
  91801. +}
  91802. +
  91803. +#
  91804. +#
  91805. +sub load_module {
  91806. + my $params = shift;
  91807. + print "\nRemoving Module\n";
  91808. + system "rmmod dwc_otg";
  91809. + print "Loading Module\n";
  91810. + if ($params ne "") {
  91811. + print "Module Parameters: $params\n";
  91812. + }
  91813. + if (system("modprobe dwc_otg $params")) {
  91814. + warn "Unable to load module\n";
  91815. + return 0;
  91816. + }
  91817. + return 1;
  91818. +}
  91819. +
  91820. +#
  91821. +#
  91822. +sub test_status {
  91823. + my $arg = shift;
  91824. +
  91825. + print "\n";
  91826. +
  91827. + if (defined $arg) {
  91828. + warn "WARNING: $arg\n";
  91829. + }
  91830. +
  91831. + if ($errors > 0) {
  91832. + warn "TEST FAILED with $errors errors\n";
  91833. + return 0;
  91834. + } else {
  91835. + print "TEST PASSED\n";
  91836. + return 0 if (defined $arg);
  91837. + }
  91838. + return 1;
  91839. +}
  91840. +
  91841. +#
  91842. +#
  91843. +@EXPORT = qw(
  91844. +$sysfsdir
  91845. +$paramdir
  91846. +$params
  91847. +$errors
  91848. +check_arch
  91849. +load_module
  91850. +test_status
  91851. +);
  91852. +
  91853. +1;
  91854. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/Makefile linux-3.11.10/drivers/usb/host/dwc_otg/test/Makefile
  91855. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  91856. +++ linux-3.11.10/drivers/usb/host/dwc_otg/test/Makefile 2014-02-07 19:57:30.000000000 +0100
  91857. @@ -0,0 +1,16 @@
  91858. +
  91859. +PERL=/usr/bin/perl
  91860. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  91861. +
  91862. +.PHONY : test
  91863. +test : perl_tests
  91864. +
  91865. +perl_tests :
  91866. + @echo
  91867. + @echo Running perl tests
  91868. + @for test in $(PL_TESTS); do \
  91869. + if $(PERL) ./$$test ; then \
  91870. + echo "=======> $$test, PASSED" ; \
  91871. + else echo "=======> $$test, FAILED" ; \
  91872. + fi \
  91873. + done
  91874. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-3.11.10/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  91875. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  91876. +++ linux-3.11.10/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-02-07 19:57:30.000000000 +0100
  91877. @@ -0,0 +1,133 @@
  91878. +#!/usr/bin/perl -w
  91879. +#
  91880. +# Run this program on the integrator.
  91881. +#
  91882. +# - Tests module parameter default values.
  91883. +# - Tests setting of valid module parameter values via modprobe.
  91884. +# - Tests invalid module parameter values.
  91885. +# -----------------------------------------------------------------------------
  91886. +use strict;
  91887. +use dwc_otg_test;
  91888. +
  91889. +check_arch() or die;
  91890. +
  91891. +#
  91892. +#
  91893. +sub test {
  91894. + my ($param,$expected) = @_;
  91895. + my $value = get($param);
  91896. +
  91897. + if ($value == $expected) {
  91898. + print "$param = $value, okay\n";
  91899. + }
  91900. +
  91901. + else {
  91902. + warn "ERROR: value of $param != $expected, $value\n";
  91903. + $errors ++;
  91904. + }
  91905. +}
  91906. +
  91907. +#
  91908. +#
  91909. +sub get {
  91910. + my $param = shift;
  91911. + my $tmp = `cat $paramdir/$param`;
  91912. + chomp $tmp;
  91913. + return $tmp;
  91914. +}
  91915. +
  91916. +#
  91917. +#
  91918. +sub test_main {
  91919. +
  91920. + print "\nTesting Module Parameters\n";
  91921. +
  91922. + load_module("") or die;
  91923. +
  91924. + # Test initial values
  91925. + print "\nTesting Default Values\n";
  91926. + foreach (@{$params}) {
  91927. + test ($_->{NAME}, $_->{DEFAULT});
  91928. + }
  91929. +
  91930. + # Test low value
  91931. + print "\nTesting Low Value\n";
  91932. + my $cmd_params = "";
  91933. + foreach (@{$params}) {
  91934. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  91935. + }
  91936. + load_module($cmd_params) or die;
  91937. +
  91938. + foreach (@{$params}) {
  91939. + test ($_->{NAME}, $_->{LOW});
  91940. + }
  91941. +
  91942. + # Test high value
  91943. + print "\nTesting High Value\n";
  91944. + $cmd_params = "";
  91945. + foreach (@{$params}) {
  91946. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  91947. + }
  91948. + load_module($cmd_params) or die;
  91949. +
  91950. + foreach (@{$params}) {
  91951. + test ($_->{NAME}, $_->{HIGH});
  91952. + }
  91953. +
  91954. + # Test Enum
  91955. + print "\nTesting Enumerated\n";
  91956. + foreach (@{$params}) {
  91957. + if (defined $_->{ENUM}) {
  91958. + my $value;
  91959. + foreach $value (@{$_->{ENUM}}) {
  91960. + $cmd_params = "$_->{NAME}=$value";
  91961. + load_module($cmd_params) or die;
  91962. + test ($_->{NAME}, $value);
  91963. + }
  91964. + }
  91965. + }
  91966. +
  91967. + # Test Invalid Values
  91968. + print "\nTesting Invalid Values\n";
  91969. + $cmd_params = "";
  91970. + foreach (@{$params}) {
  91971. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  91972. + }
  91973. + load_module($cmd_params) or die;
  91974. +
  91975. + foreach (@{$params}) {
  91976. + test ($_->{NAME}, $_->{DEFAULT});
  91977. + }
  91978. +
  91979. + $cmd_params = "";
  91980. + foreach (@{$params}) {
  91981. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  91982. + }
  91983. + load_module($cmd_params) or die;
  91984. +
  91985. + foreach (@{$params}) {
  91986. + test ($_->{NAME}, $_->{DEFAULT});
  91987. + }
  91988. +
  91989. + print "\nTesting Enumerated\n";
  91990. + foreach (@{$params}) {
  91991. + if (defined $_->{ENUM}) {
  91992. + my $value;
  91993. + foreach $value (@{$_->{ENUM}}) {
  91994. + $value = $value + 1;
  91995. + $cmd_params = "$_->{NAME}=$value";
  91996. + load_module($cmd_params) or die;
  91997. + test ($_->{NAME}, $_->{DEFAULT});
  91998. + $value = $value - 2;
  91999. + $cmd_params = "$_->{NAME}=$value";
  92000. + load_module($cmd_params) or die;
  92001. + test ($_->{NAME}, $_->{DEFAULT});
  92002. + }
  92003. + }
  92004. + }
  92005. +
  92006. + test_status() or die;
  92007. +}
  92008. +
  92009. +test_main();
  92010. +0;
  92011. diff -Nur linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-3.11.10/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  92012. --- linux-3.11.10.orig/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  92013. +++ linux-3.11.10/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-02-07 19:57:30.000000000 +0100
  92014. @@ -0,0 +1,193 @@
  92015. +#!/usr/bin/perl -w
  92016. +#
  92017. +# Run this program on the integrator
  92018. +# - Tests select sysfs attributes.
  92019. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  92020. +# -----------------------------------------------------------------------------
  92021. +use strict;
  92022. +use dwc_otg_test;
  92023. +
  92024. +check_arch() or die;
  92025. +
  92026. +#
  92027. +#
  92028. +sub test {
  92029. + my ($attr,$expected) = @_;
  92030. + my $string = get($attr);
  92031. +
  92032. + if ($string eq $expected) {
  92033. + printf("$attr = $string, okay\n");
  92034. + }
  92035. + else {
  92036. + warn "ERROR: value of $attr != $expected, $string\n";
  92037. + $errors ++;
  92038. + }
  92039. +}
  92040. +
  92041. +#
  92042. +#
  92043. +sub set {
  92044. + my ($reg, $value) = @_;
  92045. + system "echo $value > $sysfsdir/$reg";
  92046. +}
  92047. +
  92048. +#
  92049. +#
  92050. +sub get {
  92051. + my $attr = shift;
  92052. + my $string = `cat $sysfsdir/$attr`;
  92053. + chomp $string;
  92054. + if ($string =~ m/\s\=\s/) {
  92055. + my $tmp;
  92056. + ($tmp, $string) = split /\s=\s/, $string;
  92057. + }
  92058. + return $string;
  92059. +}
  92060. +
  92061. +#
  92062. +#
  92063. +sub test_main {
  92064. + print("\nTesting Sysfs Attributes\n");
  92065. +
  92066. + load_module("") or die;
  92067. +
  92068. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  92069. + print("\nTesting Default Values\n");
  92070. +
  92071. + test("regoffset", "0xffffffff");
  92072. + test("regvalue", "invalid offset");
  92073. + test("guid", "0x12345678"); # this will fail if it has been changed
  92074. + test("gsnpsid", "0x4f54200a");
  92075. +
  92076. + # Test operation of regoffset/regvalue
  92077. + print("\nTesting regoffset\n");
  92078. + set('regoffset', '5a5a5a5a');
  92079. + test("regoffset", "0xffffffff");
  92080. +
  92081. + set('regoffset', '0');
  92082. + test("regoffset", "0x00000000");
  92083. +
  92084. + set('regoffset', '40000');
  92085. + test("regoffset", "0x00000000");
  92086. +
  92087. + set('regoffset', '3ffff');
  92088. + test("regoffset", "0x0003ffff");
  92089. +
  92090. + set('regoffset', '1');
  92091. + test("regoffset", "0x00000001");
  92092. +
  92093. + print("\nTesting regvalue\n");
  92094. + set('regoffset', '3c');
  92095. + test("regvalue", "0x12345678");
  92096. + set('regvalue', '5a5a5a5a');
  92097. + test("regvalue", "0x5a5a5a5a");
  92098. + set('regvalue','a5a5a5a5');
  92099. + test("regvalue", "0xa5a5a5a5");
  92100. + set('guid','12345678');
  92101. +
  92102. + # Test HNP Capable
  92103. + print("\nTesting HNP Capable bit\n");
  92104. + set('hnpcapable', '1');
  92105. + test("hnpcapable", "0x1");
  92106. + set('hnpcapable','0');
  92107. + test("hnpcapable", "0x0");
  92108. +
  92109. + set('regoffset','0c');
  92110. +
  92111. + my $old = get('gusbcfg');
  92112. + print("setting hnpcapable\n");
  92113. + set('hnpcapable', '1');
  92114. + test("hnpcapable", "0x1");
  92115. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  92116. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  92117. +
  92118. + $old = get('gusbcfg');
  92119. + print("clearing hnpcapable\n");
  92120. + set('hnpcapable', '0');
  92121. + test("hnpcapable", "0x0");
  92122. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  92123. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  92124. +
  92125. + # Test SRP Capable
  92126. + print("\nTesting SRP Capable bit\n");
  92127. + set('srpcapable', '1');
  92128. + test("srpcapable", "0x1");
  92129. + set('srpcapable','0');
  92130. + test("srpcapable", "0x0");
  92131. +
  92132. + set('regoffset','0c');
  92133. +
  92134. + $old = get('gusbcfg');
  92135. + print("setting srpcapable\n");
  92136. + set('srpcapable', '1');
  92137. + test("srpcapable", "0x1");
  92138. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  92139. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  92140. +
  92141. + $old = get('gusbcfg');
  92142. + print("clearing srpcapable\n");
  92143. + set('srpcapable', '0');
  92144. + test("srpcapable", "0x0");
  92145. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  92146. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  92147. +
  92148. + # Test GGPIO
  92149. + print("\nTesting GGPIO\n");
  92150. + set('ggpio','5a5a5a5a');
  92151. + test('ggpio','0x5a5a0000');
  92152. + set('ggpio','a5a5a5a5');
  92153. + test('ggpio','0xa5a50000');
  92154. + set('ggpio','11110000');
  92155. + test('ggpio','0x11110000');
  92156. + set('ggpio','00001111');
  92157. + test('ggpio','0x00000000');
  92158. +
  92159. + # Test DEVSPEED
  92160. + print("\nTesting DEVSPEED\n");
  92161. + set('regoffset','800');
  92162. + $old = get('regvalue');
  92163. + set('devspeed','0');
  92164. + test('devspeed','0x0');
  92165. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  92166. + set('devspeed','1');
  92167. + test('devspeed','0x1');
  92168. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  92169. + set('devspeed','2');
  92170. + test('devspeed','0x2');
  92171. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  92172. + set('devspeed','3');
  92173. + test('devspeed','0x3');
  92174. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  92175. + set('devspeed','4');
  92176. + test('devspeed','0x0');
  92177. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  92178. + set('devspeed','5');
  92179. + test('devspeed','0x1');
  92180. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  92181. +
  92182. +
  92183. + # mode Returns the current mode:0 for device mode1 for host mode Read
  92184. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  92185. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  92186. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  92187. + # bussuspend Suspend the USB bus. Read/Write
  92188. + # busconnected Get the connection status of the bus Read
  92189. +
  92190. + # gotgctl Get or set the Core Control Status Register. Read/Write
  92191. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  92192. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  92193. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  92194. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  92195. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  92196. + ## guid Get or set the value of the User ID Register Read/Write
  92197. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  92198. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  92199. + # enumspeed Gets the device enumeration Speed. Read
  92200. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  92201. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  92202. +
  92203. + test_status("TEST NYI") or die;
  92204. +}
  92205. +
  92206. +test_main();
  92207. +0;
  92208. diff -Nur linux-3.11.10.orig/drivers/usb/host/Kconfig linux-3.11.10/drivers/usb/host/Kconfig
  92209. --- linux-3.11.10.orig/drivers/usb/host/Kconfig 2013-11-29 19:42:37.000000000 +0100
  92210. +++ linux-3.11.10/drivers/usb/host/Kconfig 2014-02-07 19:57:30.000000000 +0100
  92211. @@ -671,6 +671,19 @@
  92212. To compile this driver a module, choose M here: the module
  92213. will be called "hwa-hc".
  92214. +config USB_DWCOTG
  92215. + tristate "Synopsis DWC host support"
  92216. + depends on USB
  92217. + help
  92218. + The Synopsis DWC controller is a dual-role
  92219. + host/peripheral/OTG ("On The Go") USB controllers.
  92220. +
  92221. + Enable this option to support this IP in host controller mode.
  92222. + If unsure, say N.
  92223. +
  92224. + To compile this driver as a module, choose M here: the
  92225. + modules built will be called dwc_otg and dwc_common_port.
  92226. +
  92227. config USB_IMX21_HCD
  92228. tristate "i.MX21 HCD support"
  92229. depends on ARM && ARCH_MXC
  92230. diff -Nur linux-3.11.10.orig/drivers/usb/host/Makefile linux-3.11.10/drivers/usb/host/Makefile
  92231. --- linux-3.11.10.orig/drivers/usb/host/Makefile 2013-11-29 19:42:37.000000000 +0100
  92232. +++ linux-3.11.10/drivers/usb/host/Makefile 2014-02-07 19:57:30.000000000 +0100
  92233. @@ -52,6 +52,8 @@
  92234. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  92235. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  92236. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  92237. +
  92238. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  92239. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  92240. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  92241. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  92242. diff -Nur linux-3.11.10.orig/drivers/usb/Makefile linux-3.11.10/drivers/usb/Makefile
  92243. --- linux-3.11.10.orig/drivers/usb/Makefile 2013-11-29 19:42:37.000000000 +0100
  92244. +++ linux-3.11.10/drivers/usb/Makefile 2014-02-07 19:57:30.000000000 +0100
  92245. @@ -23,6 +23,7 @@
  92246. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  92247. obj-$(CONFIG_USB_HWA_HCD) += host/
  92248. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  92249. +obj-$(CONFIG_USB_DWCOTG) += host/
  92250. obj-$(CONFIG_USB_IMX21_HCD) += host/
  92251. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  92252. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  92253. diff -Nur linux-3.11.10.orig/drivers/video/bcm2708_fb.c linux-3.11.10/drivers/video/bcm2708_fb.c
  92254. --- linux-3.11.10.orig/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  92255. +++ linux-3.11.10/drivers/video/bcm2708_fb.c 2014-02-07 19:57:30.000000000 +0100
  92256. @@ -0,0 +1,647 @@
  92257. +/*
  92258. + * linux/drivers/video/bcm2708_fb.c
  92259. + *
  92260. + * Copyright (C) 2010 Broadcom
  92261. + *
  92262. + * This file is subject to the terms and conditions of the GNU General Public
  92263. + * License. See the file COPYING in the main directory of this archive
  92264. + * for more details.
  92265. + *
  92266. + * Broadcom simple framebuffer driver
  92267. + *
  92268. + * This file is derived from cirrusfb.c
  92269. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  92270. + *
  92271. + */
  92272. +#include <linux/module.h>
  92273. +#include <linux/kernel.h>
  92274. +#include <linux/errno.h>
  92275. +#include <linux/string.h>
  92276. +#include <linux/slab.h>
  92277. +#include <linux/mm.h>
  92278. +#include <linux/fb.h>
  92279. +#include <linux/init.h>
  92280. +#include <linux/ioport.h>
  92281. +#include <linux/list.h>
  92282. +#include <linux/platform_device.h>
  92283. +#include <linux/clk.h>
  92284. +#include <linux/printk.h>
  92285. +#include <linux/console.h>
  92286. +
  92287. +#include <mach/dma.h>
  92288. +#include <mach/platform.h>
  92289. +#include <mach/vcio.h>
  92290. +
  92291. +#include <asm/sizes.h>
  92292. +#include <linux/io.h>
  92293. +#include <linux/dma-mapping.h>
  92294. +
  92295. +#ifdef BCM2708_FB_DEBUG
  92296. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  92297. +#else
  92298. +#define print_debug(fmt,...)
  92299. +#endif
  92300. +
  92301. +/* This is limited to 16 characters when displayed by X startup */
  92302. +static const char *bcm2708_name = "BCM2708 FB";
  92303. +
  92304. +#define DRIVER_NAME "bcm2708_fb"
  92305. +
  92306. +/* this data structure describes each frame buffer device we find */
  92307. +
  92308. +struct fbinfo_s {
  92309. + u32 xres, yres, xres_virtual, yres_virtual;
  92310. + u32 pitch, bpp;
  92311. + u32 xoffset, yoffset;
  92312. + u32 base;
  92313. + u32 screen_size;
  92314. + u16 cmap[256];
  92315. +};
  92316. +
  92317. +struct bcm2708_fb {
  92318. + struct fb_info fb;
  92319. + struct platform_device *dev;
  92320. + struct fbinfo_s *info;
  92321. + dma_addr_t dma;
  92322. + u32 cmap[16];
  92323. + int dma_chan;
  92324. + int dma_irq;
  92325. + void __iomem *dma_chan_base;
  92326. + void *cb_base; /* DMA control blocks */
  92327. + dma_addr_t cb_handle;
  92328. +};
  92329. +
  92330. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  92331. +
  92332. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  92333. +{
  92334. + int ret = 0;
  92335. +
  92336. + memset(&var->transp, 0, sizeof(var->transp));
  92337. +
  92338. + var->red.msb_right = 0;
  92339. + var->green.msb_right = 0;
  92340. + var->blue.msb_right = 0;
  92341. +
  92342. + switch (var->bits_per_pixel) {
  92343. + case 1:
  92344. + case 2:
  92345. + case 4:
  92346. + case 8:
  92347. + var->red.length = var->bits_per_pixel;
  92348. + var->red.offset = 0;
  92349. + var->green.length = var->bits_per_pixel;
  92350. + var->green.offset = 0;
  92351. + var->blue.length = var->bits_per_pixel;
  92352. + var->blue.offset = 0;
  92353. + break;
  92354. + case 16:
  92355. + var->red.length = 5;
  92356. + var->blue.length = 5;
  92357. + /*
  92358. + * Green length can be 5 or 6 depending whether
  92359. + * we're operating in RGB555 or RGB565 mode.
  92360. + */
  92361. + if (var->green.length != 5 && var->green.length != 6)
  92362. + var->green.length = 6;
  92363. + break;
  92364. + case 24:
  92365. + var->red.length = 8;
  92366. + var->blue.length = 8;
  92367. + var->green.length = 8;
  92368. + break;
  92369. + case 32:
  92370. + var->red.length = 8;
  92371. + var->green.length = 8;
  92372. + var->blue.length = 8;
  92373. + var->transp.length = 8;
  92374. + break;
  92375. + default:
  92376. + ret = -EINVAL;
  92377. + break;
  92378. + }
  92379. +
  92380. + /*
  92381. + * >= 16bpp displays have separate colour component bitfields
  92382. + * encoded in the pixel data. Calculate their position from
  92383. + * the bitfield length defined above.
  92384. + */
  92385. + if (ret == 0 && var->bits_per_pixel >= 24) {
  92386. + var->red.offset = 0;
  92387. + var->green.offset = var->red.offset + var->red.length;
  92388. + var->blue.offset = var->green.offset + var->green.length;
  92389. + var->transp.offset = var->blue.offset + var->blue.length;
  92390. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  92391. + var->blue.offset = 0;
  92392. + var->green.offset = var->blue.offset + var->blue.length;
  92393. + var->red.offset = var->green.offset + var->green.length;
  92394. + var->transp.offset = var->red.offset + var->red.length;
  92395. + }
  92396. +
  92397. + return ret;
  92398. +}
  92399. +
  92400. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  92401. + struct fb_info *info)
  92402. +{
  92403. + /* info input, var output */
  92404. + int yres;
  92405. +
  92406. + /* info input, var output */
  92407. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  92408. + info->var.xres, info->var.yres, info->var.xres_virtual,
  92409. + info->var.yres_virtual, (int)info->screen_size,
  92410. + info->var.bits_per_pixel);
  92411. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  92412. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  92413. + var->bits_per_pixel);
  92414. +
  92415. + if (!var->bits_per_pixel)
  92416. + var->bits_per_pixel = 16;
  92417. +
  92418. + if (bcm2708_fb_set_bitfields(var) != 0) {
  92419. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  92420. + var->bits_per_pixel);
  92421. + return -EINVAL;
  92422. + }
  92423. +
  92424. +
  92425. + if (var->xres_virtual < var->xres)
  92426. + var->xres_virtual = var->xres;
  92427. + /* use highest possible virtual resolution */
  92428. + if (var->yres_virtual == -1) {
  92429. + var->yres_virtual = 480;
  92430. +
  92431. + pr_err
  92432. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  92433. + var->xres_virtual, var->yres_virtual);
  92434. + }
  92435. + if (var->yres_virtual < var->yres)
  92436. + var->yres_virtual = var->yres;
  92437. +
  92438. + if (var->xoffset < 0)
  92439. + var->xoffset = 0;
  92440. + if (var->yoffset < 0)
  92441. + var->yoffset = 0;
  92442. +
  92443. + /* truncate xoffset and yoffset to maximum if too high */
  92444. + if (var->xoffset > var->xres_virtual - var->xres)
  92445. + var->xoffset = var->xres_virtual - var->xres - 1;
  92446. + if (var->yoffset > var->yres_virtual - var->yres)
  92447. + var->yoffset = var->yres_virtual - var->yres - 1;
  92448. +
  92449. + yres = var->yres;
  92450. + if (var->vmode & FB_VMODE_DOUBLE)
  92451. + yres *= 2;
  92452. + else if (var->vmode & FB_VMODE_INTERLACED)
  92453. + yres = (yres + 1) / 2;
  92454. +
  92455. + if (yres > 1200) {
  92456. + pr_err("bcm2708_fb_check_var: ERROR: VerticalTotal >= 1200; "
  92457. + "special treatment required! (TODO)\n");
  92458. + return -EINVAL;
  92459. + }
  92460. +
  92461. + return 0;
  92462. +}
  92463. +
  92464. +static int bcm2708_fb_set_par(struct fb_info *info)
  92465. +{
  92466. + uint32_t val = 0;
  92467. + struct bcm2708_fb *fb = to_bcm2708(info);
  92468. + volatile struct fbinfo_s *fbinfo = fb->info;
  92469. + fbinfo->xres = info->var.xres;
  92470. + fbinfo->yres = info->var.yres;
  92471. + fbinfo->xres_virtual = info->var.xres_virtual;
  92472. + fbinfo->yres_virtual = info->var.yres_virtual;
  92473. + fbinfo->bpp = info->var.bits_per_pixel;
  92474. + fbinfo->xoffset = info->var.xoffset;
  92475. + fbinfo->yoffset = info->var.yoffset;
  92476. + fbinfo->base = 0; /* filled in by VC */
  92477. + fbinfo->pitch = 0; /* filled in by VC */
  92478. +
  92479. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  92480. + info->var.xres, info->var.yres, info->var.xres_virtual,
  92481. + info->var.yres_virtual, (int)info->screen_size,
  92482. + info->var.bits_per_pixel);
  92483. +
  92484. + /* ensure last write to fbinfo is visible to GPU */
  92485. + wmb();
  92486. +
  92487. + /* inform vc about new framebuffer */
  92488. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  92489. +
  92490. + /* TODO: replace fb driver with vchiq version */
  92491. + /* wait for response */
  92492. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  92493. +
  92494. + /* ensure GPU writes are visible to us */
  92495. + rmb();
  92496. +
  92497. + if (val == 0) {
  92498. + fb->fb.fix.line_length = fbinfo->pitch;
  92499. +
  92500. + if (info->var.bits_per_pixel <= 8)
  92501. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  92502. + else
  92503. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  92504. +
  92505. + fb->fb.fix.smem_start = fbinfo->base;
  92506. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  92507. + fb->fb.screen_size = fbinfo->screen_size;
  92508. + if (fb->fb.screen_base)
  92509. + iounmap(fb->fb.screen_base);
  92510. + fb->fb.screen_base =
  92511. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  92512. + if (!fb->fb.screen_base) {
  92513. + /* the console may currently be locked */
  92514. + console_trylock();
  92515. + console_unlock();
  92516. +
  92517. + BUG(); /* what can we do here */
  92518. + }
  92519. + }
  92520. + print_debug
  92521. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  92522. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  92523. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  92524. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  92525. +
  92526. + return val;
  92527. +}
  92528. +
  92529. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  92530. +{
  92531. + unsigned int mask = (1 << bf->length) - 1;
  92532. +
  92533. + return (val >> (16 - bf->length) & mask) << bf->offset;
  92534. +}
  92535. +
  92536. +
  92537. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  92538. + unsigned int green, unsigned int blue,
  92539. + unsigned int transp, struct fb_info *info)
  92540. +{
  92541. + struct bcm2708_fb *fb = to_bcm2708(info);
  92542. +
  92543. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  92544. + if (fb->fb.var.bits_per_pixel <= 8) {
  92545. + if (regno < 256) {
  92546. + /* blue [0:4], green [5:10], red [11:15] */
  92547. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  92548. + ((green >> (16-6)) & 0x3f) << 5 |
  92549. + ((blue >> (16-5)) & 0x1f) << 0;
  92550. + }
  92551. + /* Hack: we need to tell GPU the palette has changed, but currently bcm2708_fb_set_par takes noticable time when called for every (256) colour */
  92552. + /* So just call it for what looks like the last colour in a list for now. */
  92553. + if (regno == 15 || regno == 255)
  92554. + bcm2708_fb_set_par(info);
  92555. + } else if (regno < 16) {
  92556. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  92557. + convert_bitfield(blue, &fb->fb.var.blue) |
  92558. + convert_bitfield(green, &fb->fb.var.green) |
  92559. + convert_bitfield(red, &fb->fb.var.red);
  92560. + }
  92561. + return regno > 255;
  92562. +}
  92563. +
  92564. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  92565. +{
  92566. + /*print_debug("bcm2708_fb_blank\n"); */
  92567. + return -1;
  92568. +}
  92569. +
  92570. +static void bcm2708_fb_fillrect(struct fb_info *info,
  92571. + const struct fb_fillrect *rect)
  92572. +{
  92573. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  92574. + cfb_fillrect(info, rect);
  92575. +}
  92576. +
  92577. +/* A helper function for configuring dma control block */
  92578. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  92579. + int burst_size,
  92580. + dma_addr_t dst,
  92581. + int dst_stride,
  92582. + dma_addr_t src,
  92583. + int src_stride,
  92584. + int w,
  92585. + int h)
  92586. +{
  92587. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  92588. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  92589. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  92590. + cb->dst = dst;
  92591. + cb->src = src;
  92592. + /*
  92593. + * This is not really obvious from the DMA documentation,
  92594. + * but the top 16 bits must be programmmed to "height -1"
  92595. + * and not "height" in 2D mode.
  92596. + */
  92597. + cb->length = ((h - 1) << 16) | w;
  92598. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  92599. + cb->pad[0] = 0;
  92600. + cb->pad[1] = 0;
  92601. +}
  92602. +
  92603. +static void bcm2708_fb_copyarea(struct fb_info *info,
  92604. + const struct fb_copyarea *region)
  92605. +{
  92606. + struct bcm2708_fb *fb = to_bcm2708(info);
  92607. + struct bcm2708_dma_cb *cb = fb->cb_base;
  92608. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  92609. + /* Channel 0 supports larger bursts and is a bit faster */
  92610. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  92611. +
  92612. + /* Fallback to cfb_copyarea() if we don't like something */
  92613. + if (bytes_per_pixel > 4 ||
  92614. + info->var.xres > 1920 || info->var.yres > 1200 ||
  92615. + region->width <= 0 || region->width > info->var.xres ||
  92616. + region->height <= 0 || region->height > info->var.yres ||
  92617. + region->sx < 0 || region->sx >= info->var.xres ||
  92618. + region->sy < 0 || region->sy >= info->var.yres ||
  92619. + region->dx < 0 || region->dx >= info->var.xres ||
  92620. + region->dy < 0 || region->dy >= info->var.yres ||
  92621. + region->sx + region->width > info->var.xres ||
  92622. + region->dx + region->width > info->var.xres ||
  92623. + region->sy + region->height > info->var.yres ||
  92624. + region->dy + region->height > info->var.yres) {
  92625. + cfb_copyarea(info, region);
  92626. + return;
  92627. + }
  92628. +
  92629. + if (region->dy == region->sy && region->dx > region->sx) {
  92630. + /*
  92631. + * A difficult case of overlapped copy. Because DMA can't
  92632. + * copy individual scanlines in backwards direction, we need
  92633. + * two-pass processing. We do it by programming a chain of dma
  92634. + * control blocks in the first 16K part of the buffer and use
  92635. + * the remaining 48K as the intermediate temporary scratch
  92636. + * buffer. The buffer size is sufficient to handle up to
  92637. + * 1920x1200 resolution at 32bpp pixel depth.
  92638. + */
  92639. + int y;
  92640. + dma_addr_t control_block_pa = fb->cb_handle;
  92641. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  92642. + int scanline_size = bytes_per_pixel * region->width;
  92643. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  92644. +
  92645. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  92646. + dma_addr_t src =
  92647. + fb->fb.fix.smem_start +
  92648. + bytes_per_pixel * region->sx +
  92649. + (region->sy + y) * fb->fb.fix.line_length;
  92650. + dma_addr_t dst =
  92651. + fb->fb.fix.smem_start +
  92652. + bytes_per_pixel * region->dx +
  92653. + (region->dy + y) * fb->fb.fix.line_length;
  92654. +
  92655. + if (region->height - y < scanlines_per_cb)
  92656. + scanlines_per_cb = region->height - y;
  92657. +
  92658. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  92659. + src, fb->fb.fix.line_length,
  92660. + scanline_size, scanlines_per_cb);
  92661. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  92662. + cb->next = control_block_pa;
  92663. + cb++;
  92664. +
  92665. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  92666. + scratchbuf, scanline_size,
  92667. + scanline_size, scanlines_per_cb);
  92668. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  92669. + cb->next = control_block_pa;
  92670. + cb++;
  92671. + }
  92672. + /* move the pointer back to the last dma control block */
  92673. + cb--;
  92674. + } else {
  92675. + /* A single dma control block is enough. */
  92676. + int sy, dy, stride;
  92677. + if (region->dy <= region->sy) {
  92678. + /* processing from top to bottom */
  92679. + dy = region->dy;
  92680. + sy = region->sy;
  92681. + stride = fb->fb.fix.line_length;
  92682. + } else {
  92683. + /* processing from bottom to top */
  92684. + dy = region->dy + region->height - 1;
  92685. + sy = region->sy + region->height - 1;
  92686. + stride = -fb->fb.fix.line_length;
  92687. + }
  92688. + set_dma_cb(cb, burst_size,
  92689. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  92690. + bytes_per_pixel * region->dx,
  92691. + stride,
  92692. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  92693. + bytes_per_pixel * region->sx,
  92694. + stride,
  92695. + region->width * bytes_per_pixel,
  92696. + region->height);
  92697. + }
  92698. +
  92699. + /* end of dma control blocks chain */
  92700. + cb->next = 0;
  92701. +
  92702. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  92703. + bcm_dma_wait_idle(fb->dma_chan_base);
  92704. +}
  92705. +
  92706. +static void bcm2708_fb_imageblit(struct fb_info *info,
  92707. + const struct fb_image *image)
  92708. +{
  92709. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  92710. + cfb_imageblit(info, image);
  92711. +}
  92712. +
  92713. +static struct fb_ops bcm2708_fb_ops = {
  92714. + .owner = THIS_MODULE,
  92715. + .fb_check_var = bcm2708_fb_check_var,
  92716. + .fb_set_par = bcm2708_fb_set_par,
  92717. + .fb_setcolreg = bcm2708_fb_setcolreg,
  92718. + .fb_blank = bcm2708_fb_blank,
  92719. + .fb_fillrect = bcm2708_fb_fillrect,
  92720. + .fb_copyarea = bcm2708_fb_copyarea,
  92721. + .fb_imageblit = bcm2708_fb_imageblit,
  92722. +};
  92723. +
  92724. +static int fbwidth = 800; /* module parameter */
  92725. +static int fbheight = 480; /* module parameter */
  92726. +static int fbdepth = 16; /* module parameter */
  92727. +
  92728. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  92729. +{
  92730. + int ret;
  92731. + dma_addr_t dma;
  92732. + void *mem;
  92733. +
  92734. + mem =
  92735. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  92736. + GFP_KERNEL);
  92737. +
  92738. + if (NULL == mem) {
  92739. + pr_err(": unable to allocate fbinfo buffer\n");
  92740. + ret = -ENOMEM;
  92741. + } else {
  92742. + fb->info = (struct fbinfo_s *)mem;
  92743. + fb->dma = dma;
  92744. + }
  92745. + fb->fb.fbops = &bcm2708_fb_ops;
  92746. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  92747. + fb->fb.pseudo_palette = fb->cmap;
  92748. +
  92749. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  92750. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  92751. + fb->fb.fix.type_aux = 0;
  92752. + fb->fb.fix.xpanstep = 0;
  92753. + fb->fb.fix.ypanstep = 0;
  92754. + fb->fb.fix.ywrapstep = 0;
  92755. + fb->fb.fix.accel = FB_ACCEL_NONE;
  92756. +
  92757. + fb->fb.var.xres = fbwidth;
  92758. + fb->fb.var.yres = fbheight;
  92759. + fb->fb.var.xres_virtual = fbwidth;
  92760. + fb->fb.var.yres_virtual = fbheight;
  92761. + fb->fb.var.bits_per_pixel = fbdepth;
  92762. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  92763. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  92764. + fb->fb.var.nonstd = 0;
  92765. + fb->fb.var.height = -1; /* height of picture in mm */
  92766. + fb->fb.var.width = -1; /* width of picture in mm */
  92767. + fb->fb.var.accel_flags = 0;
  92768. +
  92769. + fb->fb.monspecs.hfmin = 0;
  92770. + fb->fb.monspecs.hfmax = 100000;
  92771. + fb->fb.monspecs.vfmin = 0;
  92772. + fb->fb.monspecs.vfmax = 400;
  92773. + fb->fb.monspecs.dclkmin = 1000000;
  92774. + fb->fb.monspecs.dclkmax = 100000000;
  92775. +
  92776. + bcm2708_fb_set_bitfields(&fb->fb.var);
  92777. +
  92778. + /*
  92779. + * Allocate colourmap.
  92780. + */
  92781. +
  92782. + fb_set_var(&fb->fb, &fb->fb.var);
  92783. +
  92784. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d)\n", fbwidth,
  92785. + fbheight, fbdepth);
  92786. +
  92787. + ret = register_framebuffer(&fb->fb);
  92788. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  92789. + if (ret == 0)
  92790. + goto out;
  92791. +
  92792. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  92793. +out:
  92794. + return ret;
  92795. +}
  92796. +
  92797. +static int bcm2708_fb_probe(struct platform_device *dev)
  92798. +{
  92799. + struct bcm2708_fb *fb;
  92800. + int ret;
  92801. +
  92802. + fb = kmalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  92803. + if (!fb) {
  92804. + dev_err(&dev->dev,
  92805. + "could not allocate new bcm2708_fb struct\n");
  92806. + ret = -ENOMEM;
  92807. + goto free_region;
  92808. + }
  92809. + memset(fb, 0, sizeof(struct bcm2708_fb));
  92810. +
  92811. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  92812. + &fb->cb_handle, GFP_KERNEL);
  92813. + if (!fb->cb_base) {
  92814. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  92815. + ret = -ENOMEM;
  92816. + goto free_fb;
  92817. + }
  92818. +
  92819. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  92820. + fb->cb_handle);
  92821. +
  92822. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  92823. + &fb->dma_chan_base, &fb->dma_irq);
  92824. + if (ret < 0) {
  92825. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  92826. + goto free_cb;
  92827. + }
  92828. + fb->dma_chan = ret;
  92829. +
  92830. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  92831. + fb->dma_chan, fb->dma_chan_base);
  92832. +
  92833. + fb->dev = dev;
  92834. +
  92835. + ret = bcm2708_fb_register(fb);
  92836. + if (ret == 0) {
  92837. + platform_set_drvdata(dev, fb);
  92838. + goto out;
  92839. + }
  92840. +
  92841. +free_cb:
  92842. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  92843. +free_fb:
  92844. + kfree(fb);
  92845. +free_region:
  92846. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  92847. +out:
  92848. + return ret;
  92849. +}
  92850. +
  92851. +static int bcm2708_fb_remove(struct platform_device *dev)
  92852. +{
  92853. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  92854. +
  92855. + platform_set_drvdata(dev, NULL);
  92856. +
  92857. + if (fb->fb.screen_base)
  92858. + iounmap(fb->fb.screen_base);
  92859. + unregister_framebuffer(&fb->fb);
  92860. +
  92861. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  92862. + bcm_dma_chan_free(fb->dma_chan);
  92863. +
  92864. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  92865. + fb->dma);
  92866. + kfree(fb);
  92867. +
  92868. + return 0;
  92869. +}
  92870. +
  92871. +static struct platform_driver bcm2708_fb_driver = {
  92872. + .probe = bcm2708_fb_probe,
  92873. + .remove = bcm2708_fb_remove,
  92874. + .driver = {
  92875. + .name = DRIVER_NAME,
  92876. + .owner = THIS_MODULE,
  92877. + },
  92878. +};
  92879. +
  92880. +static int __init bcm2708_fb_init(void)
  92881. +{
  92882. + return platform_driver_register(&bcm2708_fb_driver);
  92883. +}
  92884. +
  92885. +module_init(bcm2708_fb_init);
  92886. +
  92887. +static void __exit bcm2708_fb_exit(void)
  92888. +{
  92889. + platform_driver_unregister(&bcm2708_fb_driver);
  92890. +}
  92891. +
  92892. +module_exit(bcm2708_fb_exit);
  92893. +
  92894. +module_param(fbwidth, int, 0644);
  92895. +module_param(fbheight, int, 0644);
  92896. +module_param(fbdepth, int, 0644);
  92897. +
  92898. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  92899. +MODULE_LICENSE("GPL");
  92900. +
  92901. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  92902. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  92903. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  92904. diff -Nur linux-3.11.10.orig/drivers/video/cfbimgblt.c linux-3.11.10/drivers/video/cfbimgblt.c
  92905. --- linux-3.11.10.orig/drivers/video/cfbimgblt.c 2013-11-29 19:42:37.000000000 +0100
  92906. +++ linux-3.11.10/drivers/video/cfbimgblt.c 2014-02-07 19:57:30.000000000 +0100
  92907. @@ -28,6 +28,11 @@
  92908. *
  92909. * Also need to add code to deal with cards endians that are different than
  92910. * the native cpu endians. I also need to deal with MSB position in the word.
  92911. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  92912. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  92913. + * significantly faster than the previous implementation.
  92914. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  92915. + * divides.
  92916. */
  92917. #include <linux/module.h>
  92918. #include <linux/string.h>
  92919. @@ -262,6 +267,133 @@
  92920. }
  92921. }
  92922. +/*
  92923. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  92924. + * into the code, main loop unrolled.
  92925. + */
  92926. +
  92927. +static inline void fast_imageblit16(const struct fb_image *image,
  92928. + struct fb_info *p, u8 __iomem * dst1,
  92929. + u32 fgcolor, u32 bgcolor)
  92930. +{
  92931. + u32 fgx = fgcolor, bgx = bgcolor;
  92932. + u32 spitch = (image->width + 7) / 8;
  92933. + u32 end_mask, eorx;
  92934. + const char *s = image->data, *src;
  92935. + u32 __iomem *dst;
  92936. + const u32 *tab = NULL;
  92937. + int i, j, k;
  92938. +
  92939. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  92940. +
  92941. + fgx <<= 16;
  92942. + bgx <<= 16;
  92943. + fgx |= fgcolor;
  92944. + bgx |= bgcolor;
  92945. +
  92946. + eorx = fgx ^ bgx;
  92947. + k = image->width / 2;
  92948. +
  92949. + for (i = image->height; i--;) {
  92950. + dst = (u32 __iomem *) dst1;
  92951. + src = s;
  92952. +
  92953. + j = k;
  92954. + while (j >= 4) {
  92955. + u8 bits = *src;
  92956. + end_mask = tab[(bits >> 6) & 3];
  92957. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92958. + end_mask = tab[(bits >> 4) & 3];
  92959. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92960. + end_mask = tab[(bits >> 2) & 3];
  92961. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92962. + end_mask = tab[bits & 3];
  92963. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92964. + src++;
  92965. + j -= 4;
  92966. + }
  92967. + if (j != 0) {
  92968. + u8 bits = *src;
  92969. + end_mask = tab[(bits >> 6) & 3];
  92970. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92971. + if (j >= 2) {
  92972. + end_mask = tab[(bits >> 4) & 3];
  92973. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  92974. + if (j == 3) {
  92975. + end_mask = tab[(bits >> 2) & 3];
  92976. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  92977. + }
  92978. + }
  92979. + }
  92980. + dst1 += p->fix.line_length;
  92981. + s += spitch;
  92982. + }
  92983. +}
  92984. +
  92985. +/*
  92986. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  92987. + * into the code, main loop unrolled.
  92988. + */
  92989. +
  92990. +static inline void fast_imageblit32(const struct fb_image *image,
  92991. + struct fb_info *p, u8 __iomem * dst1,
  92992. + u32 fgcolor, u32 bgcolor)
  92993. +{
  92994. + u32 fgx = fgcolor, bgx = bgcolor;
  92995. + u32 spitch = (image->width + 7) / 8;
  92996. + u32 end_mask, eorx;
  92997. + const char *s = image->data, *src;
  92998. + u32 __iomem *dst;
  92999. + const u32 *tab = NULL;
  93000. + int i, j, k;
  93001. +
  93002. + tab = cfb_tab32;
  93003. +
  93004. + eorx = fgx ^ bgx;
  93005. + k = image->width;
  93006. +
  93007. + for (i = image->height; i--;) {
  93008. + dst = (u32 __iomem *) dst1;
  93009. + src = s;
  93010. +
  93011. + j = k;
  93012. + while (j >= 8) {
  93013. + u8 bits = *src;
  93014. + end_mask = tab[(bits >> 7) & 1];
  93015. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93016. + end_mask = tab[(bits >> 6) & 1];
  93017. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93018. + end_mask = tab[(bits >> 5) & 1];
  93019. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93020. + end_mask = tab[(bits >> 4) & 1];
  93021. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93022. + end_mask = tab[(bits >> 3) & 1];
  93023. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93024. + end_mask = tab[(bits >> 2) & 1];
  93025. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93026. + end_mask = tab[(bits >> 1) & 1];
  93027. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93028. + end_mask = tab[bits & 1];
  93029. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93030. + src++;
  93031. + j -= 8;
  93032. + }
  93033. + if (j != 0) {
  93034. + u32 bits = (u32) * src;
  93035. + while (j > 1) {
  93036. + end_mask = tab[(bits >> 7) & 1];
  93037. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  93038. + bits <<= 1;
  93039. + j--;
  93040. + }
  93041. + end_mask = tab[(bits >> 7) & 1];
  93042. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  93043. + }
  93044. + dst1 += p->fix.line_length;
  93045. + s += spitch;
  93046. + }
  93047. +}
  93048. +
  93049. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  93050. {
  93051. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  93052. @@ -294,11 +426,21 @@
  93053. bgcolor = image->bg_color;
  93054. }
  93055. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  93056. - ((width & (32/bpp-1)) == 0) &&
  93057. - bpp >= 8 && bpp <= 32)
  93058. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  93059. - else
  93060. + if (!start_index && !pitch_index) {
  93061. + if (bpp == 32)
  93062. + fast_imageblit32(image, p, dst1, fgcolor,
  93063. + bgcolor);
  93064. + else if (bpp == 16 && (width & 1) == 0)
  93065. + fast_imageblit16(image, p, dst1, fgcolor,
  93066. + bgcolor);
  93067. + else if (bpp == 8 && (width & 3) == 0)
  93068. + fast_imageblit(image, p, dst1, fgcolor,
  93069. + bgcolor);
  93070. + else
  93071. + slow_imageblit(image, p, dst1, fgcolor,
  93072. + bgcolor,
  93073. + start_index, pitch_index);
  93074. + } else
  93075. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  93076. start_index, pitch_index);
  93077. } else
  93078. diff -Nur linux-3.11.10.orig/drivers/video/fbmem.c linux-3.11.10/drivers/video/fbmem.c
  93079. --- linux-3.11.10.orig/drivers/video/fbmem.c 2013-11-29 19:42:37.000000000 +0100
  93080. +++ linux-3.11.10/drivers/video/fbmem.c 2014-02-07 19:57:30.000000000 +0100
  93081. @@ -1074,6 +1074,25 @@
  93082. return ret;
  93083. }
  93084. +static int fb_copyarea_user(struct fb_info *info,
  93085. + struct fb_copyarea *copy)
  93086. +{
  93087. + int ret = 0;
  93088. + if (!lock_fb_info(info))
  93089. + return -ENODEV;
  93090. + if (copy->dx + copy->width > info->var.xres ||
  93091. + copy->sx + copy->width > info->var.xres ||
  93092. + copy->dy + copy->height > info->var.yres ||
  93093. + copy->sy + copy->height > info->var.yres) {
  93094. + ret = -EINVAL;
  93095. + goto out;
  93096. + }
  93097. + info->fbops->fb_copyarea(info, copy);
  93098. +out:
  93099. + unlock_fb_info(info);
  93100. + return ret;
  93101. +}
  93102. +
  93103. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  93104. unsigned long arg)
  93105. {
  93106. @@ -1084,6 +1103,7 @@
  93107. struct fb_cmap cmap_from;
  93108. struct fb_cmap_user cmap;
  93109. struct fb_event event;
  93110. + struct fb_copyarea copy;
  93111. void __user *argp = (void __user *)arg;
  93112. long ret = 0;
  93113. @@ -1193,6 +1213,15 @@
  93114. console_unlock();
  93115. unlock_fb_info(info);
  93116. break;
  93117. + case FBIOCOPYAREA:
  93118. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  93119. + /* only provide this ioctl if it is accelerated */
  93120. + if (copy_from_user(&copy, argp, sizeof(copy)))
  93121. + return -EFAULT;
  93122. + ret = fb_copyarea_user(info, &copy);
  93123. + break;
  93124. + }
  93125. + /* fall through */
  93126. default:
  93127. if (!lock_fb_info(info))
  93128. return -ENODEV;
  93129. @@ -1347,6 +1376,7 @@
  93130. case FBIOPAN_DISPLAY:
  93131. case FBIOGET_CON2FBMAP:
  93132. case FBIOPUT_CON2FBMAP:
  93133. + case FBIOCOPYAREA:
  93134. arg = (unsigned long) compat_ptr(arg);
  93135. case FBIOBLANK:
  93136. ret = do_fb_ioctl(info, cmd, arg);
  93137. diff -Nur linux-3.11.10.orig/drivers/video/Kconfig linux-3.11.10/drivers/video/Kconfig
  93138. --- linux-3.11.10.orig/drivers/video/Kconfig 2013-11-29 19:42:37.000000000 +0100
  93139. +++ linux-3.11.10/drivers/video/Kconfig 2014-02-07 19:57:30.000000000 +0100
  93140. @@ -310,6 +310,20 @@
  93141. help
  93142. Support the Permedia2 FIFO disconnect feature.
  93143. +config FB_BCM2708
  93144. + tristate "BCM2708 framebuffer support"
  93145. + depends on FB && ARM
  93146. + select FB_CFB_FILLRECT
  93147. + select FB_CFB_COPYAREA
  93148. + select FB_CFB_IMAGEBLIT
  93149. + help
  93150. + This framebuffer device driver is for the BCM2708 framebuffer.
  93151. +
  93152. + If you want to compile this as a module (=code which can be
  93153. + inserted into and removed from the running kernel), say M
  93154. + here and read <file:Documentation/kbuild/modules.txt>. The module
  93155. + will be called bcm2708_fb.
  93156. +
  93157. config FB_ARMCLCD
  93158. tristate "ARM PrimeCell PL110 support"
  93159. depends on FB && ARM && ARM_AMBA
  93160. diff -Nur linux-3.11.10.orig/drivers/video/logo/logo_linux_clut224.ppm linux-3.11.10/drivers/video/logo/logo_linux_clut224.ppm
  93161. --- linux-3.11.10.orig/drivers/video/logo/logo_linux_clut224.ppm 2013-11-29 19:42:37.000000000 +0100
  93162. +++ linux-3.11.10/drivers/video/logo/logo_linux_clut224.ppm 2014-02-07 19:57:30.000000000 +0100
  93163. @@ -1,883 +1,883 @@
  93164. P3
  93165. -80 80
  93166. +63 80
  93167. 255
  93168. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93169. -0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
  93170. -83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
  93171. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93172. -0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
  93173. -10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  93174. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93175. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93176. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93177. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93178. -
  93179. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93180. -0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
  93181. -105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
  93182. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93183. -0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
  93184. -30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
  93185. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93186. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93187. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93188. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93189. -
  93190. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
  93191. -0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
  93192. -108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
  93193. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93194. -6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
  93195. -78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
  93196. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93197. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93198. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93199. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93200. -
  93201. -0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
  93202. -11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
  93203. -108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
  93204. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93205. -22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
  93206. -26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
  93207. -14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93208. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93209. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93210. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93211. -
  93212. -0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
  93213. -53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
  93214. -132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
  93215. -1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
  93216. -50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
  93217. -2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
  93218. -38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93219. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93220. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93221. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93222. -
  93223. -0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
  93224. -59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
  93225. -117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
  93226. -7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
  93227. -78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93228. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
  93229. -78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  93230. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93231. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93232. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93233. -
  93234. -0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
  93235. -6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
  93236. -108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
  93237. -36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
  93238. -26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93239. -2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
  93240. -42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93241. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93242. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93243. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93244. -
  93245. -27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
  93246. -12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
  93247. -117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
  93248. -68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
  93249. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93250. -2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
  93251. -2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
  93252. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93253. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93254. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93255. -
  93256. -36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
  93257. -57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
  93258. -152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
  93259. -95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
  93260. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93261. -2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
  93262. -2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
  93263. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93264. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93265. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93266. -
  93267. -17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
  93268. -86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
  93269. -137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
  93270. -95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
  93271. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93272. -2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
  93273. -2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
  93274. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93275. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93276. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93277. -
  93278. -1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
  93279. -152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
  93280. -94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
  93281. -95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
  93282. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93283. -2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
  93284. -2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
  93285. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93286. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93287. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93288. -
  93289. -4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
  93290. -174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
  93291. -79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
  93292. -91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
  93293. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93294. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93295. -2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
  93296. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93297. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93298. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93299. -
  93300. -19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
  93301. -174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
  93302. -21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
  93303. -91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
  93304. -2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93305. -2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
  93306. -2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
  93307. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93308. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93309. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93310. -
  93311. -34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
  93312. -174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
  93313. -12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
  93314. -93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
  93315. -6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
  93316. -2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
  93317. -2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
  93318. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93319. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93320. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93321. -
  93322. -40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
  93323. -123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
  93324. -60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
  93325. -91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
  93326. -38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
  93327. -14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
  93328. -2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
  93329. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93330. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93331. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93332. -
  93333. -34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
  93334. -48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
  93335. -68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
  93336. -91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
  93337. -124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
  93338. -101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
  93339. -2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
  93340. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93341. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93342. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93343. -
  93344. -19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
  93345. -6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
  93346. -34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
  93347. -73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
  93348. -218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
  93349. -210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
  93350. -2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
  93351. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93352. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93353. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93354. -
  93355. -4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
  93356. -13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
  93357. -26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
  93358. -53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
  93359. -170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
  93360. -231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
  93361. -2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
  93362. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93363. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93364. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93365. -
  93366. -1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
  93367. -18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
  93368. -17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
  93369. -42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
  93370. -106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
  93371. -221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
  93372. -2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
  93373. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93374. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93375. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93376. -
  93377. -11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
  93378. -63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
  93379. -24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
  93380. -29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
  93381. -124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
  93382. -170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
  93383. -2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
  93384. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93385. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93386. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93387. -
  93388. -26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
  93389. -133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
  93390. -51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
  93391. -18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
  93392. -210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
  93393. -220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
  93394. -2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
  93395. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93396. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93397. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93398. -
  93399. -27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
  93400. -175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
  93401. -20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
  93402. -6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
  93403. -195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
  93404. -237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
  93405. -2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
  93406. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93407. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93408. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93409. -
  93410. -15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
  93411. -175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
  93412. -1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
  93413. -0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
  93414. -121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
  93415. -237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
  93416. -2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
  93417. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93418. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93419. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93420. -
  93421. -1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
  93422. -175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
  93423. -21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
  93424. -0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
  93425. -180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
  93426. -239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
  93427. -2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
  93428. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93429. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93430. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93431. -
  93432. -0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
  93433. -175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
  93434. -17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
  93435. -0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
  93436. -192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
  93437. -241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
  93438. -2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
  93439. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93440. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93441. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93442. -
  93443. -0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
  93444. -149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
  93445. -3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93446. -0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
  93447. -137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
  93448. -241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
  93449. -6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
  93450. -10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93451. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93452. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93453. -
  93454. -0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
  93455. -56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
  93456. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93457. -0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
  93458. -88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
  93459. -171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
  93460. -2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
  93461. -18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93462. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93463. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93464. -
  93465. -0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
  93466. -8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
  93467. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93468. -0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
  93469. -124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
  93470. -206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
  93471. -2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
  93472. -30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93473. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93474. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93475. -
  93476. -0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
  93477. -0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
  93478. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93479. -0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
  93480. -124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
  93481. -180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
  93482. -2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
  93483. -50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93484. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93485. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93486. -
  93487. -0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
  93488. -0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
  93489. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93490. -0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
  93491. -151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
  93492. -168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
  93493. -6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
  93494. -74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93495. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93496. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93497. -
  93498. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
  93499. -18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93500. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93501. -0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
  93502. -234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
  93503. -190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93504. -82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
  93505. -86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  93506. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93507. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93508. -
  93509. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
  93510. -52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93511. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93512. -6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
  93513. -253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
  93514. -202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93515. -202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93516. -42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93517. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93518. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93519. -
  93520. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
  93521. -36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93522. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93523. -14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
  93524. -253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
  93525. -246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93526. -253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93527. -2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
  93528. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93529. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93530. -
  93531. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93532. -21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93533. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
  93534. -34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
  93535. -253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
  93536. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93537. -253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93538. -2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
  93539. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93540. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93541. -
  93542. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93543. -12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93544. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
  93545. -58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
  93546. -253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
  93547. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93548. -253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93549. -2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
  93550. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93551. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93552. -
  93553. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93554. -0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
  93555. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
  93556. -90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
  93557. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93558. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93559. -250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93560. -2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
  93561. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93562. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93563. -
  93564. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93565. -0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
  93566. -0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
  93567. -34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
  93568. -253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
  93569. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
  93570. -226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
  93571. -2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
  93572. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93573. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93574. -
  93575. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93576. -0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
  93577. -0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
  93578. -2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
  93579. -246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
  93580. -250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
  93581. -198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
  93582. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
  93583. -10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93584. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93585. -
  93586. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93587. -0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
  93588. -0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
  93589. -2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
  93590. -250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
  93591. -253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
  93592. -195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
  93593. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
  93594. -18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93595. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93596. -
  93597. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93598. -0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
  93599. -0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
  93600. -2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
  93601. -253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
  93602. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
  93603. -231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
  93604. -30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
  93605. -26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93606. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93607. -
  93608. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93609. -0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
  93610. -0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
  93611. -26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
  93612. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93613. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93614. -253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
  93615. -30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
  93616. -42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93617. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93618. -
  93619. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93620. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
  93621. -0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
  93622. -42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
  93623. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93624. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93625. -253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
  93626. -18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
  93627. -58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93628. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93629. -
  93630. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93631. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
  93632. -0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
  93633. -22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93634. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93635. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93636. -253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
  93637. -58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
  93638. -78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93639. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93640. -
  93641. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93642. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
  93643. -36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
  93644. -2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93645. -253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
  93646. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93647. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
  93648. -42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
  93649. -86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93650. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93651. -
  93652. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93653. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93654. -36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
  93655. -2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93656. -253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
  93657. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93658. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
  93659. -2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
  93660. -74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  93661. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93662. -
  93663. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93664. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93665. -0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
  93666. -14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93667. -253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93668. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93669. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
  93670. -2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
  93671. -42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
  93672. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93673. -
  93674. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93675. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93676. -6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
  93677. -74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93678. -253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93679. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93680. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
  93681. -2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
  93682. -10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
  93683. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93684. -
  93685. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93686. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93687. -10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
  93688. -151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93689. -253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93690. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93691. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
  93692. -2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
  93693. -6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
  93694. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93695. -
  93696. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93697. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93698. -18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
  93699. -210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93700. -253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93701. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93702. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
  93703. -2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
  93704. -2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93705. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93706. -
  93707. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93708. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93709. -26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
  93710. -238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93711. -253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
  93712. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93713. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
  93714. -2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
  93715. -2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
  93716. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93717. -
  93718. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93719. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93720. -38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
  93721. -246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93722. -253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93723. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93724. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
  93725. -2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
  93726. -2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
  93727. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93728. -
  93729. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93730. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
  93731. -50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
  93732. -250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93733. -253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
  93734. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93735. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
  93736. -2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93737. -2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
  93738. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93739. -
  93740. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93741. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
  93742. -54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
  93743. -250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93744. -253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
  93745. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93746. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
  93747. -2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93748. -2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
  93749. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93750. -
  93751. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93752. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
  93753. -58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
  93754. -250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93755. -253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
  93756. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93757. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
  93758. -22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
  93759. -2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93760. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93761. -
  93762. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93763. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
  93764. -62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
  93765. -238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93766. -253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
  93767. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93768. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
  93769. -14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
  93770. -6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93771. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93772. -
  93773. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93774. -0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
  93775. -78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
  93776. -90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93777. -253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
  93778. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93779. -253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
  93780. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
  93781. -26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
  93782. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93783. -
  93784. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93785. -0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
  93786. -106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
  93787. -6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93788. -253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
  93789. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93790. -253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
  93791. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
  93792. -204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
  93793. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93794. -
  93795. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93796. -6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
  93797. -174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
  93798. -98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
  93799. -253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
  93800. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93801. -253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
  93802. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
  93803. -238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
  93804. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93805. -
  93806. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93807. -14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
  93808. -213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93809. -220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
  93810. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93811. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93812. -253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
  93813. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
  93814. -237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
  93815. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93816. -
  93817. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93818. -22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
  93819. -236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93820. -241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
  93821. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93822. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93823. -253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
  93824. -20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
  93825. -239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
  93826. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93827. -
  93828. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93829. -30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
  93830. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93831. -246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
  93832. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93833. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93834. -253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
  93835. -163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
  93836. -242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
  93837. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93838. -
  93839. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93840. -30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
  93841. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93842. -246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
  93843. -218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93844. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93845. -250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
  93846. -200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
  93847. -246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
  93848. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93849. -
  93850. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93851. -30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
  93852. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93853. -246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
  93854. -78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93855. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93856. -250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
  93857. -216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
  93858. -246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
  93859. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93860. -
  93861. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93862. -30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
  93863. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93864. -246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
  93865. -22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93866. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93867. -253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
  93868. -230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
  93869. -246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
  93870. -14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93871. -
  93872. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93873. -26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
  93874. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93875. -246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
  93876. -46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93877. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93878. -253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
  93879. -242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
  93880. -246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
  93881. -30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93882. -
  93883. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93884. -26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
  93885. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93886. -246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
  93887. -221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93888. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93889. -242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
  93890. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93891. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
  93892. -46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93893. -
  93894. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
  93895. -30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
  93896. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93897. -246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
  93898. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93899. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
  93900. -58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
  93901. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93902. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
  93903. -54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93904. -
  93905. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
  93906. -38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
  93907. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93908. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
  93909. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93910. -253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
  93911. -2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
  93912. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93913. -246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
  93914. -46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93915. -
  93916. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
  93917. -50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
  93918. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93919. -246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
  93920. -226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
  93921. -253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
  93922. -2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
  93923. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93924. -246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
  93925. -30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93926. -
  93927. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
  93928. -58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
  93929. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93930. -246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
  93931. -62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
  93932. -242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
  93933. -2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
  93934. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93935. -246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
  93936. -18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93937. -
  93938. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
  93939. -62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
  93940. -246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
  93941. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
  93942. -85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
  93943. -14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93944. -2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
  93945. -246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
  93946. -230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
  93947. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93948. -
  93949. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
  93950. -50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
  93951. -230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
  93952. -246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
  93953. -104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93954. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93955. -2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
  93956. -246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
  93957. -169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
  93958. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93959. -
  93960. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
  93961. -34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
  93962. -200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
  93963. -246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
  93964. -104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93965. -2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
  93966. -2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
  93967. -246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
  93968. -94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
  93969. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93970. -
  93971. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  93972. -18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
  93973. -163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
  93974. -226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
  93975. -85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
  93976. -38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
  93977. -2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
  93978. -234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
  93979. -50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  93980. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93981. -
  93982. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93983. -6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
  93984. -101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
  93985. -184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
  93986. -62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
  93987. -78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
  93988. -106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
  93989. -206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
  93990. -22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93991. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93992. -
  93993. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  93994. -0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
  93995. -50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
  93996. -137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
  93997. -101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
  93998. -34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
  93999. -54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
  94000. -171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
  94001. -6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94002. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94003. -
  94004. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94005. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
  94006. -18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
  94007. -94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
  94008. -62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
  94009. -10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
  94010. -22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
  94011. -134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
  94012. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94013. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94014. -
  94015. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94016. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94017. -0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
  94018. -70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
  94019. -30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94020. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94021. -6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
  94022. -94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
  94023. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94024. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94025. -
  94026. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94027. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94028. -0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
  94029. -30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
  94030. -10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94031. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94032. -0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
  94033. -54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
  94034. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94035. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94036. -
  94037. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94038. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94039. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
  94040. -6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
  94041. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94042. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94043. -0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
  94044. -18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
  94045. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94046. -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94047. -
  94048. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94049. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94050. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94051. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94052. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94053. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94054. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94055. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94056. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94058. +0 0 0 0 0 0 0 0 0
  94059. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94060. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94061. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  94062. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94063. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94064. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94065. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94066. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  94067. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94069. +0 0 0 0 0 0 0 0 0
  94070. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94071. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94072. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  94073. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  94074. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94075. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94076. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  94077. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  94078. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  94079. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94080. +0 0 0 0 0 0 0 0 0
  94081. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94082. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  94083. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  94084. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  94085. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94086. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94087. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  94088. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  94089. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  94090. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  94091. +0 0 0 0 0 0 0 0 0
  94092. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  94093. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  94094. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  94095. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  94096. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  94097. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94098. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  94099. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  94100. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  94101. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  94102. +0 0 0 0 0 0 0 0 0
  94103. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  94104. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  94105. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94106. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  94107. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  94108. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  94109. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  94110. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94111. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  94112. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  94113. +0 0 0 0 0 0 0 0 0
  94114. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94115. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  94116. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  94117. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94118. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  94119. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  94120. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  94121. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94122. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  94123. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  94124. +0 0 0 0 0 0 0 0 0
  94125. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  94126. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  94127. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  94128. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94129. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  94130. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  94131. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94132. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  94133. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  94134. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  94135. +0 0 0 0 0 0 0 0 0
  94136. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  94137. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94138. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  94139. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94140. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  94141. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  94142. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94143. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  94144. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  94145. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  94146. +0 0 0 0 0 0 0 0 0
  94147. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94148. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  94149. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  94150. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  94151. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  94152. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  94153. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94154. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  94155. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  94156. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  94157. +0 0 0 0 0 0 0 0 0
  94158. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94159. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  94160. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  94161. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  94162. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  94163. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  94164. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  94165. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  94166. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  94167. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  94168. +0 0 0 0 0 0 0 0 0
  94169. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94170. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  94171. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  94172. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  94173. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  94174. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  94175. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  94176. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  94177. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94178. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  94179. +0 0 0 0 0 0 0 0 0
  94180. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94181. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  94182. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94183. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  94184. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  94185. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  94186. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  94187. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  94188. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94189. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  94190. +0 0 0 0 0 0 0 0 0
  94191. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94192. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  94193. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94194. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  94195. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  94196. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  94197. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  94198. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  94199. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94200. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  94201. +0 0 0 0 0 0 0 0 0
  94202. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94203. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  94204. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94205. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  94206. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  94207. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  94208. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  94209. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94210. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94211. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  94212. +0 0 0 0 0 0 0 0 0
  94213. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94214. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  94215. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94216. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  94217. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  94218. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  94219. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  94220. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94221. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  94222. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  94223. +0 0 0 0 0 0 0 0 0
  94224. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94225. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  94226. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94227. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  94228. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  94229. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  94230. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  94231. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94232. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  94233. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  94234. +0 0 0 0 0 0 0 0 0
  94235. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94236. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  94237. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94238. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94239. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  94240. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94241. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  94242. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94243. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  94244. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94245. +0 0 0 0 0 0 0 0 0
  94246. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94247. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  94248. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  94249. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94250. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  94251. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94252. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  94253. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94254. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  94255. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94256. +0 0 0 0 0 0 0 0 0
  94257. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94258. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  94259. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  94260. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  94261. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  94262. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94263. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  94264. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  94265. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  94266. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94267. +0 0 0 0 0 0 0 0 0
  94268. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94269. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94270. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  94271. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  94272. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94273. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94274. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  94275. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  94276. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  94277. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94278. +0 0 0 0 0 0 0 0 0
  94279. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94280. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94281. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  94282. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  94283. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94284. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94285. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  94286. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  94287. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  94288. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94289. +0 0 0 0 0 0 0 0 0
  94290. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94291. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94292. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  94293. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  94294. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  94295. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  94296. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94297. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  94298. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94299. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94300. +0 0 0 0 0 0 0 0 0
  94301. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94302. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94303. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  94304. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  94305. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  94306. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  94307. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  94308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94309. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94310. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94311. +0 0 0 0 0 0 0 0 0
  94312. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94313. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94314. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  94315. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  94316. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  94317. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  94318. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  94319. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  94320. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94321. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94322. +0 0 0 0 0 0 0 0 0
  94323. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94324. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94325. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  94326. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  94327. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  94328. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94329. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  94330. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  94331. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94332. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94333. +0 0 0 0 0 0 0 0 0
  94334. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94335. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  94336. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  94337. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  94338. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94339. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94340. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  94341. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  94342. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  94343. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94344. +0 0 0 0 0 0 0 0 0
  94345. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94346. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  94347. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94348. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  94349. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94350. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94351. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  94352. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  94353. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  94354. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94355. +0 0 0 0 0 0 0 0 0
  94356. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94357. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  94358. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94359. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  94360. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94361. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94362. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  94363. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  94364. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  94365. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94366. +0 0 0 0 0 0 0 0 0
  94367. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94368. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  94369. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  94370. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  94371. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  94372. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94373. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  94374. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  94375. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  94376. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94377. +0 0 0 0 0 0 0 0 0
  94378. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94379. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  94380. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  94381. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94382. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  94383. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  94384. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  94385. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  94386. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  94387. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94388. +0 0 0 0 0 0 0 0 0
  94389. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94390. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  94391. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  94392. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94393. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  94394. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  94395. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  94396. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  94397. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  94398. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94399. +0 0 0 0 0 0 0 0 0
  94400. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94401. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  94402. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  94403. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  94404. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  94405. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  94406. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  94407. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  94408. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  94409. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94410. +0 0 0 0 0 0 0 0 0
  94411. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94412. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  94413. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  94414. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  94415. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  94416. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  94417. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  94418. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  94419. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  94420. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94421. +0 0 0 0 0 0 0 0 0
  94422. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94423. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  94424. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  94425. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  94426. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  94427. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  94428. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94429. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  94430. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  94431. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94432. +0 0 0 0 0 0 0 0 0
  94433. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94434. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  94435. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  94436. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94437. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  94438. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  94439. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94440. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  94441. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  94442. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94443. +0 0 0 0 0 0 0 0 0
  94444. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94445. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94446. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  94447. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94448. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  94449. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  94450. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94451. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  94452. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94453. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94454. +0 0 0 0 0 0 0 0 0
  94455. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94456. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  94457. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  94458. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94459. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  94460. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  94461. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94462. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94463. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  94464. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  94465. +0 0 0 0 0 0 0 0 0
  94466. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94467. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  94468. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  94469. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94470. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  94471. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  94472. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94473. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94474. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  94475. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  94476. +0 0 0 0 0 0 0 0 0
  94477. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  94478. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  94479. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  94480. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94481. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  94482. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  94483. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94484. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94485. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  94486. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  94487. +0 0 0 0 0 0 0 0 0
  94488. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  94489. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  94490. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  94491. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94492. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  94493. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  94494. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94495. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94496. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  94497. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  94498. +0 0 0 0 0 0 0 0 0
  94499. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  94500. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  94501. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  94502. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94503. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  94504. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  94505. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94506. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94507. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  94508. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  94509. +0 0 0 0 0 0 0 0 0
  94510. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  94511. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  94512. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  94513. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94514. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  94515. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  94516. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94517. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94518. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  94519. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  94520. +0 0 0 0 0 0 0 0 0
  94521. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  94522. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  94523. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  94524. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94525. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  94526. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  94527. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94528. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94529. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  94530. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  94531. +0 0 0 0 0 0 0 0 0
  94532. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  94533. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  94534. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  94535. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94536. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  94537. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  94538. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94539. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94540. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  94541. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  94542. +0 0 0 0 0 0 0 0 0
  94543. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  94544. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  94545. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  94546. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94547. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  94548. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  94549. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94550. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94551. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  94552. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  94553. +0 0 0 0 0 0 0 0 0
  94554. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  94555. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  94556. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  94557. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94558. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  94559. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  94560. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94561. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94562. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  94563. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  94564. +0 0 0 0 0 0 0 0 0
  94565. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  94566. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  94567. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  94568. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94569. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  94570. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  94571. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  94572. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94573. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  94574. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  94575. +0 0 0 0 0 0 0 0 0
  94576. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  94577. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  94578. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  94579. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94580. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  94581. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94582. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  94583. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  94584. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  94585. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  94586. +0 0 0 0 0 0 0 0 0
  94587. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  94588. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  94589. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  94590. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  94591. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  94592. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  94593. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  94594. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  94595. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  94596. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  94597. +0 0 0 0 0 0 0 0 0
  94598. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  94599. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  94600. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  94601. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  94602. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  94603. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  94604. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  94605. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  94606. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  94607. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  94608. +0 0 0 0 0 0 0 0 0
  94609. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  94610. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  94611. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  94612. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  94613. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  94614. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  94615. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  94616. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94617. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  94618. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  94619. +0 0 0 0 0 0 0 0 0
  94620. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  94621. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  94622. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94623. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94624. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  94625. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94626. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  94627. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94628. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  94629. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  94630. +0 0 0 0 0 0 0 0 0
  94631. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  94632. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  94633. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  94634. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  94635. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94636. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94637. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  94638. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  94639. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  94640. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  94641. +0 0 0 0 0 0 0 0 0
  94642. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94643. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  94644. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  94645. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  94646. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94647. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94648. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  94649. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  94650. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  94651. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94652. +0 0 0 0 0 0 0 0 0
  94653. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94654. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  94655. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  94656. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  94657. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94658. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94659. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  94660. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  94661. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  94662. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94663. +0 0 0 0 0 0 0 0 0
  94664. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94665. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  94666. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  94667. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  94668. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94669. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94670. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  94671. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  94672. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94673. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  94674. +0 0 0 0 0 0 0 0 0
  94675. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94676. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  94677. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  94678. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  94679. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94680. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94681. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  94682. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  94683. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94684. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  94685. +0 0 0 0 0 0 0 0 0
  94686. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94687. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  94688. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94689. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  94690. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94691. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94692. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  94693. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  94694. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94695. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  94696. +0 0 0 0 0 0 0 0 0
  94697. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94698. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  94699. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94700. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  94701. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94702. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94703. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  94704. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  94705. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94706. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  94707. +0 0 0 0 0 0 0 0 0
  94708. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94709. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  94710. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94711. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  94712. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94713. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94714. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  94715. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  94716. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  94717. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  94718. +0 0 0 0 0 0 0 0 0
  94719. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94720. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  94721. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94722. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  94723. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94724. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94725. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  94726. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94727. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94728. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  94729. +0 0 0 0 0 0 0 0 0
  94730. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94731. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  94732. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94733. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  94734. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  94735. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94736. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  94737. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94738. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  94739. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94740. +0 0 0 0 0 0 0 0 0
  94741. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94742. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  94743. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94744. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  94745. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  94746. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94747. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  94748. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94749. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  94750. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94751. +0 0 0 0 0 0 0 0 0
  94752. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94753. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  94754. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94755. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  94756. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  94757. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  94758. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  94759. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94760. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  94761. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94762. +0 0 0 0 0 0 0 0 0
  94763. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94764. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  94765. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94766. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  94767. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  94768. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  94769. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  94770. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94771. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  94772. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94773. +0 0 0 0 0 0 0 0 0
  94774. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94775. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  94776. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  94777. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  94778. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  94779. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  94780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  94781. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94782. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  94783. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94784. +0 0 0 0 0 0 0 0 0
  94785. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94786. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  94787. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  94788. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  94789. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94790. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  94792. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  94793. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  94794. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94795. +0 0 0 0 0 0 0 0 0
  94796. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94797. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94798. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  94799. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  94800. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  94801. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  94802. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  94803. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  94804. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  94805. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94806. +0 0 0 0 0 0 0 0 0
  94807. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94808. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94809. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  94810. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  94811. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  94812. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  94813. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  94814. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  94815. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94816. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94817. +0 0 0 0 0 0 0 0 0
  94818. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94819. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94820. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94821. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  94822. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  94823. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  94824. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  94825. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94826. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94827. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94828. +0 0 0 0 0 0 0 0 0
  94829. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94830. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94831. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94832. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  94833. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94834. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94835. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  94836. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94837. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94838. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94839. +0 0 0 0 0 0 0 0 0
  94840. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94841. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94842. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94843. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  94844. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94845. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94846. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  94847. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94848. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94849. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94850. +0 0 0 0 0 0 0 0 0
  94851. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94852. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94853. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94854. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  94855. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94856. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94857. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  94858. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94859. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94860. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94861. +0 0 0 0 0 0 0 0 0
  94862. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94863. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94864. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94865. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  94866. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  94867. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  94868. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  94869. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94870. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94871. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94872. +0 0 0 0 0 0 0 0 0
  94873. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94874. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94875. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94876. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94877. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  94878. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  94879. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  94880. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94881. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94882. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94883. +0 0 0 0 0 0 0 0 0
  94884. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94885. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94886. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94887. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94888. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  94889. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  94890. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94891. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94892. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94893. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94894. +0 0 0 0 0 0 0 0 0
  94895. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94896. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94897. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94898. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94899. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  94900. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  94901. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94902. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94903. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94904. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94905. +0 0 0 0 0 0 0 0 0
  94906. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94907. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94908. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94909. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94910. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94911. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94912. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94913. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94914. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94915. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94916. +0 0 0 0 0 0 0 0 0
  94917. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94918. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94919. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94920. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94921. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94922. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94923. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94924. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94925. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94926. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  94927. +0 0 0 0 0 0 0 0 0
  94928. diff -Nur linux-3.11.10.orig/drivers/video/Makefile linux-3.11.10/drivers/video/Makefile
  94929. --- linux-3.11.10.orig/drivers/video/Makefile 2013-11-29 19:42:37.000000000 +0100
  94930. +++ linux-3.11.10/drivers/video/Makefile 2014-02-07 19:57:30.000000000 +0100
  94931. @@ -100,6 +100,7 @@
  94932. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  94933. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  94934. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  94935. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  94936. obj-$(CONFIG_FB_68328) += 68328fb.o
  94937. obj-$(CONFIG_FB_GBE) += gbefb.o
  94938. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  94939. diff -Nur linux-3.11.10.orig/drivers/w1/masters/w1-gpio.c linux-3.11.10/drivers/w1/masters/w1-gpio.c
  94940. --- linux-3.11.10.orig/drivers/w1/masters/w1-gpio.c 2013-11-29 19:42:37.000000000 +0100
  94941. +++ linux-3.11.10/drivers/w1/masters/w1-gpio.c 2014-02-07 19:57:30.000000000 +0100
  94942. @@ -22,6 +22,9 @@
  94943. #include "../w1.h"
  94944. #include "../w1_int.h"
  94945. +static int w1_gpio_pullup = 0;
  94946. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  94947. +
  94948. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  94949. {
  94950. struct w1_gpio_platform_data *pdata = data;
  94951. @@ -46,6 +49,16 @@
  94952. return gpio_get_value(pdata->pin) ? 1 : 0;
  94953. }
  94954. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  94955. +{
  94956. + struct w1_gpio_platform_data *pdata = data;
  94957. +
  94958. + if (on)
  94959. + gpio_direction_output(pdata->pin, 1);
  94960. + else
  94961. + gpio_direction_input(pdata->pin);
  94962. +}
  94963. +
  94964. #if defined(CONFIG_OF)
  94965. static struct of_device_id w1_gpio_dt_ids[] = {
  94966. { .compatible = "w1-gpio" },
  94967. @@ -127,6 +140,13 @@
  94968. master->write_bit = w1_gpio_write_bit_dir;
  94969. }
  94970. + if (w1_gpio_pullup)
  94971. + if (pdata->is_open_drain)
  94972. + printk(KERN_ERR "w1-gpio 'pullup' option "
  94973. + "doesn't work with open drain GPIO\n");
  94974. + else
  94975. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  94976. +
  94977. err = w1_add_master_device(master);
  94978. if (err) {
  94979. dev_err(&pdev->dev, "w1_add_master device failed\n");
  94980. diff -Nur linux-3.11.10.orig/drivers/w1/w1.h linux-3.11.10/drivers/w1/w1.h
  94981. --- linux-3.11.10.orig/drivers/w1/w1.h 2013-11-29 19:42:37.000000000 +0100
  94982. +++ linux-3.11.10/drivers/w1/w1.h 2014-02-07 19:57:30.000000000 +0100
  94983. @@ -148,6 +148,12 @@
  94984. */
  94985. u8 (*set_pullup)(void *, int);
  94986. + /**
  94987. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  94988. + * @return -1=Error, 0=completed
  94989. + */
  94990. + void (*bitbang_pullup) (void *, u8);
  94991. +
  94992. /** Really nice hardware can handles the different types of ROM search
  94993. * w1_master* is passed to the slave found callback.
  94994. */
  94995. diff -Nur linux-3.11.10.orig/drivers/w1/w1_int.c linux-3.11.10/drivers/w1/w1_int.c
  94996. --- linux-3.11.10.orig/drivers/w1/w1_int.c 2013-11-29 19:42:37.000000000 +0100
  94997. +++ linux-3.11.10/drivers/w1/w1_int.c 2014-02-07 19:57:30.000000000 +0100
  94998. @@ -117,19 +117,21 @@
  94999. printk(KERN_ERR "w1_add_master_device: invalid function set\n");
  95000. return(-EINVAL);
  95001. }
  95002. - /* While it would be electrically possible to make a device that
  95003. - * generated a strong pullup in bit bang mode, only hardware that
  95004. - * controls 1-wire time frames are even expected to support a strong
  95005. - * pullup. w1_io.c would need to support calling set_pullup before
  95006. - * the last write_bit operation of a w1_write_8 which it currently
  95007. - * doesn't.
  95008. - */
  95009. +
  95010. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  95011. + * and takes care of timing itself */
  95012. if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  95013. printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  95014. "write_byte or touch_bit, disabling\n");
  95015. master->set_pullup = NULL;
  95016. }
  95017. + if (master->set_pullup && master->bitbang_pullup) {
  95018. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  95019. + "be set when bitbang_pullup is used, disabling\n");
  95020. + master->set_pullup = NULL;
  95021. + }
  95022. +
  95023. /* Lock until the device is added (or not) to w1_masters. */
  95024. mutex_lock(&w1_mlock);
  95025. /* Search for the first available id (starting at 1). */
  95026. diff -Nur linux-3.11.10.orig/drivers/w1/w1_io.c linux-3.11.10/drivers/w1/w1_io.c
  95027. --- linux-3.11.10.orig/drivers/w1/w1_io.c 2013-11-29 19:42:37.000000000 +0100
  95028. +++ linux-3.11.10/drivers/w1/w1_io.c 2014-02-07 19:57:30.000000000 +0100
  95029. @@ -127,10 +127,22 @@
  95030. static void w1_post_write(struct w1_master *dev)
  95031. {
  95032. if (dev->pullup_duration) {
  95033. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  95034. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  95035. - else
  95036. + if (dev->enable_pullup) {
  95037. + if (dev->bus_master->set_pullup) {
  95038. + dev->bus_master->set_pullup(dev->
  95039. + bus_master->data,
  95040. + 0);
  95041. + } else if (dev->bus_master->bitbang_pullup) {
  95042. + dev->bus_master->
  95043. + bitbang_pullup(dev->bus_master->data, 1);
  95044. msleep(dev->pullup_duration);
  95045. + dev->bus_master->
  95046. + bitbang_pullup(dev->bus_master->data, 0);
  95047. + }
  95048. + } else {
  95049. + msleep(dev->pullup_duration);
  95050. + }
  95051. +
  95052. dev->pullup_duration = 0;
  95053. }
  95054. }
  95055. diff -Nur linux-3.11.10.orig/drivers/watchdog/bcm2708_wdog.c linux-3.11.10/drivers/watchdog/bcm2708_wdog.c
  95056. --- linux-3.11.10.orig/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  95057. +++ linux-3.11.10/drivers/watchdog/bcm2708_wdog.c 2014-02-07 19:57:30.000000000 +0100
  95058. @@ -0,0 +1,384 @@
  95059. +/*
  95060. + * Broadcom BCM2708 watchdog driver.
  95061. + *
  95062. + * (c) Copyright 2010 Broadcom Europe Ltd
  95063. + *
  95064. + * This program is free software; you can redistribute it and/or
  95065. + * modify it under the terms of the GNU General Public License
  95066. + * as published by the Free Software Foundation; either version
  95067. + * 2 of the License, or (at your option) any later version.
  95068. + *
  95069. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  95070. + */
  95071. +
  95072. +#include <linux/interrupt.h>
  95073. +#include <linux/module.h>
  95074. +#include <linux/moduleparam.h>
  95075. +#include <linux/types.h>
  95076. +#include <linux/miscdevice.h>
  95077. +#include <linux/watchdog.h>
  95078. +#include <linux/fs.h>
  95079. +#include <linux/ioport.h>
  95080. +#include <linux/notifier.h>
  95081. +#include <linux/reboot.h>
  95082. +#include <linux/init.h>
  95083. +#include <linux/io.h>
  95084. +#include <linux/uaccess.h>
  95085. +#include <mach/platform.h>
  95086. +
  95087. +#include <asm/system.h>
  95088. +
  95089. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  95090. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  95091. +
  95092. +static unsigned long wdog_is_open;
  95093. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  95094. +static char expect_close;
  95095. +
  95096. +/*
  95097. + * Module parameters
  95098. + */
  95099. +
  95100. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  95101. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  95102. +
  95103. +module_param(heartbeat, int, 0);
  95104. +MODULE_PARM_DESC(heartbeat,
  95105. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  95106. + __MODULE_STRING(WD_TIMO) ")");
  95107. +
  95108. +static int nowayout = WATCHDOG_NOWAYOUT;
  95109. +module_param(nowayout, int, 0);
  95110. +MODULE_PARM_DESC(nowayout,
  95111. + "Watchdog cannot be stopped once started (default="
  95112. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  95113. +
  95114. +static DEFINE_SPINLOCK(wdog_lock);
  95115. +
  95116. +/**
  95117. + * Start the watchdog driver.
  95118. + */
  95119. +
  95120. +static int wdog_start(unsigned long timeout)
  95121. +{
  95122. + uint32_t cur;
  95123. + unsigned long flags;
  95124. + spin_lock_irqsave(&wdog_lock, flags);
  95125. +
  95126. + /* enable the watchdog */
  95127. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  95128. + __io_address(PM_WDOG));
  95129. + cur = ioread32(__io_address(PM_RSTC));
  95130. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  95131. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  95132. +
  95133. + spin_unlock_irqrestore(&wdog_lock, flags);
  95134. + return 0;
  95135. +}
  95136. +
  95137. +/**
  95138. + * Stop the watchdog driver.
  95139. + */
  95140. +
  95141. +static int wdog_stop(void)
  95142. +{
  95143. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  95144. + printk(KERN_INFO "watchdog stopped\n");
  95145. + return 0;
  95146. +}
  95147. +
  95148. +/**
  95149. + * Reload counter one with the watchdog heartbeat. We don't bother
  95150. + * reloading the cascade counter.
  95151. + */
  95152. +
  95153. +static void wdog_ping(void)
  95154. +{
  95155. + wdog_start(wdog_ticks);
  95156. +}
  95157. +
  95158. +/**
  95159. + * @t: the new heartbeat value that needs to be set.
  95160. + *
  95161. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  95162. + * value is incorrect we keep the old value and return -EINVAL. If
  95163. + * successful we return 0.
  95164. + */
  95165. +
  95166. +static int wdog_set_heartbeat(int t)
  95167. +{
  95168. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  95169. + return -EINVAL;
  95170. +
  95171. + heartbeat = t;
  95172. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  95173. + return 0;
  95174. +}
  95175. +
  95176. +/**
  95177. + * @file: file handle to the watchdog
  95178. + * @buf: buffer to write (unused as data does not matter here
  95179. + * @count: count of bytes
  95180. + * @ppos: pointer to the position to write. No seeks allowed
  95181. + *
  95182. + * A write to a watchdog device is defined as a keepalive signal.
  95183. + *
  95184. + * if 'nowayout' is set then normally a close() is ignored. But
  95185. + * if you write 'V' first then the close() will stop the timer.
  95186. + */
  95187. +
  95188. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  95189. + size_t count, loff_t *ppos)
  95190. +{
  95191. + if (count) {
  95192. + if (!nowayout) {
  95193. + size_t i;
  95194. +
  95195. + /* In case it was set long ago */
  95196. + expect_close = 0;
  95197. +
  95198. + for (i = 0; i != count; i++) {
  95199. + char c;
  95200. + if (get_user(c, buf + i))
  95201. + return -EFAULT;
  95202. + if (c == 'V')
  95203. + expect_close = 42;
  95204. + }
  95205. + }
  95206. + wdog_ping();
  95207. + }
  95208. + return count;
  95209. +}
  95210. +
  95211. +static int wdog_get_status(void)
  95212. +{
  95213. + unsigned long flags;
  95214. + int status = 0;
  95215. + spin_lock_irqsave(&wdog_lock, flags);
  95216. + /* FIXME: readback reset reason */
  95217. + spin_unlock_irqrestore(&wdog_lock, flags);
  95218. + return status;
  95219. +}
  95220. +
  95221. +static uint32_t wdog_get_remaining(void)
  95222. +{
  95223. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  95224. + return ret & PM_WDOG_TIME_SET;
  95225. +}
  95226. +
  95227. +/**
  95228. + * @file: file handle to the device
  95229. + * @cmd: watchdog command
  95230. + * @arg: argument pointer
  95231. + *
  95232. + * The watchdog API defines a common set of functions for all watchdogs
  95233. + * according to their available features. We only actually usefully support
  95234. + * querying capabilities and current status.
  95235. + */
  95236. +
  95237. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  95238. +{
  95239. + void __user *argp = (void __user *)arg;
  95240. + int __user *p = argp;
  95241. + int new_heartbeat;
  95242. + int status;
  95243. + int options;
  95244. + uint32_t remaining;
  95245. +
  95246. + struct watchdog_info ident = {
  95247. + .options = WDIOF_SETTIMEOUT|
  95248. + WDIOF_MAGICCLOSE|
  95249. + WDIOF_KEEPALIVEPING,
  95250. + .firmware_version = 1,
  95251. + .identity = "BCM2708",
  95252. + };
  95253. +
  95254. + switch (cmd) {
  95255. + case WDIOC_GETSUPPORT:
  95256. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  95257. + case WDIOC_GETSTATUS:
  95258. + status = wdog_get_status();
  95259. + return put_user(status, p);
  95260. + case WDIOC_GETBOOTSTATUS:
  95261. + return put_user(0, p);
  95262. + case WDIOC_KEEPALIVE:
  95263. + wdog_ping();
  95264. + return 0;
  95265. + case WDIOC_SETTIMEOUT:
  95266. + if (get_user(new_heartbeat, p))
  95267. + return -EFAULT;
  95268. + if (wdog_set_heartbeat(new_heartbeat))
  95269. + return -EINVAL;
  95270. + wdog_ping();
  95271. + /* Fall */
  95272. + case WDIOC_GETTIMEOUT:
  95273. + return put_user(heartbeat, p);
  95274. + case WDIOC_GETTIMELEFT:
  95275. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  95276. + return put_user(remaining, p);
  95277. + case WDIOC_SETOPTIONS:
  95278. + if (get_user(options, p))
  95279. + return -EFAULT;
  95280. + if (options & WDIOS_DISABLECARD)
  95281. + wdog_stop();
  95282. + if (options & WDIOS_ENABLECARD)
  95283. + wdog_start(wdog_ticks);
  95284. + return 0;
  95285. + default:
  95286. + return -ENOTTY;
  95287. + }
  95288. +}
  95289. +
  95290. +/**
  95291. + * @inode: inode of device
  95292. + * @file: file handle to device
  95293. + *
  95294. + * The watchdog device has been opened. The watchdog device is single
  95295. + * open and on opening we load the counters.
  95296. + */
  95297. +
  95298. +static int wdog_open(struct inode *inode, struct file *file)
  95299. +{
  95300. + if (test_and_set_bit(0, &wdog_is_open))
  95301. + return -EBUSY;
  95302. + /*
  95303. + * Activate
  95304. + */
  95305. + wdog_start(wdog_ticks);
  95306. + return nonseekable_open(inode, file);
  95307. +}
  95308. +
  95309. +/**
  95310. + * @inode: inode to board
  95311. + * @file: file handle to board
  95312. + *
  95313. + * The watchdog has a configurable API. There is a religious dispute
  95314. + * between people who want their watchdog to be able to shut down and
  95315. + * those who want to be sure if the watchdog manager dies the machine
  95316. + * reboots. In the former case we disable the counters, in the latter
  95317. + * case you have to open it again very soon.
  95318. + */
  95319. +
  95320. +static int wdog_release(struct inode *inode, struct file *file)
  95321. +{
  95322. + if (expect_close == 42) {
  95323. + wdog_stop();
  95324. + } else {
  95325. + printk(KERN_CRIT
  95326. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  95327. + wdog_ping();
  95328. + }
  95329. + clear_bit(0, &wdog_is_open);
  95330. + expect_close = 0;
  95331. + return 0;
  95332. +}
  95333. +
  95334. +/**
  95335. + * @this: our notifier block
  95336. + * @code: the event being reported
  95337. + * @unused: unused
  95338. + *
  95339. + * Our notifier is called on system shutdowns. Turn the watchdog
  95340. + * off so that it does not fire during the next reboot.
  95341. + */
  95342. +
  95343. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  95344. + void *unused)
  95345. +{
  95346. + if (code == SYS_DOWN || code == SYS_HALT)
  95347. + wdog_stop();
  95348. + return NOTIFY_DONE;
  95349. +}
  95350. +
  95351. +/*
  95352. + * Kernel Interfaces
  95353. + */
  95354. +
  95355. +
  95356. +static const struct file_operations wdog_fops = {
  95357. + .owner = THIS_MODULE,
  95358. + .llseek = no_llseek,
  95359. + .write = wdog_write,
  95360. + .unlocked_ioctl = wdog_ioctl,
  95361. + .open = wdog_open,
  95362. + .release = wdog_release,
  95363. +};
  95364. +
  95365. +static struct miscdevice wdog_miscdev = {
  95366. + .minor = WATCHDOG_MINOR,
  95367. + .name = "watchdog",
  95368. + .fops = &wdog_fops,
  95369. +};
  95370. +
  95371. +/*
  95372. + * The WDT card needs to learn about soft shutdowns in order to
  95373. + * turn the timebomb registers off.
  95374. + */
  95375. +
  95376. +static struct notifier_block wdog_notifier = {
  95377. + .notifier_call = wdog_notify_sys,
  95378. +};
  95379. +
  95380. +/**
  95381. + * cleanup_module:
  95382. + *
  95383. + * Unload the watchdog. You cannot do this with any file handles open.
  95384. + * If your watchdog is set to continue ticking on close and you unload
  95385. + * it, well it keeps ticking. We won't get the interrupt but the board
  95386. + * will not touch PC memory so all is fine. You just have to load a new
  95387. + * module in 60 seconds or reboot.
  95388. + */
  95389. +
  95390. +static void __exit wdog_exit(void)
  95391. +{
  95392. + misc_deregister(&wdog_miscdev);
  95393. + unregister_reboot_notifier(&wdog_notifier);
  95394. +}
  95395. +
  95396. +static int __init wdog_init(void)
  95397. +{
  95398. + int ret;
  95399. +
  95400. + /* Check that the heartbeat value is within it's range;
  95401. + if not reset to the default */
  95402. + if (wdog_set_heartbeat(heartbeat)) {
  95403. + wdog_set_heartbeat(WD_TIMO);
  95404. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  95405. + "0 < heartbeat < %d, using %d\n",
  95406. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  95407. + WD_TIMO);
  95408. + }
  95409. +
  95410. + ret = register_reboot_notifier(&wdog_notifier);
  95411. + if (ret) {
  95412. + printk(KERN_ERR
  95413. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  95414. + goto out_reboot;
  95415. + }
  95416. +
  95417. + ret = misc_register(&wdog_miscdev);
  95418. + if (ret) {
  95419. + printk(KERN_ERR
  95420. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  95421. + WATCHDOG_MINOR, ret);
  95422. + goto out_misc;
  95423. + }
  95424. +
  95425. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  95426. + heartbeat, nowayout);
  95427. + return 0;
  95428. +
  95429. +out_misc:
  95430. + unregister_reboot_notifier(&wdog_notifier);
  95431. +out_reboot:
  95432. + return ret;
  95433. +}
  95434. +
  95435. +module_init(wdog_init);
  95436. +module_exit(wdog_exit);
  95437. +
  95438. +MODULE_AUTHOR("Luke Diamand");
  95439. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  95440. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  95441. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  95442. +MODULE_LICENSE("GPL");
  95443. diff -Nur linux-3.11.10.orig/drivers/watchdog/Kconfig linux-3.11.10/drivers/watchdog/Kconfig
  95444. --- linux-3.11.10.orig/drivers/watchdog/Kconfig 2013-11-29 19:42:37.000000000 +0100
  95445. +++ linux-3.11.10/drivers/watchdog/Kconfig 2014-02-07 19:57:30.000000000 +0100
  95446. @@ -382,6 +382,12 @@
  95447. To compile this driver as a module, choose M here: the
  95448. module will be called retu_wdt.
  95449. +config BCM2708_WDT
  95450. + tristate "BCM2708 Watchdog"
  95451. + depends on ARCH_BCM2708
  95452. + help
  95453. + Enables BCM2708 watchdog support.
  95454. +
  95455. # AVR32 Architecture
  95456. config AT32AP700X_WDT
  95457. diff -Nur linux-3.11.10.orig/drivers/watchdog/Makefile linux-3.11.10/drivers/watchdog/Makefile
  95458. --- linux-3.11.10.orig/drivers/watchdog/Makefile 2013-11-29 19:42:37.000000000 +0100
  95459. +++ linux-3.11.10/drivers/watchdog/Makefile 2014-02-07 19:57:30.000000000 +0100
  95460. @@ -53,6 +53,7 @@
  95461. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  95462. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  95463. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  95464. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  95465. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  95466. # AVR32 Architecture
  95467. diff -Nur linux-3.11.10.orig/include/linux/broadcom/vc_cma.h linux-3.11.10/include/linux/broadcom/vc_cma.h
  95468. --- linux-3.11.10.orig/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  95469. +++ linux-3.11.10/include/linux/broadcom/vc_cma.h 2014-02-07 19:57:30.000000000 +0100
  95470. @@ -0,0 +1,29 @@
  95471. +/*****************************************************************************
  95472. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  95473. +*
  95474. +* Unless you and Broadcom execute a separate written software license
  95475. +* agreement governing use of this software, this software is licensed to you
  95476. +* under the terms of the GNU General Public License version 2, available at
  95477. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  95478. +*
  95479. +* Notwithstanding the above, under no circumstances may you combine this
  95480. +* software in any way with any other Broadcom software provided under a
  95481. +* license other than the GPL, without Broadcom's express prior written
  95482. +* consent.
  95483. +*****************************************************************************/
  95484. +
  95485. +#if !defined( VC_CMA_H )
  95486. +#define VC_CMA_H
  95487. +
  95488. +#include <linux/ioctl.h>
  95489. +
  95490. +#define VC_CMA_IOC_MAGIC 0xc5
  95491. +
  95492. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  95493. +
  95494. +#ifdef __KERNEL__
  95495. +extern void __init vc_cma_early_init(void);
  95496. +extern void __init vc_cma_reserve(void);
  95497. +#endif
  95498. +
  95499. +#endif /* VC_CMA_H */
  95500. diff -Nur linux-3.11.10.orig/include/linux/mmc/host.h linux-3.11.10/include/linux/mmc/host.h
  95501. --- linux-3.11.10.orig/include/linux/mmc/host.h 2013-11-29 19:42:37.000000000 +0100
  95502. +++ linux-3.11.10/include/linux/mmc/host.h 2014-02-07 19:57:30.000000000 +0100
  95503. @@ -281,6 +281,7 @@
  95504. MMC_CAP2_PACKED_WR)
  95505. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  95506. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  95507. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  95508. mmc_pm_flag_t pm_caps; /* supported pm features */
  95509. diff -Nur linux-3.11.10.orig/include/linux/mmc/sdhci.h linux-3.11.10/include/linux/mmc/sdhci.h
  95510. --- linux-3.11.10.orig/include/linux/mmc/sdhci.h 2013-11-29 19:42:37.000000000 +0100
  95511. +++ linux-3.11.10/include/linux/mmc/sdhci.h 2014-02-07 19:57:30.000000000 +0100
  95512. @@ -100,6 +100,7 @@
  95513. #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5)
  95514. int irq; /* Device IRQ */
  95515. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  95516. void __iomem *ioaddr; /* Mapped address */
  95517. const struct sdhci_ops *ops; /* Low level hw interface */
  95518. @@ -131,6 +132,7 @@
  95519. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  95520. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  95521. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  95522. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  95523. unsigned int version; /* SDHCI spec. version */
  95524. @@ -146,6 +148,7 @@
  95525. struct mmc_request *mrq; /* Current request */
  95526. struct mmc_command *cmd; /* Current command */
  95527. + int last_cmdop; /* Opcode of last cmd sent */
  95528. struct mmc_data *data; /* Current data request */
  95529. unsigned int data_early:1; /* Data finished before cmd */
  95530. diff -Nur linux-3.11.10.orig/include/uapi/linux/fb.h linux-3.11.10/include/uapi/linux/fb.h
  95531. --- linux-3.11.10.orig/include/uapi/linux/fb.h 2013-11-29 19:42:37.000000000 +0100
  95532. +++ linux-3.11.10/include/uapi/linux/fb.h 2014-02-07 19:57:30.000000000 +0100
  95533. @@ -34,6 +34,11 @@
  95534. #define FBIOPUT_MODEINFO 0x4617
  95535. #define FBIOGET_DISPINFO 0x4618
  95536. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  95537. +/*
  95538. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  95539. + * be concurrently added to the mainline kernel
  95540. + */
  95541. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  95542. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  95543. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  95544. diff -Nur linux-3.11.10.orig/sound/arm/bcm2835.c linux-3.11.10/sound/arm/bcm2835.c
  95545. --- linux-3.11.10.orig/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  95546. +++ linux-3.11.10/sound/arm/bcm2835.c 2014-02-07 19:57:30.000000000 +0100
  95547. @@ -0,0 +1,413 @@
  95548. +/*****************************************************************************
  95549. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  95550. +*
  95551. +* Unless you and Broadcom execute a separate written software license
  95552. +* agreement governing use of this software, this software is licensed to you
  95553. +* under the terms of the GNU General Public License version 2, available at
  95554. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  95555. +*
  95556. +* Notwithstanding the above, under no circumstances may you combine this
  95557. +* software in any way with any other Broadcom software provided under a
  95558. +* license other than the GPL, without Broadcom's express prior written
  95559. +* consent.
  95560. +*****************************************************************************/
  95561. +
  95562. +#include <linux/platform_device.h>
  95563. +
  95564. +#include <linux/init.h>
  95565. +#include <linux/slab.h>
  95566. +#include <linux/module.h>
  95567. +
  95568. +#include "bcm2835.h"
  95569. +
  95570. +/* module parameters (see "Module Parameters") */
  95571. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  95572. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  95573. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  95574. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  95575. +
  95576. +/* HACKY global pointers needed for successive probes to work : ssp
  95577. + * But compared against the changes we will have to do in VC audio_ipc code
  95578. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  95579. + * four devices in a thread, this gets things done quickly and should be easier
  95580. + * to debug if we run into issues
  95581. + */
  95582. +
  95583. +static struct snd_card *g_card = NULL;
  95584. +static bcm2835_chip_t *g_chip = NULL;
  95585. +
  95586. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  95587. +{
  95588. + kfree(chip);
  95589. + return 0;
  95590. +}
  95591. +
  95592. +/* component-destructor
  95593. + * (see "Management of Cards and Components")
  95594. + */
  95595. +static int snd_bcm2835_dev_free(struct snd_device *device)
  95596. +{
  95597. + return snd_bcm2835_free(device->device_data);
  95598. +}
  95599. +
  95600. +/* chip-specific constructor
  95601. + * (see "Management of Cards and Components")
  95602. + */
  95603. +static int snd_bcm2835_create(struct snd_card *card,
  95604. + struct platform_device *pdev,
  95605. + bcm2835_chip_t ** rchip)
  95606. +{
  95607. + bcm2835_chip_t *chip;
  95608. + int err;
  95609. + static struct snd_device_ops ops = {
  95610. + .dev_free = snd_bcm2835_dev_free,
  95611. + };
  95612. +
  95613. + *rchip = NULL;
  95614. +
  95615. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  95616. + if (chip == NULL)
  95617. + return -ENOMEM;
  95618. +
  95619. + chip->card = card;
  95620. +
  95621. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  95622. + if (err < 0) {
  95623. + snd_bcm2835_free(chip);
  95624. + return err;
  95625. + }
  95626. +
  95627. + *rchip = chip;
  95628. + return 0;
  95629. +}
  95630. +
  95631. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  95632. +{
  95633. + static int dev;
  95634. + bcm2835_chip_t *chip;
  95635. + struct snd_card *card;
  95636. + int err;
  95637. +
  95638. + if (dev >= MAX_SUBSTREAMS)
  95639. + return -ENODEV;
  95640. +
  95641. + if (!enable[dev]) {
  95642. + dev++;
  95643. + return -ENOENT;
  95644. + }
  95645. +
  95646. + if (dev > 0)
  95647. + goto add_register_map;
  95648. +
  95649. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  95650. + if (err < 0)
  95651. + goto out;
  95652. +
  95653. + snd_card_set_dev(g_card, &pdev->dev);
  95654. + strcpy(g_card->driver, "BRCM bcm2835 ALSA Driver");
  95655. + strcpy(g_card->shortname, "bcm2835 ALSA");
  95656. + sprintf(g_card->longname, "%s", g_card->shortname);
  95657. +
  95658. + err = snd_bcm2835_create(g_card, pdev, &chip);
  95659. + if (err < 0) {
  95660. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  95661. + goto out_bcm2835_create;
  95662. + }
  95663. +
  95664. + g_chip = chip;
  95665. + err = snd_bcm2835_new_pcm(chip);
  95666. + if (err < 0) {
  95667. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  95668. + goto out_bcm2835_new_pcm;
  95669. + }
  95670. +
  95671. + err = snd_bcm2835_new_ctl(chip);
  95672. + if (err < 0) {
  95673. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  95674. + goto out_bcm2835_new_ctl;
  95675. + }
  95676. +
  95677. +add_register_map:
  95678. + card = g_card;
  95679. + chip = g_chip;
  95680. +
  95681. + BUG_ON(!(card && chip));
  95682. +
  95683. + chip->avail_substreams |= (1 << dev);
  95684. + chip->pdev[dev] = pdev;
  95685. +
  95686. + if (dev == 0) {
  95687. + err = snd_card_register(card);
  95688. + if (err < 0) {
  95689. + dev_err(&pdev->dev,
  95690. + "Failed to register bcm2835 ALSA card \n");
  95691. + goto out_card_register;
  95692. + }
  95693. + platform_set_drvdata(pdev, card);
  95694. + audio_info("bcm2835 ALSA card created!\n");
  95695. + } else {
  95696. + audio_info("bcm2835 ALSA chip created!\n");
  95697. + platform_set_drvdata(pdev, (void *)dev);
  95698. + }
  95699. +
  95700. + dev++;
  95701. +
  95702. + return 0;
  95703. +
  95704. +out_card_register:
  95705. +out_bcm2835_new_ctl:
  95706. +out_bcm2835_new_pcm:
  95707. +out_bcm2835_create:
  95708. + BUG_ON(!g_card);
  95709. + if (snd_card_free(g_card))
  95710. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  95711. + g_card = NULL;
  95712. +out:
  95713. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  95714. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  95715. + return err;
  95716. +}
  95717. +
  95718. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  95719. +{
  95720. + uint32_t idx;
  95721. + void *drv_data;
  95722. +
  95723. + drv_data = platform_get_drvdata(pdev);
  95724. +
  95725. + if (drv_data == (void *)g_card) {
  95726. + /* This is the card device */
  95727. + snd_card_free((struct snd_card *)drv_data);
  95728. + g_card = NULL;
  95729. + g_chip = NULL;
  95730. + } else {
  95731. + idx = (uint32_t) drv_data;
  95732. + if (g_card != NULL) {
  95733. + BUG_ON(!g_chip);
  95734. + /* We pass chip device numbers in audio ipc devices
  95735. + * other than the one we registered our card with
  95736. + */
  95737. + idx = (uint32_t) drv_data;
  95738. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  95739. + g_chip->avail_substreams &= ~(1 << idx);
  95740. + /* There should be atleast one substream registered
  95741. + * after we are done here, as it wil be removed when
  95742. + * the *remove* is called for the card device
  95743. + */
  95744. + BUG_ON(!g_chip->avail_substreams);
  95745. + }
  95746. + }
  95747. +
  95748. + platform_set_drvdata(pdev, NULL);
  95749. +
  95750. + return 0;
  95751. +}
  95752. +
  95753. +#ifdef CONFIG_PM
  95754. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  95755. + pm_message_t state)
  95756. +{
  95757. + return 0;
  95758. +}
  95759. +
  95760. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  95761. +{
  95762. + return 0;
  95763. +}
  95764. +
  95765. +#endif
  95766. +
  95767. +static struct platform_driver bcm2835_alsa0_driver = {
  95768. + .probe = snd_bcm2835_alsa_probe,
  95769. + .remove = snd_bcm2835_alsa_remove,
  95770. +#ifdef CONFIG_PM
  95771. + .suspend = snd_bcm2835_alsa_suspend,
  95772. + .resume = snd_bcm2835_alsa_resume,
  95773. +#endif
  95774. + .driver = {
  95775. + .name = "bcm2835_AUD0",
  95776. + .owner = THIS_MODULE,
  95777. + },
  95778. +};
  95779. +
  95780. +static struct platform_driver bcm2835_alsa1_driver = {
  95781. + .probe = snd_bcm2835_alsa_probe,
  95782. + .remove = snd_bcm2835_alsa_remove,
  95783. +#ifdef CONFIG_PM
  95784. + .suspend = snd_bcm2835_alsa_suspend,
  95785. + .resume = snd_bcm2835_alsa_resume,
  95786. +#endif
  95787. + .driver = {
  95788. + .name = "bcm2835_AUD1",
  95789. + .owner = THIS_MODULE,
  95790. + },
  95791. +};
  95792. +
  95793. +static struct platform_driver bcm2835_alsa2_driver = {
  95794. + .probe = snd_bcm2835_alsa_probe,
  95795. + .remove = snd_bcm2835_alsa_remove,
  95796. +#ifdef CONFIG_PM
  95797. + .suspend = snd_bcm2835_alsa_suspend,
  95798. + .resume = snd_bcm2835_alsa_resume,
  95799. +#endif
  95800. + .driver = {
  95801. + .name = "bcm2835_AUD2",
  95802. + .owner = THIS_MODULE,
  95803. + },
  95804. +};
  95805. +
  95806. +static struct platform_driver bcm2835_alsa3_driver = {
  95807. + .probe = snd_bcm2835_alsa_probe,
  95808. + .remove = snd_bcm2835_alsa_remove,
  95809. +#ifdef CONFIG_PM
  95810. + .suspend = snd_bcm2835_alsa_suspend,
  95811. + .resume = snd_bcm2835_alsa_resume,
  95812. +#endif
  95813. + .driver = {
  95814. + .name = "bcm2835_AUD3",
  95815. + .owner = THIS_MODULE,
  95816. + },
  95817. +};
  95818. +
  95819. +static struct platform_driver bcm2835_alsa4_driver = {
  95820. + .probe = snd_bcm2835_alsa_probe,
  95821. + .remove = snd_bcm2835_alsa_remove,
  95822. +#ifdef CONFIG_PM
  95823. + .suspend = snd_bcm2835_alsa_suspend,
  95824. + .resume = snd_bcm2835_alsa_resume,
  95825. +#endif
  95826. + .driver = {
  95827. + .name = "bcm2835_AUD4",
  95828. + .owner = THIS_MODULE,
  95829. + },
  95830. +};
  95831. +
  95832. +static struct platform_driver bcm2835_alsa5_driver = {
  95833. + .probe = snd_bcm2835_alsa_probe,
  95834. + .remove = snd_bcm2835_alsa_remove,
  95835. +#ifdef CONFIG_PM
  95836. + .suspend = snd_bcm2835_alsa_suspend,
  95837. + .resume = snd_bcm2835_alsa_resume,
  95838. +#endif
  95839. + .driver = {
  95840. + .name = "bcm2835_AUD5",
  95841. + .owner = THIS_MODULE,
  95842. + },
  95843. +};
  95844. +
  95845. +static struct platform_driver bcm2835_alsa6_driver = {
  95846. + .probe = snd_bcm2835_alsa_probe,
  95847. + .remove = snd_bcm2835_alsa_remove,
  95848. +#ifdef CONFIG_PM
  95849. + .suspend = snd_bcm2835_alsa_suspend,
  95850. + .resume = snd_bcm2835_alsa_resume,
  95851. +#endif
  95852. + .driver = {
  95853. + .name = "bcm2835_AUD6",
  95854. + .owner = THIS_MODULE,
  95855. + },
  95856. +};
  95857. +
  95858. +static struct platform_driver bcm2835_alsa7_driver = {
  95859. + .probe = snd_bcm2835_alsa_probe,
  95860. + .remove = snd_bcm2835_alsa_remove,
  95861. +#ifdef CONFIG_PM
  95862. + .suspend = snd_bcm2835_alsa_suspend,
  95863. + .resume = snd_bcm2835_alsa_resume,
  95864. +#endif
  95865. + .driver = {
  95866. + .name = "bcm2835_AUD7",
  95867. + .owner = THIS_MODULE,
  95868. + },
  95869. +};
  95870. +
  95871. +static int bcm2835_alsa_device_init(void)
  95872. +{
  95873. + int err;
  95874. + err = platform_driver_register(&bcm2835_alsa0_driver);
  95875. + if (err) {
  95876. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95877. + goto out;
  95878. + }
  95879. +
  95880. + err = platform_driver_register(&bcm2835_alsa1_driver);
  95881. + if (err) {
  95882. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95883. + goto unregister_0;
  95884. + }
  95885. +
  95886. + err = platform_driver_register(&bcm2835_alsa2_driver);
  95887. + if (err) {
  95888. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95889. + goto unregister_1;
  95890. + }
  95891. +
  95892. + err = platform_driver_register(&bcm2835_alsa3_driver);
  95893. + if (err) {
  95894. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95895. + goto unregister_2;
  95896. + }
  95897. +
  95898. + err = platform_driver_register(&bcm2835_alsa4_driver);
  95899. + if (err) {
  95900. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95901. + goto unregister_3;
  95902. + }
  95903. +
  95904. + err = platform_driver_register(&bcm2835_alsa5_driver);
  95905. + if (err) {
  95906. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95907. + goto unregister_4;
  95908. + }
  95909. +
  95910. + err = platform_driver_register(&bcm2835_alsa6_driver);
  95911. + if (err) {
  95912. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95913. + goto unregister_5;
  95914. + }
  95915. +
  95916. + err = platform_driver_register(&bcm2835_alsa7_driver);
  95917. + if (err) {
  95918. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  95919. + goto unregister_6;
  95920. + }
  95921. +
  95922. + return 0;
  95923. +
  95924. +unregister_6:
  95925. + platform_driver_unregister(&bcm2835_alsa6_driver);
  95926. +unregister_5:
  95927. + platform_driver_unregister(&bcm2835_alsa5_driver);
  95928. +unregister_4:
  95929. + platform_driver_unregister(&bcm2835_alsa4_driver);
  95930. +unregister_3:
  95931. + platform_driver_unregister(&bcm2835_alsa3_driver);
  95932. +unregister_2:
  95933. + platform_driver_unregister(&bcm2835_alsa2_driver);
  95934. +unregister_1:
  95935. + platform_driver_unregister(&bcm2835_alsa1_driver);
  95936. +unregister_0:
  95937. + platform_driver_unregister(&bcm2835_alsa0_driver);
  95938. +out:
  95939. + return err;
  95940. +}
  95941. +
  95942. +static void bcm2835_alsa_device_exit(void)
  95943. +{
  95944. + platform_driver_unregister(&bcm2835_alsa0_driver);
  95945. + platform_driver_unregister(&bcm2835_alsa1_driver);
  95946. + platform_driver_unregister(&bcm2835_alsa2_driver);
  95947. + platform_driver_unregister(&bcm2835_alsa3_driver);
  95948. + platform_driver_unregister(&bcm2835_alsa4_driver);
  95949. + platform_driver_unregister(&bcm2835_alsa5_driver);
  95950. + platform_driver_unregister(&bcm2835_alsa6_driver);
  95951. + platform_driver_unregister(&bcm2835_alsa7_driver);
  95952. +}
  95953. +
  95954. +late_initcall(bcm2835_alsa_device_init);
  95955. +module_exit(bcm2835_alsa_device_exit);
  95956. +
  95957. +MODULE_AUTHOR("Dom Cobley");
  95958. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  95959. +MODULE_LICENSE("GPL");
  95960. +MODULE_ALIAS("platform:bcm2835_alsa");
  95961. diff -Nur linux-3.11.10.orig/sound/arm/bcm2835-ctl.c linux-3.11.10/sound/arm/bcm2835-ctl.c
  95962. --- linux-3.11.10.orig/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  95963. +++ linux-3.11.10/sound/arm/bcm2835-ctl.c 2014-02-07 19:57:30.000000000 +0100
  95964. @@ -0,0 +1,200 @@
  95965. +/*****************************************************************************
  95966. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  95967. +*
  95968. +* Unless you and Broadcom execute a separate written software license
  95969. +* agreement governing use of this software, this software is licensed to you
  95970. +* under the terms of the GNU General Public License version 2, available at
  95971. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  95972. +*
  95973. +* Notwithstanding the above, under no circumstances may you combine this
  95974. +* software in any way with any other Broadcom software provided under a
  95975. +* license other than the GPL, without Broadcom's express prior written
  95976. +* consent.
  95977. +*****************************************************************************/
  95978. +
  95979. +#include <linux/platform_device.h>
  95980. +#include <linux/init.h>
  95981. +#include <linux/io.h>
  95982. +#include <linux/jiffies.h>
  95983. +#include <linux/slab.h>
  95984. +#include <linux/time.h>
  95985. +#include <linux/wait.h>
  95986. +#include <linux/delay.h>
  95987. +#include <linux/moduleparam.h>
  95988. +#include <linux/sched.h>
  95989. +
  95990. +#include <sound/core.h>
  95991. +#include <sound/control.h>
  95992. +#include <sound/pcm.h>
  95993. +#include <sound/pcm_params.h>
  95994. +#include <sound/rawmidi.h>
  95995. +#include <sound/initval.h>
  95996. +#include <sound/tlv.h>
  95997. +
  95998. +#include "bcm2835.h"
  95999. +
  96000. +/* volume maximum and minimum in terms of 0.01dB */
  96001. +#define CTRL_VOL_MAX 400
  96002. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  96003. +
  96004. +
  96005. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  96006. + struct snd_ctl_elem_info *uinfo)
  96007. +{
  96008. + audio_info(" ... IN\n");
  96009. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  96010. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  96011. + uinfo->count = 1;
  96012. + uinfo->value.integer.min = CTRL_VOL_MIN;
  96013. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  96014. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  96015. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  96016. + uinfo->count = 1;
  96017. + uinfo->value.integer.min = 0;
  96018. + uinfo->value.integer.max = 1;
  96019. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  96020. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  96021. + uinfo->count = 1;
  96022. + uinfo->value.integer.min = 0;
  96023. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  96024. + }
  96025. + audio_info(" ... OUT\n");
  96026. + return 0;
  96027. +}
  96028. +
  96029. +/* toggles mute on or off depending on the value of nmute, and returns
  96030. + * 1 if the mute value was changed, otherwise 0
  96031. + */
  96032. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  96033. +{
  96034. + /* if settings are ok, just return 0 */
  96035. + if(chip->mute == nmute)
  96036. + return 0;
  96037. +
  96038. + /* if the sound is muted then we need to unmute */
  96039. + if(chip->mute == CTRL_VOL_MUTE)
  96040. + {
  96041. + chip->volume = chip->old_volume; /* copy the old volume back */
  96042. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  96043. + }
  96044. + else /* otherwise we mute */
  96045. + {
  96046. + chip->old_volume = chip->volume;
  96047. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  96048. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  96049. + }
  96050. +
  96051. + chip->mute = nmute;
  96052. + return 1;
  96053. +}
  96054. +
  96055. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  96056. + struct snd_ctl_elem_value *ucontrol)
  96057. +{
  96058. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  96059. +
  96060. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  96061. +
  96062. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  96063. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  96064. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  96065. + ucontrol->value.integer.value[0] = chip->mute;
  96066. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  96067. + ucontrol->value.integer.value[0] = chip->dest;
  96068. +
  96069. + return 0;
  96070. +}
  96071. +
  96072. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  96073. + struct snd_ctl_elem_value *ucontrol)
  96074. +{
  96075. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  96076. + int changed = 0;
  96077. +
  96078. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  96079. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  96080. + if (chip->mute == CTRL_VOL_MUTE) {
  96081. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  96082. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  96083. + }
  96084. + if (changed
  96085. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  96086. +
  96087. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  96088. + changed = 1;
  96089. + }
  96090. +
  96091. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  96092. + /* Now implemented */
  96093. + audio_info(" Mute attempted\n");
  96094. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  96095. +
  96096. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  96097. + if (ucontrol->value.integer.value[0] != chip->dest) {
  96098. + chip->dest = ucontrol->value.integer.value[0];
  96099. + changed = 1;
  96100. + }
  96101. + }
  96102. +
  96103. + if (changed) {
  96104. + if (bcm2835_audio_set_ctls(chip))
  96105. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  96106. + }
  96107. +
  96108. + return changed;
  96109. +}
  96110. +
  96111. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  96112. +
  96113. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  96114. + {
  96115. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96116. + .name = "PCM Playback Volume",
  96117. + .index = 0,
  96118. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  96119. + .private_value = PCM_PLAYBACK_VOLUME,
  96120. + .info = snd_bcm2835_ctl_info,
  96121. + .get = snd_bcm2835_ctl_get,
  96122. + .put = snd_bcm2835_ctl_put,
  96123. + .count = 1,
  96124. + .tlv = {.p = snd_bcm2835_db_scale}
  96125. + },
  96126. + {
  96127. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96128. + .name = "PCM Playback Switch",
  96129. + .index = 0,
  96130. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  96131. + .private_value = PCM_PLAYBACK_MUTE,
  96132. + .info = snd_bcm2835_ctl_info,
  96133. + .get = snd_bcm2835_ctl_get,
  96134. + .put = snd_bcm2835_ctl_put,
  96135. + .count = 1,
  96136. + },
  96137. + {
  96138. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  96139. + .name = "PCM Playback Route",
  96140. + .index = 0,
  96141. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  96142. + .private_value = PCM_PLAYBACK_DEVICE,
  96143. + .info = snd_bcm2835_ctl_info,
  96144. + .get = snd_bcm2835_ctl_get,
  96145. + .put = snd_bcm2835_ctl_put,
  96146. + .count = 1,
  96147. + },
  96148. +};
  96149. +
  96150. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  96151. +{
  96152. + int err;
  96153. + unsigned int idx;
  96154. +
  96155. + strcpy(chip->card->mixername, "Broadcom Mixer");
  96156. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  96157. + err =
  96158. + snd_ctl_add(chip->card,
  96159. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  96160. + if (err < 0)
  96161. + return err;
  96162. + }
  96163. + return 0;
  96164. +}
  96165. diff -Nur linux-3.11.10.orig/sound/arm/bcm2835.h linux-3.11.10/sound/arm/bcm2835.h
  96166. --- linux-3.11.10.orig/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  96167. +++ linux-3.11.10/sound/arm/bcm2835.h 2014-02-07 19:57:30.000000000 +0100
  96168. @@ -0,0 +1,157 @@
  96169. +/*****************************************************************************
  96170. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96171. +*
  96172. +* Unless you and Broadcom execute a separate written software license
  96173. +* agreement governing use of this software, this software is licensed to you
  96174. +* under the terms of the GNU General Public License version 2, available at
  96175. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96176. +*
  96177. +* Notwithstanding the above, under no circumstances may you combine this
  96178. +* software in any way with any other Broadcom software provided under a
  96179. +* license other than the GPL, without Broadcom's express prior written
  96180. +* consent.
  96181. +*****************************************************************************/
  96182. +
  96183. +#ifndef __SOUND_ARM_BCM2835_H
  96184. +#define __SOUND_ARM_BCM2835_H
  96185. +
  96186. +#include <linux/device.h>
  96187. +#include <linux/list.h>
  96188. +#include <linux/interrupt.h>
  96189. +#include <linux/wait.h>
  96190. +#include <sound/core.h>
  96191. +#include <sound/initval.h>
  96192. +#include <sound/pcm.h>
  96193. +#include <sound/pcm_params.h>
  96194. +#include <sound/pcm-indirect.h>
  96195. +#include <linux/workqueue.h>
  96196. +
  96197. +/*
  96198. +#define AUDIO_DEBUG_ENABLE
  96199. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  96200. +*/
  96201. +
  96202. +/* Debug macros */
  96203. +
  96204. +#ifdef AUDIO_DEBUG_ENABLE
  96205. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  96206. +
  96207. +#define audio_debug(fmt, arg...) \
  96208. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  96209. +
  96210. +#define audio_info(fmt, arg...) \
  96211. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  96212. +
  96213. +#else
  96214. +
  96215. +#define audio_debug(fmt, arg...)
  96216. +
  96217. +#define audio_info(fmt, arg...)
  96218. +
  96219. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  96220. +
  96221. +#else
  96222. +
  96223. +#define audio_debug(fmt, arg...)
  96224. +
  96225. +#define audio_info(fmt, arg...)
  96226. +
  96227. +#endif /* AUDIO_DEBUG_ENABLE */
  96228. +
  96229. +#define audio_error(fmt, arg...) \
  96230. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  96231. +
  96232. +#define audio_warning(fmt, arg...) \
  96233. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  96234. +
  96235. +#define audio_alert(fmt, arg...) \
  96236. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  96237. +
  96238. +#define MAX_SUBSTREAMS (8)
  96239. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  96240. +enum {
  96241. + CTRL_VOL_MUTE,
  96242. + CTRL_VOL_UNMUTE
  96243. +};
  96244. +
  96245. +/* macros for alsa2chip and chip2alsa, instead of functions */
  96246. +
  96247. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  96248. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  96249. +
  96250. +/* Some constants for values .. */
  96251. +typedef enum {
  96252. + AUDIO_DEST_AUTO = 0,
  96253. + AUDIO_DEST_HEADPHONES = 1,
  96254. + AUDIO_DEST_HDMI = 2,
  96255. + AUDIO_DEST_MAX,
  96256. +} SND_BCM2835_ROUTE_T;
  96257. +
  96258. +typedef enum {
  96259. + PCM_PLAYBACK_VOLUME,
  96260. + PCM_PLAYBACK_MUTE,
  96261. + PCM_PLAYBACK_DEVICE,
  96262. +} SND_BCM2835_CTRL_T;
  96263. +
  96264. +/* definition of the chip-specific record */
  96265. +typedef struct bcm2835_chip {
  96266. + struct snd_card *card;
  96267. + struct snd_pcm *pcm;
  96268. + /* Bitmat for valid reg_base and irq numbers */
  96269. + uint32_t avail_substreams;
  96270. + struct platform_device *pdev[MAX_SUBSTREAMS];
  96271. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  96272. +
  96273. + int volume;
  96274. + int old_volume; /* stores the volume value whist muted */
  96275. + int dest;
  96276. + int mute;
  96277. +} bcm2835_chip_t;
  96278. +
  96279. +typedef struct bcm2835_alsa_stream {
  96280. + bcm2835_chip_t *chip;
  96281. + struct snd_pcm_substream *substream;
  96282. + struct snd_pcm_indirect pcm_indirect;
  96283. +
  96284. + struct semaphore buffers_update_sem;
  96285. + struct semaphore control_sem;
  96286. + spinlock_t lock;
  96287. + volatile uint32_t control;
  96288. + volatile uint32_t status;
  96289. +
  96290. + int open;
  96291. + int running;
  96292. + int draining;
  96293. +
  96294. + unsigned int pos;
  96295. + unsigned int buffer_size;
  96296. + unsigned int period_size;
  96297. +
  96298. + uint32_t enable_fifo_irq;
  96299. + irq_handler_t fifo_irq_handler;
  96300. +
  96301. + atomic_t retrieved;
  96302. + struct opaque_AUDIO_INSTANCE_T *instance;
  96303. + struct workqueue_struct *my_wq;
  96304. + int idx;
  96305. +} bcm2835_alsa_stream_t;
  96306. +
  96307. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  96308. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  96309. +
  96310. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  96311. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  96312. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  96313. + uint32_t channels, uint32_t samplerate,
  96314. + uint32_t bps);
  96315. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  96316. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  96317. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  96318. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  96319. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  96320. + void *src);
  96321. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96322. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96323. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  96324. +
  96325. +#endif /* __SOUND_ARM_BCM2835_H */
  96326. diff -Nur linux-3.11.10.orig/sound/arm/bcm2835-pcm.c linux-3.11.10/sound/arm/bcm2835-pcm.c
  96327. --- linux-3.11.10.orig/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  96328. +++ linux-3.11.10/sound/arm/bcm2835-pcm.c 2014-02-07 19:57:30.000000000 +0100
  96329. @@ -0,0 +1,426 @@
  96330. +/*****************************************************************************
  96331. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96332. +*
  96333. +* Unless you and Broadcom execute a separate written software license
  96334. +* agreement governing use of this software, this software is licensed to you
  96335. +* under the terms of the GNU General Public License version 2, available at
  96336. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96337. +*
  96338. +* Notwithstanding the above, under no circumstances may you combine this
  96339. +* software in any way with any other Broadcom software provided under a
  96340. +* license other than the GPL, without Broadcom's express prior written
  96341. +* consent.
  96342. +*****************************************************************************/
  96343. +
  96344. +#include <linux/interrupt.h>
  96345. +#include <linux/slab.h>
  96346. +
  96347. +#include "bcm2835.h"
  96348. +
  96349. +/* hardware definition */
  96350. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  96351. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  96352. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  96353. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  96354. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  96355. + .rate_min = 8000,
  96356. + .rate_max = 48000,
  96357. + .channels_min = 1,
  96358. + .channels_max = 2,
  96359. + .buffer_bytes_max = 128 * 1024,
  96360. + .period_bytes_min = 1 * 1024,
  96361. + .period_bytes_max = 128 * 1024,
  96362. + .periods_min = 1,
  96363. + .periods_max = 128,
  96364. +};
  96365. +
  96366. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  96367. +{
  96368. + audio_info("Freeing up alsa stream here ..\n");
  96369. + if (runtime->private_data)
  96370. + kfree(runtime->private_data);
  96371. + runtime->private_data = NULL;
  96372. +}
  96373. +
  96374. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  96375. +{
  96376. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  96377. + uint32_t consumed = 0;
  96378. + int new_period = 0;
  96379. +
  96380. + audio_info(" .. IN\n");
  96381. +
  96382. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  96383. + alsa_stream ? alsa_stream->substream : 0);
  96384. +
  96385. + if (alsa_stream->open)
  96386. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  96387. +
  96388. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  96389. + * each iteration are the buffers that have been played out already
  96390. + */
  96391. +
  96392. + if (alsa_stream->period_size) {
  96393. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  96394. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  96395. + new_period = 1;
  96396. + }
  96397. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  96398. + alsa_stream->pos,
  96399. + consumed,
  96400. + alsa_stream->buffer_size,
  96401. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  96402. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  96403. + new_period);
  96404. + if (alsa_stream->buffer_size) {
  96405. + alsa_stream->pos += consumed &~ (1<<30);
  96406. + alsa_stream->pos %= alsa_stream->buffer_size;
  96407. + }
  96408. +
  96409. + if (alsa_stream->substream) {
  96410. + if (new_period)
  96411. + snd_pcm_period_elapsed(alsa_stream->substream);
  96412. + } else {
  96413. + audio_warning(" unexpected NULL substream\n");
  96414. + }
  96415. + audio_info(" .. OUT\n");
  96416. +
  96417. + return IRQ_HANDLED;
  96418. +}
  96419. +
  96420. +/* open callback */
  96421. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  96422. +{
  96423. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  96424. + struct snd_pcm_runtime *runtime = substream->runtime;
  96425. + bcm2835_alsa_stream_t *alsa_stream;
  96426. + int idx;
  96427. + int err;
  96428. +
  96429. + audio_info(" .. IN (%d)\n", substream->number);
  96430. +
  96431. + audio_info("Alsa open (%d)\n", substream->number);
  96432. + idx = substream->number;
  96433. +
  96434. + if (idx > MAX_SUBSTREAMS) {
  96435. + audio_error
  96436. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  96437. + idx, MAX_SUBSTREAMS);
  96438. + err = -ENODEV;
  96439. + goto out;
  96440. + }
  96441. +
  96442. + /* Check if we are ready */
  96443. + if (!(chip->avail_substreams & (1 << idx))) {
  96444. + /* We are not ready yet */
  96445. + audio_error("substream(%d) device is not ready yet\n", idx);
  96446. + err = -EAGAIN;
  96447. + goto out;
  96448. + }
  96449. +
  96450. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  96451. + if (alsa_stream == NULL) {
  96452. + return -ENOMEM;
  96453. + }
  96454. +
  96455. + /* Initialise alsa_stream */
  96456. + alsa_stream->chip = chip;
  96457. + alsa_stream->substream = substream;
  96458. + alsa_stream->idx = idx;
  96459. + chip->alsa_stream[idx] = alsa_stream;
  96460. +
  96461. + sema_init(&alsa_stream->buffers_update_sem, 0);
  96462. + sema_init(&alsa_stream->control_sem, 0);
  96463. + spin_lock_init(&alsa_stream->lock);
  96464. +
  96465. + /* Enabled in start trigger, called on each "fifo irq" after that */
  96466. + alsa_stream->enable_fifo_irq = 0;
  96467. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  96468. +
  96469. + runtime->private_data = alsa_stream;
  96470. + runtime->private_free = snd_bcm2835_playback_free;
  96471. + runtime->hw = snd_bcm2835_playback_hw;
  96472. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  96473. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  96474. + 16);
  96475. +
  96476. + err = bcm2835_audio_open(alsa_stream);
  96477. + if (err != 0) {
  96478. + kfree(alsa_stream);
  96479. + return err;
  96480. + }
  96481. +
  96482. + alsa_stream->open = 1;
  96483. + alsa_stream->draining = 1;
  96484. +
  96485. +out:
  96486. + audio_info(" .. OUT =%d\n", err);
  96487. +
  96488. + return err;
  96489. +}
  96490. +
  96491. +/* close callback */
  96492. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  96493. +{
  96494. + /* the hardware-specific codes will be here */
  96495. +
  96496. + struct snd_pcm_runtime *runtime = substream->runtime;
  96497. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96498. +
  96499. + audio_info(" .. IN\n");
  96500. + audio_info("Alsa close\n");
  96501. +
  96502. + /*
  96503. + * Call stop if it's still running. This happens when app
  96504. + * is force killed and we don't get a stop trigger.
  96505. + */
  96506. + if (alsa_stream->running) {
  96507. + int err;
  96508. + err = bcm2835_audio_stop(alsa_stream);
  96509. + alsa_stream->running = 0;
  96510. + if (err != 0)
  96511. + audio_error(" Failed to STOP alsa device\n");
  96512. + }
  96513. +
  96514. + alsa_stream->period_size = 0;
  96515. + alsa_stream->buffer_size = 0;
  96516. +
  96517. + if (alsa_stream->open) {
  96518. + alsa_stream->open = 0;
  96519. + bcm2835_audio_close(alsa_stream);
  96520. + }
  96521. + if (alsa_stream->chip)
  96522. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  96523. + /*
  96524. + * Do not free up alsa_stream here, it will be freed up by
  96525. + * runtime->private_free callback we registered in *_open above
  96526. + */
  96527. +
  96528. + audio_info(" .. OUT\n");
  96529. +
  96530. + return 0;
  96531. +}
  96532. +
  96533. +/* hw_params callback */
  96534. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  96535. + struct snd_pcm_hw_params *params)
  96536. +{
  96537. + int err;
  96538. + struct snd_pcm_runtime *runtime = substream->runtime;
  96539. + bcm2835_alsa_stream_t *alsa_stream =
  96540. + (bcm2835_alsa_stream_t *) runtime->private_data;
  96541. +
  96542. + audio_info(" .. IN\n");
  96543. +
  96544. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  96545. + if (err < 0) {
  96546. + audio_error
  96547. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  96548. + return err;
  96549. + }
  96550. +
  96551. + err = bcm2835_audio_set_params(alsa_stream, params_channels(params),
  96552. + params_rate(params),
  96553. + snd_pcm_format_width(params_format
  96554. + (params)));
  96555. + if (err < 0) {
  96556. + audio_error(" error setting hw params\n");
  96557. + }
  96558. +
  96559. + bcm2835_audio_setup(alsa_stream);
  96560. +
  96561. + /* in preparation of the stream, set the controls (volume level) of the stream */
  96562. + bcm2835_audio_set_ctls(alsa_stream->chip);
  96563. +
  96564. + audio_info(" .. OUT\n");
  96565. +
  96566. + return err;
  96567. +}
  96568. +
  96569. +/* hw_free callback */
  96570. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  96571. +{
  96572. + audio_info(" .. IN\n");
  96573. + return snd_pcm_lib_free_pages(substream);
  96574. +}
  96575. +
  96576. +/* prepare callback */
  96577. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  96578. +{
  96579. + struct snd_pcm_runtime *runtime = substream->runtime;
  96580. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96581. +
  96582. + audio_info(" .. IN\n");
  96583. +
  96584. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  96585. +
  96586. + alsa_stream->pcm_indirect.hw_buffer_size =
  96587. + alsa_stream->pcm_indirect.sw_buffer_size =
  96588. + snd_pcm_lib_buffer_bytes(substream);
  96589. +
  96590. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  96591. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  96592. + alsa_stream->pos = 0;
  96593. +
  96594. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  96595. + alsa_stream->buffer_size, alsa_stream->period_size,
  96596. + alsa_stream->pos, runtime->frame_bits);
  96597. +
  96598. + audio_info(" .. OUT\n");
  96599. + return 0;
  96600. +}
  96601. +
  96602. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  96603. + struct snd_pcm_indirect *rec, size_t bytes)
  96604. +{
  96605. + struct snd_pcm_runtime *runtime = substream->runtime;
  96606. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96607. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  96608. + int err;
  96609. +
  96610. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  96611. + if (err)
  96612. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  96613. +
  96614. +}
  96615. +
  96616. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  96617. +{
  96618. + struct snd_pcm_runtime *runtime = substream->runtime;
  96619. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96620. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  96621. +
  96622. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  96623. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  96624. + snd_bcm2835_pcm_transfer);
  96625. + return 0;
  96626. +}
  96627. +
  96628. +/* trigger callback */
  96629. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  96630. +{
  96631. + struct snd_pcm_runtime *runtime = substream->runtime;
  96632. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96633. + int err = 0;
  96634. +
  96635. + audio_info(" .. IN\n");
  96636. +
  96637. + switch (cmd) {
  96638. + case SNDRV_PCM_TRIGGER_START:
  96639. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  96640. + alsa_stream->running);
  96641. + if (!alsa_stream->running) {
  96642. + err = bcm2835_audio_start(alsa_stream);
  96643. + if (err == 0) {
  96644. + alsa_stream->pcm_indirect.hw_io =
  96645. + alsa_stream->pcm_indirect.hw_data =
  96646. + bytes_to_frames(runtime,
  96647. + alsa_stream->pos);
  96648. + substream->ops->ack(substream);
  96649. + alsa_stream->running = 1;
  96650. + alsa_stream->draining = 1;
  96651. + } else {
  96652. + audio_error(" Failed to START alsa device (%d)\n", err);
  96653. + }
  96654. + }
  96655. + break;
  96656. + case SNDRV_PCM_TRIGGER_STOP:
  96657. + audio_debug
  96658. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  96659. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  96660. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  96661. + audio_info("DRAINING\n");
  96662. + alsa_stream->draining = 1;
  96663. + } else {
  96664. + audio_info("DROPPING\n");
  96665. + alsa_stream->draining = 0;
  96666. + }
  96667. + if (alsa_stream->running) {
  96668. + err = bcm2835_audio_stop(alsa_stream);
  96669. + if (err != 0)
  96670. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  96671. + alsa_stream->running = 0;
  96672. + }
  96673. + break;
  96674. + default:
  96675. + err = -EINVAL;
  96676. + }
  96677. +
  96678. + audio_info(" .. OUT\n");
  96679. + return err;
  96680. +}
  96681. +
  96682. +/* pointer callback */
  96683. +static snd_pcm_uframes_t
  96684. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  96685. +{
  96686. + struct snd_pcm_runtime *runtime = substream->runtime;
  96687. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  96688. +
  96689. + audio_info(" .. IN\n");
  96690. +
  96691. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  96692. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  96693. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  96694. + alsa_stream->pos);
  96695. +
  96696. + audio_info(" .. OUT\n");
  96697. + return snd_pcm_indirect_playback_pointer(substream,
  96698. + &alsa_stream->pcm_indirect,
  96699. + alsa_stream->pos);
  96700. +}
  96701. +
  96702. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  96703. + unsigned int cmd, void *arg)
  96704. +{
  96705. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  96706. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  96707. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  96708. + return ret;
  96709. +}
  96710. +
  96711. +/* operators */
  96712. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  96713. + .open = snd_bcm2835_playback_open,
  96714. + .close = snd_bcm2835_playback_close,
  96715. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  96716. + .hw_params = snd_bcm2835_pcm_hw_params,
  96717. + .hw_free = snd_bcm2835_pcm_hw_free,
  96718. + .prepare = snd_bcm2835_pcm_prepare,
  96719. + .trigger = snd_bcm2835_pcm_trigger,
  96720. + .pointer = snd_bcm2835_pcm_pointer,
  96721. + .ack = snd_bcm2835_pcm_ack,
  96722. +};
  96723. +
  96724. +/* create a pcm device */
  96725. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  96726. +{
  96727. + struct snd_pcm *pcm;
  96728. + int err;
  96729. +
  96730. + audio_info(" .. IN\n");
  96731. + err =
  96732. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  96733. + if (err < 0)
  96734. + return err;
  96735. + pcm->private_data = chip;
  96736. + strcpy(pcm->name, "bcm2835 ALSA");
  96737. + chip->pcm = pcm;
  96738. + chip->dest = AUDIO_DEST_AUTO;
  96739. + chip->volume = alsa2chip(0);
  96740. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  96741. + /* set operators */
  96742. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  96743. + &snd_bcm2835_playback_ops);
  96744. +
  96745. + /* pre-allocation of buffers */
  96746. + /* NOTE: this may fail */
  96747. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  96748. + snd_dma_continuous_data
  96749. + (GFP_KERNEL), 64 * 1024,
  96750. + 64 * 1024);
  96751. +
  96752. + audio_info(" .. OUT\n");
  96753. +
  96754. + return 0;
  96755. +}
  96756. diff -Nur linux-3.11.10.orig/sound/arm/bcm2835-vchiq.c linux-3.11.10/sound/arm/bcm2835-vchiq.c
  96757. --- linux-3.11.10.orig/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  96758. +++ linux-3.11.10/sound/arm/bcm2835-vchiq.c 2014-02-07 19:57:30.000000000 +0100
  96759. @@ -0,0 +1,879 @@
  96760. +/*****************************************************************************
  96761. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  96762. +*
  96763. +* Unless you and Broadcom execute a separate written software license
  96764. +* agreement governing use of this software, this software is licensed to you
  96765. +* under the terms of the GNU General Public License version 2, available at
  96766. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  96767. +*
  96768. +* Notwithstanding the above, under no circumstances may you combine this
  96769. +* software in any way with any other Broadcom software provided under a
  96770. +* license other than the GPL, without Broadcom's express prior written
  96771. +* consent.
  96772. +*****************************************************************************/
  96773. +
  96774. +#include <linux/device.h>
  96775. +#include <sound/core.h>
  96776. +#include <sound/initval.h>
  96777. +#include <sound/pcm.h>
  96778. +#include <linux/io.h>
  96779. +#include <linux/interrupt.h>
  96780. +#include <linux/fs.h>
  96781. +#include <linux/file.h>
  96782. +#include <linux/mm.h>
  96783. +#include <linux/syscalls.h>
  96784. +#include <asm/uaccess.h>
  96785. +#include <linux/slab.h>
  96786. +#include <linux/delay.h>
  96787. +#include <linux/atomic.h>
  96788. +#include <linux/module.h>
  96789. +#include <linux/completion.h>
  96790. +
  96791. +#include "bcm2835.h"
  96792. +
  96793. +/* ---- Include Files -------------------------------------------------------- */
  96794. +
  96795. +#include "interface/vchi/vchi.h"
  96796. +#include "vc_vchi_audioserv_defs.h"
  96797. +
  96798. +/* ---- Private Constants and Types ------------------------------------------ */
  96799. +
  96800. +#define BCM2835_AUDIO_STOP 0
  96801. +#define BCM2835_AUDIO_START 1
  96802. +#define BCM2835_AUDIO_WRITE 2
  96803. +
  96804. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  96805. +#ifdef AUDIO_DEBUG_ENABLE
  96806. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96807. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96808. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96809. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96810. +#else
  96811. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  96812. + #define LOG_WARN( fmt, arg... )
  96813. + #define LOG_INFO( fmt, arg... )
  96814. + #define LOG_DBG( fmt, arg... )
  96815. +#endif
  96816. +
  96817. +typedef struct opaque_AUDIO_INSTANCE_T {
  96818. + uint32_t num_connections;
  96819. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  96820. + struct completion msg_avail_comp;
  96821. + struct mutex vchi_mutex;
  96822. + bcm2835_alsa_stream_t *alsa_stream;
  96823. + int32_t result;
  96824. + short peer_version;
  96825. +} AUDIO_INSTANCE_T;
  96826. +
  96827. +bool force_bulk = false;
  96828. +
  96829. +/* ---- Private Variables ---------------------------------------------------- */
  96830. +
  96831. +/* ---- Private Function Prototypes ------------------------------------------ */
  96832. +
  96833. +/* ---- Private Functions ---------------------------------------------------- */
  96834. +
  96835. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  96836. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  96837. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  96838. + uint32_t count, void *src);
  96839. +
  96840. +typedef struct {
  96841. + struct work_struct my_work;
  96842. + bcm2835_alsa_stream_t *alsa_stream;
  96843. + int cmd;
  96844. + void *src;
  96845. + uint32_t count;
  96846. +} my_work_t;
  96847. +
  96848. +static void my_wq_function(struct work_struct *work)
  96849. +{
  96850. + my_work_t *w = (my_work_t *) work;
  96851. + int ret = -9;
  96852. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  96853. + switch (w->cmd) {
  96854. + case BCM2835_AUDIO_START:
  96855. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  96856. + break;
  96857. + case BCM2835_AUDIO_STOP:
  96858. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  96859. + break;
  96860. + case BCM2835_AUDIO_WRITE:
  96861. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  96862. + w->src);
  96863. + break;
  96864. + default:
  96865. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  96866. + break;
  96867. + }
  96868. + kfree((void *)work);
  96869. + LOG_DBG(" .. OUT %d\n", ret);
  96870. +}
  96871. +
  96872. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  96873. +{
  96874. + int ret = -1;
  96875. + LOG_DBG(" .. IN\n");
  96876. + if (alsa_stream->my_wq) {
  96877. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  96878. + /*--- Queue some work (item 1) ---*/
  96879. + if (work) {
  96880. + INIT_WORK((struct work_struct *)work, my_wq_function);
  96881. + work->alsa_stream = alsa_stream;
  96882. + work->cmd = BCM2835_AUDIO_START;
  96883. + if (queue_work
  96884. + (alsa_stream->my_wq, (struct work_struct *)work))
  96885. + ret = 0;
  96886. + } else
  96887. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  96888. + }
  96889. + LOG_DBG(" .. OUT %d\n", ret);
  96890. + return ret;
  96891. +}
  96892. +
  96893. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  96894. +{
  96895. + int ret = -1;
  96896. + LOG_DBG(" .. IN\n");
  96897. + if (alsa_stream->my_wq) {
  96898. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  96899. + /*--- Queue some work (item 1) ---*/
  96900. + if (work) {
  96901. + INIT_WORK((struct work_struct *)work, my_wq_function);
  96902. + work->alsa_stream = alsa_stream;
  96903. + work->cmd = BCM2835_AUDIO_STOP;
  96904. + if (queue_work
  96905. + (alsa_stream->my_wq, (struct work_struct *)work))
  96906. + ret = 0;
  96907. + } else
  96908. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  96909. + }
  96910. + LOG_DBG(" .. OUT %d\n", ret);
  96911. + return ret;
  96912. +}
  96913. +
  96914. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  96915. + uint32_t count, void *src)
  96916. +{
  96917. + int ret = -1;
  96918. + LOG_DBG(" .. IN\n");
  96919. + if (alsa_stream->my_wq) {
  96920. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  96921. + /*--- Queue some work (item 1) ---*/
  96922. + if (work) {
  96923. + INIT_WORK((struct work_struct *)work, my_wq_function);
  96924. + work->alsa_stream = alsa_stream;
  96925. + work->cmd = BCM2835_AUDIO_WRITE;
  96926. + work->src = src;
  96927. + work->count = count;
  96928. + if (queue_work
  96929. + (alsa_stream->my_wq, (struct work_struct *)work))
  96930. + ret = 0;
  96931. + } else
  96932. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  96933. + }
  96934. + LOG_DBG(" .. OUT %d\n", ret);
  96935. + return ret;
  96936. +}
  96937. +
  96938. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  96939. +{
  96940. + alsa_stream->my_wq = create_workqueue("my_queue");
  96941. + return;
  96942. +}
  96943. +
  96944. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  96945. +{
  96946. + if (alsa_stream->my_wq) {
  96947. + flush_workqueue(alsa_stream->my_wq);
  96948. + destroy_workqueue(alsa_stream->my_wq);
  96949. + alsa_stream->my_wq = NULL;
  96950. + }
  96951. + return;
  96952. +}
  96953. +
  96954. +static void audio_vchi_callback(void *param,
  96955. + const VCHI_CALLBACK_REASON_T reason,
  96956. + void *msg_handle)
  96957. +{
  96958. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  96959. + int32_t status;
  96960. + int32_t msg_len;
  96961. + VC_AUDIO_MSG_T m;
  96962. + bcm2835_alsa_stream_t *alsa_stream = 0;
  96963. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  96964. + instance, param, reason, msg_handle);
  96965. +
  96966. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  96967. + return;
  96968. + }
  96969. + alsa_stream = instance->alsa_stream;
  96970. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  96971. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  96972. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  96973. + LOG_DBG
  96974. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  96975. + instance, m.u.result.success);
  96976. + instance->result = m.u.result.success;
  96977. + complete(&instance->msg_avail_comp);
  96978. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  96979. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  96980. + LOG_DBG
  96981. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  96982. + instance, m.u.complete.count);
  96983. + if (alsa_stream && callback) {
  96984. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  96985. + callback(0, alsa_stream);
  96986. + } else {
  96987. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  96988. + alsa_stream, callback);
  96989. + }
  96990. + } else {
  96991. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  96992. + }
  96993. + LOG_DBG(" .. OUT\n");
  96994. +}
  96995. +
  96996. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  96997. + VCHI_CONNECTION_T **
  96998. + vchi_connections,
  96999. + uint32_t num_connections)
  97000. +{
  97001. + uint32_t i;
  97002. + AUDIO_INSTANCE_T *instance;
  97003. + int status;
  97004. +
  97005. + LOG_DBG("%s: start", __func__);
  97006. +
  97007. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  97008. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  97009. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  97010. +
  97011. + return NULL;
  97012. + }
  97013. + /* Allocate memory for this instance */
  97014. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  97015. +
  97016. + memset(instance, 0, sizeof(*instance));
  97017. + instance->num_connections = num_connections;
  97018. +
  97019. + /* Create a lock for exclusive, serialized VCHI connection access */
  97020. + mutex_init(&instance->vchi_mutex);
  97021. + /* Open the VCHI service connections */
  97022. + for (i = 0; i < num_connections; i++) {
  97023. + SERVICE_CREATION_T params = {
  97024. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  97025. + VC_AUDIO_SERVER_NAME, // 4cc service code
  97026. + vchi_connections[i], // passed in fn pointers
  97027. + 0, // rx fifo size (unused)
  97028. + 0, // tx fifo size (unused)
  97029. + audio_vchi_callback, // service callback
  97030. + instance, // service callback parameter
  97031. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  97032. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  97033. + 0 // want crc check on bulk transfers
  97034. + };
  97035. +
  97036. + status = vchi_service_open(vchi_instance, &params,
  97037. + &instance->vchi_handle[i]);
  97038. + if (status) {
  97039. + LOG_ERR
  97040. + ("%s: failed to open VCHI service connection (status=%d)\n",
  97041. + __func__, status);
  97042. +
  97043. + goto err_close_services;
  97044. + }
  97045. + /* Finished with the service for now */
  97046. + vchi_service_release(instance->vchi_handle[i]);
  97047. + }
  97048. +
  97049. + return instance;
  97050. +
  97051. +err_close_services:
  97052. + for (i = 0; i < instance->num_connections; i++) {
  97053. + vchi_service_close(instance->vchi_handle[i]);
  97054. + }
  97055. +
  97056. + kfree(instance);
  97057. +
  97058. + return NULL;
  97059. +}
  97060. +
  97061. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  97062. +{
  97063. + uint32_t i;
  97064. +
  97065. + LOG_DBG(" .. IN\n");
  97066. +
  97067. + if (instance == NULL) {
  97068. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  97069. +
  97070. + return -1;
  97071. + }
  97072. +
  97073. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  97074. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97075. + {
  97076. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97077. + return -EINTR;
  97078. + }
  97079. +
  97080. + /* Close all VCHI service connections */
  97081. + for (i = 0; i < instance->num_connections; i++) {
  97082. + int32_t success;
  97083. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  97084. + vchi_service_use(instance->vchi_handle[i]);
  97085. +
  97086. + success = vchi_service_close(instance->vchi_handle[i]);
  97087. + if (success != 0) {
  97088. + LOG_ERR
  97089. + ("%s: failed to close VCHI service connection (status=%d)\n",
  97090. + __func__, success);
  97091. + }
  97092. + }
  97093. +
  97094. + mutex_unlock(&instance->vchi_mutex);
  97095. +
  97096. + kfree(instance);
  97097. +
  97098. + LOG_DBG(" .. OUT\n");
  97099. +
  97100. + return 0;
  97101. +}
  97102. +
  97103. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  97104. +{
  97105. + static VCHI_INSTANCE_T vchi_instance;
  97106. + static VCHI_CONNECTION_T *vchi_connection;
  97107. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97108. + int ret;
  97109. + LOG_DBG(" .. IN\n");
  97110. +
  97111. + LOG_INFO("%s: start", __func__);
  97112. + //BUG_ON(instance);
  97113. + if (instance) {
  97114. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  97115. + __func__, instance);
  97116. + instance->alsa_stream = alsa_stream;
  97117. + alsa_stream->instance = instance;
  97118. + ret = 0; // xxx todo -1;
  97119. + goto err_free_mem;
  97120. + }
  97121. +
  97122. + /* Initialize and create a VCHI connection */
  97123. + ret = vchi_initialise(&vchi_instance);
  97124. + if (ret != 0) {
  97125. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  97126. + __func__, ret);
  97127. +
  97128. + ret = -EIO;
  97129. + goto err_free_mem;
  97130. + }
  97131. + ret = vchi_connect(NULL, 0, vchi_instance);
  97132. + if (ret != 0) {
  97133. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  97134. + __func__, ret);
  97135. +
  97136. + ret = -EIO;
  97137. + goto err_free_mem;
  97138. + }
  97139. +
  97140. + /* Initialize an instance of the audio service */
  97141. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  97142. +
  97143. + if (instance == NULL /*|| audio_handle != instance */ ) {
  97144. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  97145. +
  97146. + ret = -EPERM;
  97147. + goto err_free_mem;
  97148. + }
  97149. +
  97150. + instance->alsa_stream = alsa_stream;
  97151. + alsa_stream->instance = instance;
  97152. +
  97153. + LOG_DBG(" success !\n");
  97154. +err_free_mem:
  97155. + LOG_DBG(" .. OUT\n");
  97156. +
  97157. + return ret;
  97158. +}
  97159. +
  97160. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  97161. +{
  97162. + AUDIO_INSTANCE_T *instance;
  97163. + VC_AUDIO_MSG_T m;
  97164. + int32_t success;
  97165. + int ret;
  97166. + LOG_DBG(" .. IN\n");
  97167. +
  97168. + my_workqueue_init(alsa_stream);
  97169. +
  97170. + ret = bcm2835_audio_open_connection(alsa_stream);
  97171. + if (ret != 0) {
  97172. + ret = -1;
  97173. + goto exit;
  97174. + }
  97175. + instance = alsa_stream->instance;
  97176. +
  97177. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97178. + {
  97179. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97180. + return -EINTR;
  97181. + }
  97182. + vchi_service_use(instance->vchi_handle[0]);
  97183. +
  97184. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  97185. +
  97186. + /* Send the message to the videocore */
  97187. + success = vchi_msg_queue(instance->vchi_handle[0],
  97188. + &m, sizeof m,
  97189. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97190. +
  97191. + if (success != 0) {
  97192. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97193. + __func__, success);
  97194. +
  97195. + ret = -1;
  97196. + goto unlock;
  97197. + }
  97198. +
  97199. + ret = 0;
  97200. +
  97201. +unlock:
  97202. + vchi_service_release(instance->vchi_handle[0]);
  97203. + mutex_unlock(&instance->vchi_mutex);
  97204. +exit:
  97205. + LOG_DBG(" .. OUT\n");
  97206. + return ret;
  97207. +}
  97208. +
  97209. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  97210. + bcm2835_chip_t * chip)
  97211. +{
  97212. + VC_AUDIO_MSG_T m;
  97213. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97214. + int32_t success;
  97215. + int ret;
  97216. + LOG_DBG(" .. IN\n");
  97217. +
  97218. + LOG_INFO
  97219. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  97220. +
  97221. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97222. + {
  97223. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97224. + return -EINTR;
  97225. + }
  97226. + vchi_service_use(instance->vchi_handle[0]);
  97227. +
  97228. + instance->result = -1;
  97229. +
  97230. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  97231. + m.u.control.dest = chip->dest;
  97232. + m.u.control.volume = chip->volume;
  97233. +
  97234. + /* Create the message available completion */
  97235. + init_completion(&instance->msg_avail_comp);
  97236. +
  97237. + /* Send the message to the videocore */
  97238. + success = vchi_msg_queue(instance->vchi_handle[0],
  97239. + &m, sizeof m,
  97240. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97241. +
  97242. + if (success != 0) {
  97243. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97244. + __func__, success);
  97245. +
  97246. + ret = -1;
  97247. + goto unlock;
  97248. + }
  97249. +
  97250. + /* We are expecting a reply from the videocore */
  97251. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97252. + if (ret) {
  97253. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  97254. + __func__, success);
  97255. + goto unlock;
  97256. + }
  97257. +
  97258. + if (instance->result != 0) {
  97259. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  97260. +
  97261. + ret = -1;
  97262. + goto unlock;
  97263. + }
  97264. +
  97265. + ret = 0;
  97266. +
  97267. +unlock:
  97268. + vchi_service_release(instance->vchi_handle[0]);
  97269. + mutex_unlock(&instance->vchi_mutex);
  97270. +
  97271. + LOG_DBG(" .. OUT\n");
  97272. + return ret;
  97273. +}
  97274. +
  97275. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  97276. +{
  97277. + int i;
  97278. + int ret = 0;
  97279. + LOG_DBG(" .. IN\n");
  97280. +
  97281. + /* change ctls for all substreams */
  97282. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  97283. + if (chip->avail_substreams & (1 << i)) {
  97284. + if (!chip->alsa_stream[i])
  97285. + {
  97286. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  97287. + ret = 0;
  97288. + }
  97289. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  97290. + (chip->alsa_stream[i], chip) != 0)
  97291. + {
  97292. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  97293. + ret = -1;
  97294. + }
  97295. + else LOG_DBG(" Controls set for stream %d\n", i);
  97296. + }
  97297. + }
  97298. + LOG_DBG(" .. OUT ret=%d\n", ret);
  97299. + return ret;
  97300. +}
  97301. +
  97302. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  97303. + uint32_t channels, uint32_t samplerate,
  97304. + uint32_t bps)
  97305. +{
  97306. + VC_AUDIO_MSG_T m;
  97307. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97308. + int32_t success;
  97309. + int ret;
  97310. + LOG_DBG(" .. IN\n");
  97311. +
  97312. + LOG_INFO
  97313. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  97314. + channels, samplerate, bps);
  97315. +
  97316. + /* resend ctls - alsa_stream may not have been open when first send */
  97317. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  97318. + if (ret != 0) {
  97319. + LOG_ERR(" Alsa controls not supported\n");
  97320. + return -EINVAL;
  97321. + }
  97322. +
  97323. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97324. + {
  97325. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97326. + return -EINTR;
  97327. + }
  97328. + vchi_service_use(instance->vchi_handle[0]);
  97329. +
  97330. + instance->result = -1;
  97331. +
  97332. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  97333. + m.u.config.channels = channels;
  97334. + m.u.config.samplerate = samplerate;
  97335. + m.u.config.bps = bps;
  97336. +
  97337. + /* Create the message available completion */
  97338. + init_completion(&instance->msg_avail_comp);
  97339. +
  97340. + /* Send the message to the videocore */
  97341. + success = vchi_msg_queue(instance->vchi_handle[0],
  97342. + &m, sizeof m,
  97343. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97344. +
  97345. + if (success != 0) {
  97346. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  97347. + __func__, success);
  97348. +
  97349. + ret = -1;
  97350. + goto unlock;
  97351. + }
  97352. +
  97353. + /* We are expecting a reply from the videocore */
  97354. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97355. + if (ret) {
  97356. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  97357. + __func__, success);
  97358. + goto unlock;
  97359. + }
  97360. +
  97361. + if (instance->result != 0) {
  97362. + LOG_ERR("%s: result=%d", __func__, instance->result);
  97363. +
  97364. + ret = -1;
  97365. + goto unlock;
  97366. + }
  97367. +
  97368. + ret = 0;
  97369. +
  97370. +unlock:
  97371. + vchi_service_release(instance->vchi_handle[0]);
  97372. + mutex_unlock(&instance->vchi_mutex);
  97373. +
  97374. + LOG_DBG(" .. OUT\n");
  97375. + return ret;
  97376. +}
  97377. +
  97378. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  97379. +{
  97380. + LOG_DBG(" .. IN\n");
  97381. +
  97382. + LOG_DBG(" .. OUT\n");
  97383. +
  97384. + return 0;
  97385. +}
  97386. +
  97387. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  97388. +{
  97389. + VC_AUDIO_MSG_T m;
  97390. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97391. + int32_t success;
  97392. + int ret;
  97393. + LOG_DBG(" .. IN\n");
  97394. +
  97395. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97396. + {
  97397. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97398. + return -EINTR;
  97399. + }
  97400. + vchi_service_use(instance->vchi_handle[0]);
  97401. +
  97402. + m.type = VC_AUDIO_MSG_TYPE_START;
  97403. +
  97404. + /* Send the message to the videocore */
  97405. + success = vchi_msg_queue(instance->vchi_handle[0],
  97406. + &m, sizeof m,
  97407. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97408. +
  97409. + if (success != 0) {
  97410. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97411. + __func__, success);
  97412. +
  97413. + ret = -1;
  97414. + goto unlock;
  97415. + }
  97416. +
  97417. + ret = 0;
  97418. +
  97419. +unlock:
  97420. + vchi_service_release(instance->vchi_handle[0]);
  97421. + mutex_unlock(&instance->vchi_mutex);
  97422. + LOG_DBG(" .. OUT\n");
  97423. + return ret;
  97424. +}
  97425. +
  97426. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  97427. +{
  97428. + VC_AUDIO_MSG_T m;
  97429. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97430. + int32_t success;
  97431. + int ret;
  97432. + LOG_DBG(" .. IN\n");
  97433. +
  97434. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97435. + {
  97436. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97437. + return -EINTR;
  97438. + }
  97439. + vchi_service_use(instance->vchi_handle[0]);
  97440. +
  97441. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  97442. + m.u.stop.draining = alsa_stream->draining;
  97443. +
  97444. + /* Send the message to the videocore */
  97445. + success = vchi_msg_queue(instance->vchi_handle[0],
  97446. + &m, sizeof m,
  97447. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97448. +
  97449. + if (success != 0) {
  97450. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97451. + __func__, success);
  97452. +
  97453. + ret = -1;
  97454. + goto unlock;
  97455. + }
  97456. +
  97457. + ret = 0;
  97458. +
  97459. +unlock:
  97460. + vchi_service_release(instance->vchi_handle[0]);
  97461. + mutex_unlock(&instance->vchi_mutex);
  97462. + LOG_DBG(" .. OUT\n");
  97463. + return ret;
  97464. +}
  97465. +
  97466. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  97467. +{
  97468. + VC_AUDIO_MSG_T m;
  97469. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97470. + int32_t success;
  97471. + int ret;
  97472. + LOG_DBG(" .. IN\n");
  97473. +
  97474. + my_workqueue_quit(alsa_stream);
  97475. +
  97476. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97477. + {
  97478. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97479. + return -EINTR;
  97480. + }
  97481. + vchi_service_use(instance->vchi_handle[0]);
  97482. +
  97483. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  97484. +
  97485. + /* Create the message available completion */
  97486. + init_completion(&instance->msg_avail_comp);
  97487. +
  97488. + /* Send the message to the videocore */
  97489. + success = vchi_msg_queue(instance->vchi_handle[0],
  97490. + &m, sizeof m,
  97491. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97492. +
  97493. + if (success != 0) {
  97494. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97495. + __func__, success);
  97496. + ret = -1;
  97497. + goto unlock;
  97498. + }
  97499. +
  97500. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  97501. + if (ret) {
  97502. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  97503. + __func__, success);
  97504. + goto unlock;
  97505. + }
  97506. + if (instance->result != 0) {
  97507. + LOG_ERR("%s: failed result (status=%d)",
  97508. + __func__, instance->result);
  97509. +
  97510. + ret = -1;
  97511. + goto unlock;
  97512. + }
  97513. +
  97514. + ret = 0;
  97515. +
  97516. +unlock:
  97517. + vchi_service_release(instance->vchi_handle[0]);
  97518. + mutex_unlock(&instance->vchi_mutex);
  97519. +
  97520. + /* Stop the audio service */
  97521. + if (instance) {
  97522. + vc_vchi_audio_deinit(instance);
  97523. + alsa_stream->instance = NULL;
  97524. + }
  97525. + LOG_DBG(" .. OUT\n");
  97526. + return ret;
  97527. +}
  97528. +
  97529. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  97530. + uint32_t count, void *src)
  97531. +{
  97532. + VC_AUDIO_MSG_T m;
  97533. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  97534. + int32_t success;
  97535. + int ret;
  97536. +
  97537. + LOG_DBG(" .. IN\n");
  97538. +
  97539. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  97540. +
  97541. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  97542. + {
  97543. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  97544. + return -EINTR;
  97545. + }
  97546. + vchi_service_use(instance->vchi_handle[0]);
  97547. +
  97548. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  97549. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  97550. + }
  97551. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  97552. + m.u.write.count = count;
  97553. + // old version uses bulk, new version uses control
  97554. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  97555. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  97556. + m.u.write.cookie = alsa_stream;
  97557. + m.u.write.silence = src == NULL;
  97558. +
  97559. + /* Send the message to the videocore */
  97560. + success = vchi_msg_queue(instance->vchi_handle[0],
  97561. + &m, sizeof m,
  97562. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97563. +
  97564. + if (success != 0) {
  97565. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  97566. + __func__, success);
  97567. +
  97568. + ret = -1;
  97569. + goto unlock;
  97570. + }
  97571. + if (!m.u.write.silence) {
  97572. + if (m.u.write.max_packet == 0) {
  97573. + /* Send the message to the videocore */
  97574. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  97575. + src, count,
  97576. + 0 *
  97577. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  97578. + +
  97579. + 1 *
  97580. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  97581. + NULL);
  97582. + } else {
  97583. + while (count > 0) {
  97584. + int bytes = min((int)m.u.write.max_packet, (int)count);
  97585. + success = vchi_msg_queue(instance->vchi_handle[0],
  97586. + src, bytes,
  97587. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  97588. + src = (char *)src + bytes;
  97589. + count -= bytes;
  97590. + }
  97591. + }
  97592. + if (success != 0) {
  97593. + LOG_ERR
  97594. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  97595. + __func__, success);
  97596. +
  97597. + ret = -1;
  97598. + goto unlock;
  97599. + }
  97600. + }
  97601. + ret = 0;
  97602. +
  97603. +unlock:
  97604. + vchi_service_release(instance->vchi_handle[0]);
  97605. + mutex_unlock(&instance->vchi_mutex);
  97606. + LOG_DBG(" .. OUT\n");
  97607. + return ret;
  97608. +}
  97609. +
  97610. +/**
  97611. + * Returns all buffers from arm->vc
  97612. + */
  97613. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97614. +{
  97615. + LOG_DBG(" .. IN\n");
  97616. + LOG_DBG(" .. OUT\n");
  97617. + return;
  97618. +}
  97619. +
  97620. +/**
  97621. + * Forces VC to flush(drop) its filled playback buffers and
  97622. + * return them the us. (VC->ARM)
  97623. + */
  97624. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97625. +{
  97626. + LOG_DBG(" .. IN\n");
  97627. + LOG_DBG(" .. OUT\n");
  97628. +}
  97629. +
  97630. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  97631. +{
  97632. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  97633. + atomic_sub(count, &alsa_stream->retrieved);
  97634. + return count;
  97635. +}
  97636. +
  97637. +module_param(force_bulk, bool, 0444);
  97638. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  97639. diff -Nur linux-3.11.10.orig/sound/arm/Kconfig linux-3.11.10/sound/arm/Kconfig
  97640. --- linux-3.11.10.orig/sound/arm/Kconfig 2013-11-29 19:42:37.000000000 +0100
  97641. +++ linux-3.11.10/sound/arm/Kconfig 2014-02-07 19:57:30.000000000 +0100
  97642. @@ -39,5 +39,12 @@
  97643. Say Y or M if you want to support any AC97 codec attached to
  97644. the PXA2xx AC97 interface.
  97645. +config SND_BCM2835
  97646. + tristate "BCM2835 ALSA driver"
  97647. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  97648. + select SND_PCM
  97649. + help
  97650. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  97651. +
  97652. endif # SND_ARM
  97653. diff -Nur linux-3.11.10.orig/sound/arm/Makefile linux-3.11.10/sound/arm/Makefile
  97654. --- linux-3.11.10.orig/sound/arm/Makefile 2013-11-29 19:42:37.000000000 +0100
  97655. +++ linux-3.11.10/sound/arm/Makefile 2014-02-07 19:57:30.000000000 +0100
  97656. @@ -14,3 +14,8 @@
  97657. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  97658. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  97659. +
  97660. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  97661. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  97662. +
  97663. +EXTRA_CFLAGS += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  97664. diff -Nur linux-3.11.10.orig/sound/arm/vc_vchi_audioserv_defs.h linux-3.11.10/sound/arm/vc_vchi_audioserv_defs.h
  97665. --- linux-3.11.10.orig/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  97666. +++ linux-3.11.10/sound/arm/vc_vchi_audioserv_defs.h 2014-02-07 19:57:30.000000000 +0100
  97667. @@ -0,0 +1,116 @@
  97668. +/*****************************************************************************
  97669. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  97670. +*
  97671. +* Unless you and Broadcom execute a separate written software license
  97672. +* agreement governing use of this software, this software is licensed to you
  97673. +* under the terms of the GNU General Public License version 2, available at
  97674. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  97675. +*
  97676. +* Notwithstanding the above, under no circumstances may you combine this
  97677. +* software in any way with any other Broadcom software provided under a
  97678. +* license other than the GPL, without Broadcom's express prior written
  97679. +* consent.
  97680. +*****************************************************************************/
  97681. +
  97682. +#ifndef _VC_AUDIO_DEFS_H_
  97683. +#define _VC_AUDIO_DEFS_H_
  97684. +
  97685. +#define VC_AUDIOSERV_MIN_VER 1
  97686. +#define VC_AUDIOSERV_VER 2
  97687. +
  97688. +// FourCC code used for VCHI connection
  97689. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  97690. +
  97691. +// Maximum message length
  97692. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  97693. +
  97694. +// List of screens that are currently supported
  97695. +// All message types supported for HOST->VC direction
  97696. +typedef enum {
  97697. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  97698. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  97699. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  97700. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  97701. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  97702. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  97703. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  97704. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  97705. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  97706. + VC_AUDIO_MSG_TYPE_MAX
  97707. +} VC_AUDIO_MSG_TYPE;
  97708. +
  97709. +// configure the audio
  97710. +typedef struct {
  97711. + uint32_t channels;
  97712. + uint32_t samplerate;
  97713. + uint32_t bps;
  97714. +
  97715. +} VC_AUDIO_CONFIG_T;
  97716. +
  97717. +typedef struct {
  97718. + uint32_t volume;
  97719. + uint32_t dest;
  97720. +
  97721. +} VC_AUDIO_CONTROL_T;
  97722. +
  97723. +// audio
  97724. +typedef struct {
  97725. + uint32_t dummy;
  97726. +
  97727. +} VC_AUDIO_OPEN_T;
  97728. +
  97729. +// audio
  97730. +typedef struct {
  97731. + uint32_t dummy;
  97732. +
  97733. +} VC_AUDIO_CLOSE_T;
  97734. +// audio
  97735. +typedef struct {
  97736. + uint32_t dummy;
  97737. +
  97738. +} VC_AUDIO_START_T;
  97739. +// audio
  97740. +typedef struct {
  97741. + uint32_t draining;
  97742. +
  97743. +} VC_AUDIO_STOP_T;
  97744. +
  97745. +// configure the write audio samples
  97746. +typedef struct {
  97747. + uint32_t count; // in bytes
  97748. + void *callback;
  97749. + void *cookie;
  97750. + uint16_t silence;
  97751. + uint16_t max_packet;
  97752. +} VC_AUDIO_WRITE_T;
  97753. +
  97754. +// Generic result for a request (VC->HOST)
  97755. +typedef struct {
  97756. + int32_t success; // Success value
  97757. +
  97758. +} VC_AUDIO_RESULT_T;
  97759. +
  97760. +// Generic result for a request (VC->HOST)
  97761. +typedef struct {
  97762. + int32_t count; // Success value
  97763. + void *callback;
  97764. + void *cookie;
  97765. +} VC_AUDIO_COMPLETE_T;
  97766. +
  97767. +// Message header for all messages in HOST->VC direction
  97768. +typedef struct {
  97769. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  97770. + union {
  97771. + VC_AUDIO_CONFIG_T config;
  97772. + VC_AUDIO_CONTROL_T control;
  97773. + VC_AUDIO_OPEN_T open;
  97774. + VC_AUDIO_CLOSE_T close;
  97775. + VC_AUDIO_START_T start;
  97776. + VC_AUDIO_STOP_T stop;
  97777. + VC_AUDIO_WRITE_T write;
  97778. + VC_AUDIO_RESULT_T result;
  97779. + VC_AUDIO_COMPLETE_T complete;
  97780. + } u;
  97781. +} VC_AUDIO_MSG_T;
  97782. +
  97783. +#endif // _VC_AUDIO_DEFS_H_